Skip to content

Commit 53cd33d

Browse files
authored
Merge pull request #1053 from luissimas/fix-storage-constraints
#1053 #### Description Fixes: #1052. 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. #### QA Steps The following python script can be used to verify both the bug in the current version as well as the fix implemented: ```python import asyncio from juju.model import Model bundle_file = "./bundle.yaml" bundle = """ name: sample-bundle series: jammy machines: "0": constraints: instance-type=type1 applications: swift-storage: charm: swift-storage channel: yoga/stable num_units: 1 to: - "0" storage: block-devices: cinder,1,5G """ async def main(): with open(bundle_file, "w") as f: f.write(bundle) model = Model() await model.connect() await model.deploy(bundle_file) asyncio.run(main()) ``` All CI tests need to pass. #### Notes & Discussion I wasn't able to add a regression test for this fix since the `juju-qa-test` charm does not support the addition of storage devices. With that said, I'm open to suggestions on how to test this behavior to make sure it's correct and that it stays that way on future changes.
2 parents 77f02b2 + 49b1fdd commit 53cd33d

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

juju/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .client import client, connector
3030
from .client.overrides import Caveat, Macaroon
3131
from .constraints import parse as parse_constraints
32+
from .constraints import parse_storage_constraint
3233
from .controller import Controller, ConnectedController
3334
from .delta import get_entity_class, get_entity_delta
3435
from .errors import JujuAPIError, JujuError, JujuModelConfigError, JujuBackupError
@@ -2115,7 +2116,7 @@ async def _deploy(self, charm_url, application, series, config,
21152116
devices=devices,
21162117
dryrun=False,
21172118
placement=placement,
2118-
storage=storage,
2119+
storage={k: parse_storage_constraint(v) for k, v in (storage or dict()).items()},
21192120
trust=trust,
21202121
base=charm_origin.base,
21212122
channel=channel,
@@ -2150,7 +2151,7 @@ async def _deploy(self, charm_url, application, series, config,
21502151
endpoint_bindings=endpoint_bindings,
21512152
num_units=num_units,
21522153
resources=resources,
2153-
storage=storage,
2154+
storage={k: parse_storage_constraint(v) for k, v in (storage or dict()).items()},
21542155
placement=placement,
21552156
devices=devices,
21562157
attach_storage=attach_storage,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: bundle-with-storage-constraint
2+
3+
series: jammy
4+
5+
applications:
6+
postgresql:
7+
charm: postgresql
8+
num_units: 1
9+
channel: 14/stable
10+
storage:
11+
pgdata: lxd,8G

tests/integration/test_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ async def test_deploy_invalid_bundle():
211211
await model.deploy(str(bundle_path))
212212

213213

214+
@base.bootstrapped
215+
@pytest.mark.bundle
216+
async def test_deploy_bundle_with_storage_constraint():
217+
bundle_path = INTEGRATION_TEST_DIR / 'bundle' / 'bundle-with-storage-constraint.yaml'
218+
219+
async with base.CleanModel() as model:
220+
await model.deploy(bundle_path)
221+
await wait_for_bundle(model, bundle_path)
222+
storage = await model.list_storage()
223+
assert len(storage) == 1
224+
225+
214226
@base.bootstrapped
215227
async def test_deploy_local_charm():
216228
charm_path = TESTS_DIR / 'charm'

0 commit comments

Comments
 (0)