Skip to content

Commit 4c44e9b

Browse files
authored
Merge pull request #902 from cderici/model-name-on-2.9
#902 #### Description Backports `model.name` from HEAD into 2.9. Gets this particular change from 55ea0e2 adds the name property into a Model object. Couldn't directly cherry pick because of the other stuff in the commit. Fixes #893 #### QA Steps Also backports the integration test as well, so: ``` tox -e integration -- tests/integration/test_model.py::test_model_name ```
2 parents e0c5d8b + f16e7aa commit 4c44e9b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

juju/model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,14 @@ async def get_info(self):
10211021

10221022
return self.info
10231023

1024+
@property
1025+
def name(self):
1026+
"""Return the name of this model
1027+
"""
1028+
if self._info is None:
1029+
raise JujuError("Model is not connected")
1030+
return self._info.name
1031+
10241032
@property
10251033
def info(self):
10261034
"""Return the cached client.ModelInfo object for this Model.

tests/integration/test_model.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
from ..utils import MB, GB, TESTS_DIR, OVERLAYS_DIR, SSH_KEY, INTEGRATION_TEST_DIR
2222

2323

24+
@base.bootstrapped
25+
@pytest.mark.asyncio
26+
async def test_model_name(event_loop):
27+
model = Model()
28+
with pytest.raises(JujuError):
29+
model.name
30+
31+
async with base.CleanModel() as new_model:
32+
await model.connect(new_model.name)
33+
assert model.name == new_model.name
34+
await model.disconnect()
35+
36+
2437
@base.bootstrapped
2538
@pytest.mark.asyncio
2639
async def test_deploy_local_bundle_dir(event_loop):

0 commit comments

Comments
 (0)