Skip to content

Commit 1943665

Browse files
committed
Test and fixup for remove_storage
1 parent 59d5275 commit 1943665

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

juju/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ async def list_storage_pools(self):
985985
raise JujuError(err.message)
986986
return [p.serialize() for p in res.results[0].storage_pools]
987987

988-
async def remove_storage(self, force=False, destroy_storage=False, *storage_ids):
988+
async def remove_storage(self, *storage_ids, force=False, destroy_storage=False):
989989
"""Removes storage from the model.
990990
991991
:param bool force: Remove storage even if it is currently attached
@@ -997,11 +997,13 @@ async def remove_storage(self, force=False, destroy_storage=False, *storage_ids)
997997
raise JujuError("Expected at least one storage ID")
998998

999999
storage_facade = client.StorageFacade.from_connection(self.connection())
1000-
return await storage_facade.Remove(storage=[client.RemoveStorageInstance(
1000+
ret = await storage_facade.Remove(storage=[client.RemoveStorageInstance(
10011001
destroy_storage=destroy_storage,
1002-
force=False,
1003-
tag=tag.storage(s)
1002+
force=force,
1003+
tag=s,
10041004
) for s in storage_ids])
1005+
if ret.results[0].error:
1006+
raise JujuError(ret.results[0].error.message)
10051007

10061008
async def remove_application(self, app_name, block_until_done=False):
10071009
"""Removes the given application from the model.

tests/integration/test_model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,14 @@ async def test_detach_storage(event_loop):
10841084

10851085
_storage_details_2 = await model.show_storage_details(storage_id)
10861086
storage_details_2 = _storage_details_2[0]
1087-
assert 'unit-postgresql-0' not in storage_details_2['attachments']
1087+
assert ('unit-postgresql-0' not in storage_details_2['attachments']) or \
1088+
storage_details_2['attachments']['unit-postgresql-0'].life == 'dying'
1089+
1090+
# remove_storage
1091+
await model.remove_storage(storage_id)
1092+
await jasyncio.sleep(10)
1093+
storages = await model.list_storage()
1094+
assert all([storage_id not in s['storage-tag'] for s in storages])
10881095

10891096

10901097
@base.bootstrapped

0 commit comments

Comments
 (0)