Skip to content

Commit 019b8e6

Browse files
committed
Test and cleanup add_storage
1 parent dd9faf5 commit 019b8e6

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

juju/unit.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,23 @@ async def add_storage(self, storage_name, pool=None, count=1, size=1024):
132132
by the charm, which can specify a maximum number of storage instances per unit.
133133
:param: int size: the required size of the storage instance, in MiB.
134134
135-
:return:
135+
:return: []str storage_tags
136136
"""
137-
constraints = None
137+
constraints = client.StorageConstraints(count=count)
138138
if pool:
139139
constraints = client.StorageConstraints(pool=pool, count=count, size=size)
140140

141141
storage_facade = client.StorageFacade.from_connection(self.connection)
142-
return await storage_facade.AddToUnit(storages=[client.StorageAddParams(
142+
res = await storage_facade.AddToUnit(storages=[client.StorageAddParams(
143143
name=storage_name,
144144
unit=tag.unit(self.name),
145145
storage=constraints,
146146
)])
147+
result = res.results[0]
148+
if result.error is not None:
149+
raise JujuError("{}".format(result.error))
150+
storage_details = result.result
151+
return storage_details.storage_tags
147152

148153
async def attach_storage(self, storage_ids=[]):
149154
"""Attaches existing storage to this unit.

tests/integration/test_model.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import pylxd
1414
import pytest
15-
from juju import jasyncio
15+
from juju import jasyncio, tag
1616
from juju.client import client
1717
from juju.errors import JujuError, JujuUnitError, JujuConnectionError
1818
from juju.model import Model, ModelObserver
@@ -1051,3 +1051,14 @@ async def test_model_cache_update(event_loop):
10511051
await model.disconnect()
10521052
await m.disconnect()
10531053
await controller.destroy_models(model_name)
1054+
1055+
1056+
@base.bootstrapped
1057+
@pytest.mark.asyncio
1058+
async def test_add_storage(event_loop):
1059+
async with base.CleanModel() as model:
1060+
app = await model.deploy('postgresql')
1061+
await model.wait_for_idle(status="active")
1062+
unit = app.units[0]
1063+
ret = await unit.add_storage("pgdata")
1064+
assert any([tag.storage("pgdata") in s for s in ret])

0 commit comments

Comments
 (0)