Skip to content

Commit d4f6677

Browse files
authored
Merge pull request #1043 from Thanhphan1147/add_missing_revision_params_in_bundle_add_charms
#1043 #### Description Fixes #1042. When deploying a bundle, although the plan is properly generated with the correct revision for the charms in the bundle, and the change steps are generated with the correct parameter. I believe that the `addCharm` step does not take into account the specified "revision" of the charm to deploy, as a result the revision deployed is the latest revision instead of the specified revision. ref: https://github.com/juju/python-libjuju/blob/5ed5ae461514feb84dc0f96c2e46b6fab9f35861/juju/bundle.py#L709-L713 This PR simply adds the missing parameter to the `AddCharmChange` step and propagate the value to `client.CharmOrigin` to add the correct revision. #### QA Steps 1. Create a bundle containing one or more charms with revision 2. Deploy the bundle with `model.deploy` 3. The deployed charms in the bundle should have the revision specified in the bundle. - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing - [x] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing - ~~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed package~~ (I think this is too small of a change to warrant a doc update)
2 parents 2c30901 + 04f0e53 commit d4f6677

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

juju/bundle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ class AddCharmChange(ChangeInfo):
659659
_toPy = {'charm': 'charm',
660660
'series': 'series',
661661
'channel': 'channel',
662+
'revision': 'revision',
662663
'architecture': 'architecture'}
663664

664665
"""AddCharmChange holds a change for adding a charm to the environment.
@@ -675,6 +676,7 @@ class AddCharmChange(ChangeInfo):
675676
:series: series of the charm to be added if the charm default is
676677
not sufficient.
677678
:channel: preferred channel for obtaining the charm.
679+
:revision: specified revision of the charm to be added if specified.
678680
"""
679681
@staticmethod
680682
def method():
@@ -710,6 +712,7 @@ async def run(self, context):
710712
architecture=arch,
711713
risk=ch.risk,
712714
track=ch.track,
715+
revision=self.revision,
713716
base=base)
714717
identifier, origin = await context.model._resolve_charm(url, origin)
715718

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
applications:
2+
hello-juju:
3+
charm: "hello-juju"
4+
channel: latest/stable
5+
revision: 7
6+
num_units: 1

tests/integration/test_model.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pytest
1616
from juju import jasyncio, tag, url
1717
from juju.client import client
18+
from juju.client._definitions import FullStatus
1819
from juju.errors import JujuError, JujuModelError, JujuUnitError, JujuConnectionError
1920
from juju.model import Model, ModelObserver
2021
from juju.utils import block_until, run_with_interrupt, wait_for_bundle, base_channel_to_series
@@ -181,6 +182,25 @@ async def test_deploy_bundle_local_charm_series_manifest():
181182
assert model.units['test1/0'].workload_status == 'active'
182183

183184

185+
@base.bootstrapped
186+
@pytest.mark.bundle
187+
async def test_deploy_bundle_with_pinned_charm_revision():
188+
bundle_dir = INTEGRATION_TEST_DIR / 'bundle'
189+
bundle_yaml_path = bundle_dir / 'bundle-with-charm-revision.yaml'
190+
# Revision of the hello-juju charm defined in the bundle yaml
191+
# We can also read the yaml to get the revision but we are hard-coding it for now for simplicity
192+
pinned_revision = 7
193+
194+
async with base.CleanModel() as model:
195+
await model.deploy(str(bundle_yaml_path))
196+
197+
application = model.applications.get('hello-juju', None)
198+
status: FullStatus = await model.get_status([application.name])
199+
# the 'charm' field of application status should be of this format:
200+
# ch:amd64/{series}/{name}-{revision}
201+
assert f"{application.name}-{pinned_revision}" in status.applications[application.name]["charm"]
202+
203+
184204
@base.bootstrapped
185205
@pytest.mark.bundle
186206
async def test_deploy_invalid_bundle():

tests/unit/test_bundle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,14 @@ def test_dict_params(self):
312312
change = AddCharmChange(1, [], params={"charm": "charm",
313313
"series": "series",
314314
"channel": "channel",
315+
"revision": "revision",
315316
"architecture": "architecture"})
316317
self.assertEqual({"change_id": 1,
317318
"requires": [],
318319
"charm": "charm",
319320
"series": "series",
320321
"channel": "channel",
322+
"revision": "revision",
321323
"architecture": "architecture"}, change.__dict__)
322324

323325
def test_dict_params_missing_data(self):
@@ -328,6 +330,7 @@ def test_dict_params_missing_data(self):
328330
"charm": "charm",
329331
"series": "series",
330332
"channel": None,
333+
"revision": None,
331334
"architecture": None}, change.__dict__)
332335

333336

0 commit comments

Comments
 (0)