Skip to content

Commit 8600362

Browse files
committed
Fix bundle deploy idempotency
When a bundle is deployed which contains an application which already exists in the model, the CLI will skip adding the application but libjuju will raise an error. This fixes the latter behavior.
1 parent 4ec4240 commit 8600362

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

juju/bundle.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ async def run(self, context):
329329
:param context: is used for any methods or properties required to
330330
perform a change.
331331
"""
332+
if self.application in context.model.applications:
333+
log.debug('Skipping %s; already in model', self.application)
334+
return self.application
335+
332336
# resolve indirect references
333337
charm = context.resolve(self.charm)
334338
options = {}

tests/unit/test_bundle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ async def test_run(self, event_loop):
166166
model = mock.Mock()
167167
model._deploy = base.AsyncMock(return_value=None)
168168
model._add_store_resources = base.AsyncMock(return_value=["resource1"])
169+
model.applications = {}
169170

170171
context = mock.Mock()
171172
context.resolve.return_value = "charm1"
@@ -192,6 +193,13 @@ async def test_run(self, event_loop):
192193
devices="devices",
193194
num_units="num_units")
194195

196+
# confirm that it's idempotent
197+
model.applications = {"application": None}
198+
result = await change.run(context)
199+
assert result == "application"
200+
model._add_store_resources.assert_called_once()
201+
model._deploy.assert_called_once()
202+
195203
@pytest.mark.asyncio
196204
async def test_run_local(self, event_loop):
197205
change = AddApplicationChange(1, [], params={"charm": "local:charm",
@@ -206,6 +214,7 @@ async def test_run_local(self, event_loop):
206214

207215
model = mock.Mock()
208216
model._deploy = base.AsyncMock(return_value=None)
217+
model.applications = {}
209218

210219
context = mock.Mock()
211220
context.resolve.return_value = "local:charm1"

0 commit comments

Comments
 (0)