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

fix(refresh): bug with revisions #1067

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

jack-w-shaw
Copy link
Member

@jack-w-shaw jack-w-shaw commented Jun 28, 2024

Description

We are incorrectly refreshing charms. The current method queries the controller for the charm's current origin and charm url

In pylibjuju, we then just overwrite the appropriate fields. However, this leaves behind id_ and hash_

This means when we later refresh, we are always returned the most recent revision by charmhub, no matter what revision we specify.

The way we handle this in the Juju CLI is by reconstructing the charm origin using MakeOrigin:
https://github.com/juju/juju/blob/a03ade4d358b1b0f135374b15b1bcd6b46d0ba0f/cmd/juju/application/utils/origin.go#L20-L75

This ensures only the fields we expect are present.

Do something similar in pylibjuju, ensuring we behave the same as the CLI.

Fixes: #1057

QA Steps

Unit tests

tox -e unit

Integration tests

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

Manual tests

$ juju bootstrap lxd lxd
$ juju add-model m
$ juju deploy opensearch --revision 90 --channel=2/edge
$ python -m asyncio
>>> from juju.model import Model
>>> m = Model()
>>> await m.connect()
>>> app = m.applicatyions["opensearch"]
>>> await app.refresh(revision=91)
>>> exit()
$ juju status
Model  Controller  Cloud/Region         Version    SLA          Timestamp
m      lxd1        localhost/localhost  3.6-beta1  unsupported  13:32:44+01:00

App         Version  Status       Scale  Charm       Channel  Rev  Exposed  Message
opensearch           maintenance      1  opensearch  2/edge    91  no       Installing OpenSearch...

Unit           Workload     Agent      Machine  Public address  Ports  Message
opensearch/0*  maintenance  executing  0        10.219.211.254         (install) Installing OpenSearch...

Machine  State    Address         Inst id        Base          AZ  Message
0        started  10.219.211.254  juju-56bc09-0  ubuntu@22.04      Running

@jack-w-shaw jack-w-shaw force-pushed the JUJU-6262_fix_refresh_revision branch from 4d56e56 to d44b2a1 Compare July 3, 2024 12:29
@jack-w-shaw jack-w-shaw changed the title [WIP] fix(refresh): bug with revisions fix(refresh): bug with revisions Jul 3, 2024
@jack-w-shaw jack-w-shaw requested a review from cderici July 3, 2024 12:33
@jack-w-shaw jack-w-shaw force-pushed the JUJU-6262_fix_refresh_revision branch 2 times, most recently from 5482461 to 890ba55 Compare July 3, 2024 12:47
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.

Looks good, couple of changes needed, and all the tests related to this need to pass.

juju/application.py Show resolved Hide resolved

charmhub = self.model.charmhub
charm_resources = await charmhub.list_resources(charm_name)
origin = client.CharmOrigin(
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this out into a helper function and have some unit tests against this to protect the logic for any regressions.

Copy link
Member Author

Choose a reason for hiding this comment

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

What logic exactly are you referring to here?

Copy link
Contributor

Choose a reason for hiding this comment

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

More like decisions I meant to say, we make a bunch of decisions here, it would be nice if we have unit tests that assert those decisions so if any of them are violated in the future we'd catch it before it breaks.

            source=str(Source.CHARM_HUB),
            risk=channel.risk if channel else current_origin.risk,
            track=channel.track if channel else current_origin.track,
            revision=revision or current_origin.revision,
            base=current_origin.base,
            architecture=current_origin.get('architecture', DEFAULT_ARCHITECTURE),

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

tests/integration/test_application.py Outdated Show resolved Hide resolved
juju/application.py Outdated Show resolved Hide resolved
@jack-w-shaw jack-w-shaw force-pushed the JUJU-6262_fix_refresh_revision branch 3 times, most recently from 56b16bc to 7ae2a4d Compare July 9, 2024 10:32
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.

Looks very good, thanks for adding the extra unit tests 👍

We'll land it as soon as the check job is fixed.

@jack-w-shaw jack-w-shaw force-pushed the JUJU-6262_fix_refresh_revision branch from 643231b to 7ae2a4d Compare July 11, 2024 11:03
@jack-w-shaw
Copy link
Member Author

/merge

1 similar comment
@jack-w-shaw
Copy link
Member Author

/merge

We are incorrectly refreshing charms. The current method queries the
controller for the charm's current origin and charm url

In pylibjuju, we then just overwrite the appropriate fields. However,
this leaves behind id_ and hash_

This means when we later refresh, we are always returned the most recent
revision by charmhub, no matter what revision we specify.

The way we handle this in the Juju CLI is by reconstructing the charm
origin using MakeOrigin:
https://github.com/juju/juju/blob/a03ade4d358b1b0f135374b15b1bcd6b46d0ba0f/cmd/juju/application/utils/origin.go#L20-L75

This ensures only the fields we expect are present.

Replicate this method, ensuring we behave the same as the CLI.

Fixes: juju#1057
@jack-w-shaw jack-w-shaw force-pushed the JUJU-6262_fix_refresh_revision branch from 7ae2a4d to 956aa5a Compare July 11, 2024 11:54
@jack-w-shaw
Copy link
Member Author

/merge

@jujubot jujubot merged commit d0a18d3 into juju:main Jul 11, 2024
7 of 9 checks passed
jujubot added a commit that referenced this pull request Jul 11, 2024
#1071

## What's Changed
* fix parsing of storage constraints by @luissimas in #1053
* Add setuptools to tox.ini by @Aflynn50 in #1058
* fix(refresh): bug with revisions by @jack-w-shaw in #1067
* feat: conventional commits static analysis by @SimonRichardson in #1068
* fix(series): add noble support by @jack-w-shaw in #1063
* fix zones constrains list parsing by @luissimas in #1054
* fix(model): fix wrong instanciation of list-secrets facade by @gboutry in #1065
* fix(makefile): run .tox before lint in makefile target by @cderici in #1069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refresh] revision option does not work
3 participants