Add integration tests.
[osm/N2VC.git] / examples / config.py
1 """
2 This example:
3
4 1. Connects to the current model
5 2. Resets it
6 3. Deploys a charm and prints its config and constraints
7
8 """
9 import asyncio
10 import logging
11
12 from juju.model import Model
13
14 log = logging.getLogger(__name__)
15
16 MB = 1
17
18
19 async def run():
20 model = Model()
21 await model.connect_current()
22 await model.reset(force=True)
23
24 ubuntu_app = await model.deploy(
25 'mysql',
26 application_name='mysql',
27 series='trusty',
28 channel='stable',
29 config={
30 'tuning-level': 'safest',
31 },
32 constraints={
33 'mem': 256 * MB,
34 },
35 )
36
37 # update and check app config
38 await ubuntu_app.set_config({'tuning-level': 'fast'})
39 config = await ubuntu_app.get_config()
40 assert(config['tuning-level']['value'] == 'fast')
41
42 # update and check app constraints
43 await ubuntu_app.set_constraints({'mem': 512 * MB})
44 constraints = await ubuntu_app.get_constraints()
45 assert(constraints['mem'] == 512 * MB)
46
47 await model.disconnect()
48 model.loop.stop()
49
50 logging.basicConfig(level=logging.DEBUG)
51 ws_logger = logging.getLogger('websockets.protocol')
52 ws_logger.setLevel(logging.INFO)
53 loop = asyncio.get_event_loop()
54 loop.set_debug(False)
55 loop.create_task(run())
56 loop.run_forever()