Skip to content

Commit 1c3c9c5

Browse files
committed
Test and cleanup list_storage
1 parent 019b8e6 commit 1c3c9c5

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

juju/model.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,16 +940,24 @@ async def list_storage(self, filesystem=False, volume=False):
940940
:param bool volume: List volume storage
941941
:return:
942942
"""
943-
storage_facade = client.StorageFacade.from_connection(self.connection)
943+
storage_facade = client.StorageFacade.from_connection(self.connection())
944+
944945
if filesystem and volume:
945946
raise JujuError("--filesystem and --volume can not be used together")
946947
if filesystem:
947-
res = await storage_facade.ListFilesystems(filters=[])
948+
_res = await storage_facade.ListFilesystems(filters=[client.FilesystemFilter()])
948949
elif volume:
949-
res = await storage_facade.ListVolumes(filters=[])
950+
_res = await storage_facade.ListVolumes(filters=[client.VolumeFilter()])
950951
else:
951-
res = await storage_facade.ListStorageDetails(filters=[])
952-
return res.results
952+
_res = await storage_facade.ListStorageDetails(filters=[client.StorageFilter()])
953+
954+
err = _res.results[0].error
955+
res = _res.results[0].result
956+
957+
if err is not None:
958+
raise JujuError(err.message)
959+
960+
return [details.serialize() for details in res]
953961

954962
async def show_storage_details(self, *storage_ids):
955963
"""Shows storage instance information.

tests/integration/test_model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,18 @@ async def test_add_storage(event_loop):
10621062
unit = app.units[0]
10631063
ret = await unit.add_storage("pgdata")
10641064
assert any([tag.storage("pgdata") in s for s in ret])
1065+
1066+
1067+
@base.bootstrapped
1068+
@pytest.mark.asyncio
1069+
async def test_list_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+
await unit.add_storage("pgdata")
1075+
storages = await model.list_storage()
1076+
await model.list_storage(filesystem=True)
1077+
await model.list_storage(volume=True)
1078+
1079+
assert any([tag.storage("pgdata") in s['storage-tag'] for s in storages])

0 commit comments

Comments
 (0)