Skip to content

Commit 59d5275

Browse files
committed
Test for detach storage & show_storage_details
1 parent 1caed77 commit 59d5275

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

juju/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ async def show_storage_details(self, *storage_ids):
970970

971971
storage_facade = client.StorageFacade.from_connection(self.connection())
972972
res = await storage_facade.StorageDetails(entities=[client.Entity(tag.storage(s)) for s in storage_ids])
973-
return res.results
973+
return [s.result.serialize() for s in res.results]
974974

975975
async def list_storage_pools(self):
976976
"""List storage pools.

juju/unit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def attach_storage(self, storage_ids=[]):
165165
unit_tag=self.tag,
166166
) for s_id in storage_ids])
167167

168-
async def detach_storage(self, force=False, *storage_ids):
168+
async def detach_storage(self, *storage_ids, force=False):
169169
"""Detaches storage from units.
170170
171171
:param bool force: Forcefully detach storage
@@ -176,13 +176,15 @@ async def detach_storage(self, force=False, *storage_ids):
176176
raise JujuError("Expected at least one storage ID")
177177

178178
storage_facade = client.StorageFacade.from_connection(self.connection)
179-
return await storage_facade.DetachStorage(
179+
ret = await storage_facade.DetachStorage(
180180
force=force,
181-
ids=[client.StorageAttachmentIds(ids=[client.StorageAttachmentId(
181+
ids=client.StorageAttachmentIds(ids=[client.StorageAttachmentId(
182182
storage_tag=tag.storage(s),
183183
unit_tag=self.tag,
184-
) for s in storage_ids])]
184+
) for s in storage_ids])
185185
)
186+
if ret.results[0].error:
187+
raise JujuError(ret.results[0].error.message)
186188

187189
async def run(self, command, timeout=None):
188190
"""Run command on this unit.

tests/integration/test_model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,29 @@ async def test_add_storage(event_loop):
10641064
assert any([tag.storage("pgdata") in s for s in ret])
10651065

10661066

1067+
@base.bootstrapped
1068+
@pytest.mark.asyncio
1069+
async def test_detach_storage(event_loop):
1070+
async with base.CleanModel() as model:
1071+
app = await model.deploy('postgresql')
1072+
await model.wait_for_idle(status="active")
1073+
unit = app.units[0]
1074+
storage_ids = await unit.add_storage("pgdata")
1075+
storage_id = storage_ids[0]
1076+
await jasyncio.sleep(5)
1077+
1078+
_storage_details_1 = await model.show_storage_details(storage_id)
1079+
storage_details_1 = _storage_details_1[0]
1080+
assert 'unit-postgresql-0' in storage_details_1['attachments']
1081+
1082+
await unit.detach_storage(storage_id)
1083+
await jasyncio.sleep(10)
1084+
1085+
_storage_details_2 = await model.show_storage_details(storage_id)
1086+
storage_details_2 = _storage_details_2[0]
1087+
assert 'unit-postgresql-0' not in storage_details_2['attachments']
1088+
1089+
10671090
@base.bootstrapped
10681091
@pytest.mark.asyncio
10691092
async def test_list_storage(event_loop):

0 commit comments

Comments
 (0)