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

Allow switch kwarg in refresh to switch to local charms #971

Merged
merged 2 commits into from
Oct 25, 2023

Conversation

jack-w-shaw
Copy link
Member

Port forward #968

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 #963

QA Steps

tox -e integration -- tests/integration/test_application.py::test_refresh_charmhub_to_local

All CI tests need to pass.

Verify the following example script runs successfully:

from juju import jasyncio
from juju.model import Model


async def main():
    model = Model()
    print('Connecting to model')
    await model.connect()
    try:
        print('path="/home/jack/charms/ubuntu"')
        await depl(model, path="/home/jack/charms/ubuntu")
        print('switch="/home/jack/charms/ubuntu"')
        await depl(model, switch="/home/jack/charms/ubuntu")
        print('switch="local:/home/jack/charms/ubuntu"')
        await depl(model, switch="local:/home/jack/charms/ubuntu")
    finally:
        print('Disconnecting from model')
        await model.disconnect()

async def depl(model, **kwargs):
    try:
        app = await model.deploy("ubuntu")
        await model.block_until(lambda: all(u[0].workload_status == 'active' for u in app.units))
        await app.refresh(**kwargs)
    finally:
        await app.remove()
        await model.block_until(lambda: not len(model.applications))

if __name__ == '__main__':
    jasyncio.run(main())

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
Copy link
Contributor

@cderici cderici left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@cderici cderici added the hint/3.x going on main branch label Oct 24, 2023
@jack-w-shaw
Copy link
Member Author

jack-w-shaw commented Oct 25, 2023

NOTE: The one integration test failure is a timeout, which passes when I try locally. Merging anyway

@jack-w-shaw
Copy link
Member Author

/merge

@jack-w-shaw jack-w-shaw force-pushed the JUJU-4829_fix_refresh_bug-master branch from 8b3537c to 67188f4 Compare October 25, 2023 12:16
@jack-w-shaw
Copy link
Member Author

/merge

@cderici
Copy link
Contributor

cderici commented Oct 25, 2023

The error is actually a new one that I haven't seen before.

raise AssertionError('Unable to add_machine in %s attempts with spec : %s -- exception was %s' % (attempt, spec, err))
AssertionError: Unable to add_machine in 3 attempts with spec : ssh:[email protected]:/home/runner/.local/share/juju/ssh/juju_id_rsa -- exception was Authentication failed: transport shut down or saw EOF

But I'm sure that it's not related to this change. This can safely land no problem. I'll see if that issue is a release blocker or not, thanks for pointing it out 👍

@jack-w-shaw
Copy link
Member Author

/merge

@jujubot jujubot merged commit cd49a4f into juju:master Oct 25, 2023
6 of 8 checks passed
@jack-w-shaw jack-w-shaw deleted the JUJU-4829_fix_refresh_bug-master branch October 25, 2023 15:43
@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
hint/3.x going on main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python-libjuju cannot use app.refresh(switch=...) to switch to a local charm
3 participants