X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=examples%2Fadd_model.py;h=e70345038d97a7d684d02b2342d7c6afab85b424;hb=e2a3f01e7bb983ac3cd8eb24117e0d4208b40cc9;hp=323b6ec2b524da2183210608d45a262d7209035c;hpb=e42708b6ce89b35b88ae526065951f994128ceed;p=osm%2FN2VC.git diff --git a/examples/add_model.py b/examples/add_model.py index 323b6ec..e703450 100644 --- a/examples/add_model.py +++ b/examples/add_model.py @@ -11,6 +11,7 @@ from juju import utils from juju.controller import Controller import asyncio from logging import getLogger +import uuid LOG = getLogger(__name__) @@ -21,7 +22,9 @@ async def main(): await controller.connect_current() try: - model = await controller.add_model("quux") + model_name = "addmodeltest-{}".format(uuid.uuid4()) + print("Adding model {}".format(model_name)) + model = await controller.add_model(model_name) print('Deploying ubuntu') application = await model.deploy( @@ -38,7 +41,8 @@ async def main(): for unit in application.units)) print("Verifying that we can ssh into the created model") - ret = utils.execute_process('juju', 'ssh', 'ls /', log=LOG) + ret = await utils.execute_process( + 'juju', 'ssh', '-m', model_name, 'ubuntu/0', 'ls /', log=LOG) assert ret print('Removing ubuntu') @@ -47,6 +51,10 @@ async def main(): print("Destroying model") await controller.destroy_model(model.info.uuid) + except Exception as e: + LOG.exception( + "Test failed! Model {} may not be cleaned up".format(model_name)) + finally: print('Disconnecting from controller') await model.disconnect()