Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize & fix unit removal #967

Merged
merged 4 commits into from Oct 24, 2023

Conversation

cderici
Copy link
Member

@cderici cderici commented Oct 20, 2023

Description

This change does two things:

  1. Fixes the unit.destroy(...) references unit name rather than unit tag #950 as @addyess suggested.
  2. Optimizes the model.destroy_units where currently we're calling the API (ApplicationFacade.DestroyUnits) for each unit to be destroyed. This changes it so that the API is called only once with the list of the units.

Fixes #950

QA Steps

Added an integration test for the first case:

tox -e integration -- tests/integration/test_unit.py::test_destroy_unit

For the model.destroy_units() we already have a test:

tox -e integration -- tests/integration/test_model.py::test_destroy_units

Additionally, we also have a bunch of tests that use the model.destroy_units(), so they should be passing as well in the CI.

All CI tests need to pass.

Notes & Discussion

Normally it should be the case where the model.destroy_units() would use the Unit.destroy() on the Unit object. However, doing that for multiple units would be either inefficient (call u.destroy() for each unit -- thereby having the same inefficiency that we currently have), or a bit awkward since a unit would be requesting removal for other units. That's why we keep the model.destroy_units, as well as the unit.destroy() essentially doing the same thing.

Currently it's calling the API for each unit to be destroyed. This
changes it so that we're only calling the API only once.
Copy link
Member

@jack-w-shaw jack-w-shaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

juju/model.py Outdated
'max-wait': max_wait,
'dry-run': dry_run,
}])
await self.destroy_units(unit_id, destroy_storage, dry_run, force, max_wait)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the last 4 args be kwargs? I don't know exactly how python handles variadic positional / ket word args, but this seems a little fragile to me. It seems like later args could be misinterpreted as unit_names with only a small change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, this call needs to be fixed, but changing the args on the definition would mean changing the API in a run-by, which a lot of users would be upset about. That needs to be done in a major release.

I also realized we're not returning the result here (mostly because this is called only for its side-effect, but nevertheless). I'll fix it, thanks for the heads up 👍

jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 23, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
@cderici
Copy link
Member Author

cderici commented Oct 24, 2023

/merge

jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 24, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 24, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 24, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 24, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
@cderici
Copy link
Member Author

cderici commented Oct 24, 2023

/merge

@jujubot jujubot merged commit a677a64 into juju:master Oct 24, 2023
7 of 8 checks passed
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 26, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
jack-w-shaw added a commit to jack-w-shaw/python-libjuju that referenced this pull request Oct 26, 2023
Check if the switch param is pointing to a local charm. If it is, run
local_refresh as if it were provided

This is how the Juju CLI works, which was missing from pylibjuju.
Replicate this.

Also push url parsing of switch kwarg behind a check if it's local
charm, meaning we avoid the possibility where we attempt to parse a path
as if it were a url

Resolves juju#967
@cderici cderici mentioned this pull request Oct 26, 2023
jujubot added a commit that referenced this pull request Oct 26, 2023
#980

## What's Changed
* Repository Maintenance Improvements by @cderici in #922
* Stale bot to not bother feature requests by @cderici in #926
* Fix linter issues by @cderici in #928
* Fix docstring typo by @DanielArndt in #927
* Fix asyncio on README by @marceloneppel in #930
* Fix integration/test_application.test_action by @cderici in #932
* Update 3.2 facade clients by @cderici in #931
* [JUJU-4488] Add licence headers to source files on 3.x by @cderici in #934
* Update async tests to use builtin python suite by @DanielArndt in #935
* Pass correct charm url to series selector by @cderici in #942
* Green CI cleanup for python-libjuju by @cderici in #939
* Bring forward support for nested assumes expressions on 3x by @cderici in #943
* Release 3.2.2.0 notes by @cderici in #945
* Cleanup release process for 3.x by @cderici in #946
* Use new DeployFromRepository endpoint for deploy by @cderici in #949
* Handle pending upload resources deployfromrepository by @cderici in #953
* Optimize connection teardown by @cderici in #952
* Use `log.warning` instead of the deprecated `warn` by @sed-i in #954
* Find controller name by endpoint on 3.x track by @cderici in #966
* Optimize & fix unit removal by @cderici in #967
* Allow switch kwarg in refresh to switch to local charms by @jack-w-shaw in #971
* Parse charm URLs consistantly for local charms by @jack-w-shaw in #974
* Juju config directory location fix on 3.x by @cderici in #976
* [JUJU-4779] Ensure valid charm origin for local charm switches by @jack-w-shaw in #978
* Application refresh with resources on 3.x by @cderici in #973

#### Notes & Discussion

JUJU-4851

[JUJU-4488]: https://warthogs.atlassian.net/browse/JUJU-4488?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-4779]: https://warthogs.atlassian.net/browse/JUJU-4779?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unit.destroy(...) references unit name rather than unit tag
3 participants