From 18b2325145be314be9cf3e37d75e49abf587b093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Simas?= Date: Mon, 20 May 2024 10:54:47 -0300 Subject: [PATCH 1/3] fix parsing of storage constraints Parses the storage constraints when deploying applications. Before this change the storage constraints where not parsing, resulting in an error when deploying bundles that contained applications with storage definitions. --- juju/model.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/juju/model.py b/juju/model.py index ab5bb88d3..45faa99e2 100644 --- a/juju/model.py +++ b/juju/model.py @@ -29,6 +29,7 @@ from .client import client, connector from .client.overrides import Caveat, Macaroon from .constraints import parse as parse_constraints +from .constraints import parse_storage_constraint from .controller import Controller, ConnectedController from .delta import get_entity_class, get_entity_delta from .errors import JujuAPIError, JujuError, JujuModelConfigError, JujuBackupError @@ -2115,7 +2116,7 @@ async def _deploy(self, charm_url, application, series, config, devices=devices, dryrun=False, placement=placement, - storage=storage, + storage={k: parse_storage_constraint(v) for k, v in (storage or dict()).items()}, trust=trust, base=charm_origin.base, channel=channel, @@ -2150,7 +2151,7 @@ async def _deploy(self, charm_url, application, series, config, endpoint_bindings=endpoint_bindings, num_units=num_units, resources=resources, - storage=storage, + storage={k: parse_storage_constraint(v) for k, v in (storage or dict()).items()}, placement=placement, devices=devices, attach_storage=attach_storage, From 79f4b2a213413819d57252d3e8b394fced99b113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Simas?= Date: Fri, 31 May 2024 11:46:35 -0300 Subject: [PATCH 2/3] add storage constraint integration test --- .../bundle/bundle-with-storage-constraint.yaml | 11 +++++++++++ tests/integration/test_model.py | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/integration/bundle/bundle-with-storage-constraint.yaml diff --git a/tests/integration/bundle/bundle-with-storage-constraint.yaml b/tests/integration/bundle/bundle-with-storage-constraint.yaml new file mode 100644 index 000000000..4fd78612b --- /dev/null +++ b/tests/integration/bundle/bundle-with-storage-constraint.yaml @@ -0,0 +1,11 @@ +name: bundle-with-storage-constraint + +series: jammy + +applications: + postgresql: + charm: postgresql + num_units: 1 + channel: 14/stable + storage: + pgdata: lxd,8G diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index b078cc8db..c5fa2eb5d 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -210,6 +210,17 @@ async def test_deploy_invalid_bundle(): with pytest.raises(JujuError): await model.deploy(str(bundle_path)) +@base.bootstrapped +@pytest.mark.bundle +async def test_deploy_bundle_with_storage_constraint(): + bundle_path = INTEGRATION_TEST_DIR / 'bundle' / 'bundle-with-storage-constraint.yaml' + + async with base.CleanModel() as model: + await model.deploy(bundle_path) + await wait_for_bundle(model, bundle_path) + storage = await model.list_storage() + assert len(storage) == 1 + @base.bootstrapped async def test_deploy_local_charm(): From 49b1fddcd3869cd79917d7c126065d9865bc945b Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Fri, 31 May 2024 11:40:06 -0600 Subject: [PATCH 3/3] fix(linter): test bundle storage constraint --- 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 c5fa2eb5d..d10e3fbbe 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -210,6 +210,7 @@ async def test_deploy_invalid_bundle(): with pytest.raises(JujuError): await model.deploy(str(bundle_path)) + @base.bootstrapped @pytest.mark.bundle async def test_deploy_bundle_with_storage_constraint():