blob: 88766f15b08e346515f040a024b3fd56a037ca0c [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Creates a model on the current controller
52. Deploys a charm to it.
63. Attempts to ssh into the charm
7
8"""
9from juju import loop
10from juju import utils
11from juju.controller import Controller
12import asyncio
13from logging import getLogger
14import uuid
15
16LOG = getLogger(__name__)
17
18
19async def main():
20 controller = Controller()
21 print("Connecting to controller")
Adam Israelb0943662018-08-02 15:32:00 -040022 # connect to current controller with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050023 await controller.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040024
25 try:
26 model_name = "addmodeltest-{}".format(uuid.uuid4())
27 print("Adding model {}".format(model_name))
28 model = await controller.add_model(model_name)
29
30 print('Deploying ubuntu')
31 application = await model.deploy(
32 'ubuntu-10',
33 application_name='ubuntu',
34 series='trusty',
35 channel='stable',
36 )
37
38 print('Waiting for active')
39 await asyncio.sleep(10)
40 await model.block_until(
41 lambda: all(unit.workload_status == 'active'
42 for unit in application.units))
43
44 print("Verifying that we can ssh into the created model")
45 ret = await utils.execute_process(
46 'juju', 'ssh', '-m', model_name, 'ubuntu/0', 'ls /', log=LOG)
47 assert ret
48
49 print('Removing ubuntu')
50 await application.remove()
51
52 print("Destroying model")
53 await controller.destroy_model(model.info.uuid)
54
55 except Exception:
56 LOG.exception(
57 "Test failed! Model {} may not be cleaned up".format(model_name))
58
59 finally:
60 print('Disconnecting from controller')
61 if model:
62 await model.disconnect()
63 await controller.disconnect()
64
65
66if __name__ == '__main__':
67 loop.run(main())