X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=examples%2Fadd_model.py;h=3e46490b20f6f45fcb89a173407c848467b03c74;hb=eac6d53d640fec2d1adab425c0ce891136b5784b;hp=323b6ec2b524da2183210608d45a262d7209035c;hpb=e42708b6ce89b35b88ae526065951f994128ceed;p=osm%2FN2VC.git diff --git a/examples/add_model.py b/examples/add_model.py index 323b6ec..3e46490 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,10 +51,16 @@ async def main(): print("Destroying model") await controller.destroy_model(model.info.uuid) + except Exception: + LOG.exception( + "Test failed! Model {} may not be cleaned up".format(model_name)) + finally: print('Disconnecting from controller') - await model.disconnect() + if model: + await model.disconnect() await controller.disconnect() -loop.run(main()) +if __name__ == '__main__': + loop.run(main())