From da3287e63d3032618a5700584ab05b01a0ec547a Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Mon, 15 Apr 2024 18:12:21 +0200 Subject: [PATCH 01/14] add missing "revision" parameter to addModel step. --- juju/bundle.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/juju/bundle.py b/juju/bundle.py index e8eee5731..12239c881 100644 --- a/juju/bundle.py +++ b/juju/bundle.py @@ -659,6 +659,7 @@ class AddCharmChange(ChangeInfo): _toPy = {'charm': 'charm', 'series': 'series', 'channel': 'channel', + 'revision': 'revision', 'architecture': 'architecture'} """AddCharmChange holds a change for adding a charm to the environment. @@ -675,6 +676,7 @@ class AddCharmChange(ChangeInfo): :series: series of the charm to be added if the charm default is not sufficient. :channel: preferred channel for obtaining the charm. + :revision: specified revision of the charm to be added if specified. """ @staticmethod def method(): @@ -710,6 +712,7 @@ async def run(self, context): architecture=arch, risk=ch.risk, track=ch.track, + revision=self.revision, base=base) identifier, origin = await context.model._resolve_charm(url, origin) From f50d247fe7a40d89892c4c5d9da4a8780196b0fe Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 16:44:22 +0200 Subject: [PATCH 02/14] update unit tests for new param --- tests/unit/test_bundle.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_bundle.py b/tests/unit/test_bundle.py index 22ea15877..5140dfd36 100644 --- a/tests/unit/test_bundle.py +++ b/tests/unit/test_bundle.py @@ -312,12 +312,14 @@ def test_dict_params(self): change = AddCharmChange(1, [], params={"charm": "charm", "series": "series", "channel": "channel", + "revision": "revision", "architecture": "architecture"}) self.assertEqual({"change_id": 1, "requires": [], "charm": "charm", "series": "series", "channel": "channel", + "revision": "revision", "architecture": "architecture"}, change.__dict__) def test_dict_params_missing_data(self): @@ -328,6 +330,7 @@ def test_dict_params_missing_data(self): "charm": "charm", "series": "series", "channel": None, + "revision": None, "architecture": None}, change.__dict__) From b450bc6e096b51f05f8f7b3940ab795caf593156 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:44:12 +0200 Subject: [PATCH 03/14] sort import and add integration test --- tests/integration/test_model.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index a2165e8fd..8dfd50976 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -10,17 +10,22 @@ import mock import paramiko - import pylxd import pytest + from juju import jasyncio, tag, url +from juju.application import Application from juju.client import client -from juju.errors import JujuError, JujuModelError, JujuUnitError, JujuConnectionError +from juju.client._definitions import FullStatus +from juju.errors import (JujuConnectionError, JujuError, JujuModelError, + JujuUnitError) from juju.model import Model, ModelObserver -from juju.utils import block_until, run_with_interrupt, wait_for_bundle, base_channel_to_series +from juju.utils import (base_channel_to_series, block_until, + run_with_interrupt, wait_for_bundle) from .. import base -from ..utils import MB, GB, TESTS_DIR, OVERLAYS_DIR, SSH_KEY, INTEGRATION_TEST_DIR +from ..utils import (GB, INTEGRATION_TEST_DIR, MB, OVERLAYS_DIR, SSH_KEY, + TESTS_DIR) @base.bootstrapped @@ -181,6 +186,25 @@ async def test_deploy_bundle_local_charm_series_manifest(): assert model.units['test1/0'].workload_status == 'active' +@base.bootstrapped +@pytest.mark.bundle +async def test_deploy_bundle_with_pinned_charm_revision(): + bundle_dir = INTEGRATION_TEST_DIR / 'bundle-with-charm-revision.yaml' + bundle_yaml_path = bundle_dir / 'bundle-include-file.yaml' + # Revision of the hello-juju charm defined in the bundle yaml + # We can also read the yaml to get the revision but wr're hard-coding it for now for simplicity + pinned_revision = 8 + + async with base.CleanModel() as model: + await model.deploy(str(bundle_yaml_path)) + + application: Application = model.applications.get('hello-juju', None) + status: FullStatus = await model.get_status([application.name]) + # the 'charm' field of application status should be of this format: + # ch:amd64/{series}/{name}-{revision} + assert f"{application.name}-{pinned_revision}" in status.applications[application.name]["charm"] + + @base.bootstrapped @pytest.mark.bundle async def test_deploy_invalid_bundle(): From a649d1f92817510295004265765ca1855cdf1c81 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:44:35 +0200 Subject: [PATCH 04/14] add bundle with pinned revision test file --- tests/integration/bundle/bundle-with-charm-revision.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/integration/bundle/bundle-with-charm-revision.yaml diff --git a/tests/integration/bundle/bundle-with-charm-revision.yaml b/tests/integration/bundle/bundle-with-charm-revision.yaml new file mode 100644 index 000000000..d2d3399e0 --- /dev/null +++ b/tests/integration/bundle/bundle-with-charm-revision.yaml @@ -0,0 +1,7 @@ +applications: + hello-juju: + charm: "hello-juju" + channel: latest/stable + revision: 8 + num_units: 1 + series: focal From 2c4b8cd177201637712e7052d42aa2a4e54ae7dd Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:45:57 +0200 Subject: [PATCH 05/14] refactor imports --- tests/integration/test_model.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 8dfd50976..53ab31b12 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -17,11 +17,19 @@ from juju.application import Application from juju.client import client from juju.client._definitions import FullStatus -from juju.errors import (JujuConnectionError, JujuError, JujuModelError, - JujuUnitError) +from juju.errors import ( + JujuConnectionError, + JujuError, + JujuModelError, + JujuUnitError +) from juju.model import Model, ModelObserver -from juju.utils import (base_channel_to_series, block_until, - run_with_interrupt, wait_for_bundle) +from juju.utils import ( + base_channel_to_series, + block_until, + run_with_interrupt, + wait_for_bundle +) from .. import base from ..utils import (GB, INTEGRATION_TEST_DIR, MB, OVERLAYS_DIR, SSH_KEY, From 7dfcfd05c0e12386edd17864c701af75dca261ab Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:49:14 +0200 Subject: [PATCH 06/14] more import refactoring --- tests/integration/test_model.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 53ab31b12..3c0313a2b 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -1,6 +1,7 @@ # Copyright 2023 Canonical Ltd. # Licensed under the Apache V2, see LICENCE file for details. + import json import os import random @@ -10,31 +11,18 @@ import mock import paramiko + import pylxd import pytest - from juju import jasyncio, tag, url -from juju.application import Application from juju.client import client from juju.client._definitions import FullStatus -from juju.errors import ( - JujuConnectionError, - JujuError, - JujuModelError, - JujuUnitError -) +from juju.errors import JujuError, JujuModelError, JujuUnitError, JujuConnectionError from juju.model import Model, ModelObserver -from juju.utils import ( - base_channel_to_series, - block_until, - run_with_interrupt, - wait_for_bundle -) +from juju.utils import block_until, run_with_interrupt, wait_for_bundle, base_channel_to_series from .. import base -from ..utils import (GB, INTEGRATION_TEST_DIR, MB, OVERLAYS_DIR, SSH_KEY, - TESTS_DIR) - +from ..utils import MB, GB, TESTS_DIR, OVERLAYS_DIR, SSH_KEY, INTEGRATION_TEST_DIR @base.bootstrapped async def test_model_name(): From 73c216daf34c63d92efe3646221bcc5804936bd0 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:51:00 +0200 Subject: [PATCH 07/14] add missing newline --- tests/integration/test_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 3c0313a2b..06317b3b5 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -24,6 +24,7 @@ from .. import base from ..utils import MB, GB, TESTS_DIR, OVERLAYS_DIR, SSH_KEY, INTEGRATION_TEST_DIR + @base.bootstrapped async def test_model_name(): model = Model() From 8ae928d248e07abf10901878f91638a04f9a86c3 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:51:36 +0200 Subject: [PATCH 08/14] remove type-hint --- tests/integration/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 06317b3b5..75e9bcf32 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -195,7 +195,7 @@ async def test_deploy_bundle_with_pinned_charm_revision(): async with base.CleanModel() as model: await model.deploy(str(bundle_yaml_path)) - application: Application = model.applications.get('hello-juju', None) + application = model.applications.get('hello-juju', None) status: FullStatus = await model.get_status([application.name]) # the 'charm' field of application status should be of this format: # ch:amd64/{series}/{name}-{revision} From 7748838bf33ddb27158289b55f9c6cf638bbf763 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Tue, 16 Apr 2024 17:52:11 +0200 Subject: [PATCH 09/14] remove extra new line --- tests/integration/test_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 75e9bcf32..bd64fdacb 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -1,7 +1,6 @@ # Copyright 2023 Canonical Ltd. # Licensed under the Apache V2, see LICENCE file for details. - import json import os import random From fcfa17dd6ad08f4d0af13a8352da1e9ac070169e Mon Sep 17 00:00:00 2001 From: Phan Trung Thanh Date: Wed, 17 Apr 2024 11:20:58 +0200 Subject: [PATCH 10/14] Update tests/integration/test_model.py Co-authored-by: Caner Derici --- tests/integration/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index bd64fdacb..b2919b73b 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -185,7 +185,7 @@ async def test_deploy_bundle_local_charm_series_manifest(): @base.bootstrapped @pytest.mark.bundle async def test_deploy_bundle_with_pinned_charm_revision(): - bundle_dir = INTEGRATION_TEST_DIR / 'bundle-with-charm-revision.yaml' + bundle_dir = INTEGRATION_TEST_DIR / 'bundle' bundle_yaml_path = bundle_dir / 'bundle-include-file.yaml' # Revision of the hello-juju charm defined in the bundle yaml # We can also read the yaml to get the revision but wr're hard-coding it for now for simplicity From 94f03d73ac90f4e8e65d1e33681436734c3e3196 Mon Sep 17 00:00:00 2001 From: Phan Trung Thanh Date: Wed, 17 Apr 2024 11:22:22 +0200 Subject: [PATCH 11/14] Update tests/integration/test_model.py Co-authored-by: Caner Derici --- tests/integration/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index b2919b73b..af3f2f7fb 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -186,7 +186,7 @@ async def test_deploy_bundle_local_charm_series_manifest(): @pytest.mark.bundle async def test_deploy_bundle_with_pinned_charm_revision(): bundle_dir = INTEGRATION_TEST_DIR / 'bundle' - bundle_yaml_path = bundle_dir / 'bundle-include-file.yaml' + bundle_yaml_path = bundle_dir / 'bundle-with-charm-revision.yaml' # Revision of the hello-juju charm defined in the bundle yaml # We can also read the yaml to get the revision but wr're hard-coding it for now for simplicity pinned_revision = 8 From cd01ce3fbf72ee4de91b8f7d73734f82d5a73601 Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Wed, 17 Apr 2024 11:23:29 +0200 Subject: [PATCH 12/14] correct typo --- tests/integration/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index bd64fdacb..482152aff 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -188,7 +188,7 @@ async def test_deploy_bundle_with_pinned_charm_revision(): bundle_dir = INTEGRATION_TEST_DIR / 'bundle-with-charm-revision.yaml' bundle_yaml_path = bundle_dir / 'bundle-include-file.yaml' # Revision of the hello-juju charm defined in the bundle yaml - # We can also read the yaml to get the revision but wr're hard-coding it for now for simplicity + # We can also read the yaml to get the revision but we are hard-coding it for now for simplicity pinned_revision = 8 async with base.CleanModel() as model: From bc84a16dc479dc9bfd8fa4aa9b6b00ae7644a29c Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Wed, 17 Apr 2024 12:20:24 +0200 Subject: [PATCH 13/14] use an old revision to avoid false-positives --- tests/integration/bundle/bundle-with-charm-revision.yaml | 2 +- tests/integration/test_model.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/bundle/bundle-with-charm-revision.yaml b/tests/integration/bundle/bundle-with-charm-revision.yaml index d2d3399e0..922993689 100644 --- a/tests/integration/bundle/bundle-with-charm-revision.yaml +++ b/tests/integration/bundle/bundle-with-charm-revision.yaml @@ -2,6 +2,6 @@ applications: hello-juju: charm: "hello-juju" channel: latest/stable - revision: 8 + revision: 7 num_units: 1 series: focal diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 9b65e1cd4..b078cc8db 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -189,7 +189,7 @@ async def test_deploy_bundle_with_pinned_charm_revision(): bundle_yaml_path = bundle_dir / 'bundle-with-charm-revision.yaml' # Revision of the hello-juju charm defined in the bundle yaml # We can also read the yaml to get the revision but we are hard-coding it for now for simplicity - pinned_revision = 8 + pinned_revision = 7 async with base.CleanModel() as model: await model.deploy(str(bundle_yaml_path)) From c8648b16bca13845dfe11690beb794091533bc4c Mon Sep 17 00:00:00 2001 From: Trung Thanh Phan Date: Wed, 17 Apr 2024 12:22:38 +0200 Subject: [PATCH 14/14] remove series as focal is not supported for rev7 --- tests/integration/bundle/bundle-with-charm-revision.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/bundle/bundle-with-charm-revision.yaml b/tests/integration/bundle/bundle-with-charm-revision.yaml index 922993689..fbd8c1574 100644 --- a/tests/integration/bundle/bundle-with-charm-revision.yaml +++ b/tests/integration/bundle/bundle-with-charm-revision.yaml @@ -4,4 +4,3 @@ applications: channel: latest/stable revision: 7 num_units: 1 - series: focal