Merge commit '19031b24b523c872c1ac367821dc60c950a09755' as 'modules/libjuju'
[osm/N2VC.git] / modules / libjuju / tests / integration / test_application.py
1 import pytest
2
3 from .. import base
4
5 MB = 1
6
7
8 @base.bootstrapped
9 @pytest.mark.asyncio
10 async def test_action(event_loop):
11 async with base.CleanModel() as model:
12 ubuntu_app = await model.deploy(
13 'mysql',
14 application_name='mysql',
15 series='trusty',
16 channel='stable',
17 config={
18 'tuning-level': 'safest',
19 },
20 constraints={
21 'mem': 256 * MB,
22 },
23 )
24
25 # update and check app config
26 await ubuntu_app.set_config({'tuning-level': 'fast'})
27 config = await ubuntu_app.get_config()
28 assert config['tuning-level']['value'] == 'fast'
29
30 # update and check app constraints
31 await ubuntu_app.set_constraints({'mem': 512 * MB})
32 constraints = await ubuntu_app.get_constraints()
33 assert constraints['mem'] == 512 * MB
34
35
36 @base.bootstrapped
37 @pytest.mark.asyncio
38 async def test_add_units(event_loop):
39 from juju.unit import Unit
40
41 async with base.CleanModel() as model:
42 app = await model.deploy(
43 'ubuntu-0',
44 application_name='ubuntu',
45 series='trusty',
46 channel='stable',
47 )
48 units = await app.add_units(count=2)
49
50 assert len(units) == 2
51 for unit in units:
52 assert isinstance(unit, Unit)
53
54
55 @base.bootstrapped
56 @pytest.mark.asyncio
57 async def test_upgrade_charm(event_loop):
58 async with base.CleanModel() as model:
59 app = await model.deploy('ubuntu-0')
60 assert app.data['charm-url'] == 'cs:ubuntu-0'
61 await app.upgrade_charm()
62 assert app.data['charm-url'].startswith('cs:ubuntu-')
63 assert app.data['charm-url'] != 'cs:ubuntu-0'
64
65
66 @base.bootstrapped
67 @pytest.mark.asyncio
68 async def test_upgrade_charm_channel(event_loop):
69 async with base.CleanModel() as model:
70 app = await model.deploy('ubuntu-0')
71 assert app.data['charm-url'] == 'cs:ubuntu-0'
72 await app.upgrade_charm(channel='stable')
73 assert app.data['charm-url'].startswith('cs:ubuntu-')
74 assert app.data['charm-url'] != 'cs:ubuntu-0'
75
76
77 @base.bootstrapped
78 @pytest.mark.asyncio
79 async def test_upgrade_charm_revision(event_loop):
80 async with base.CleanModel() as model:
81 app = await model.deploy('ubuntu-0')
82 assert app.data['charm-url'] == 'cs:ubuntu-0'
83 await app.upgrade_charm(revision=8)
84 assert app.data['charm-url'] == 'cs:ubuntu-8'
85
86
87 @base.bootstrapped
88 @pytest.mark.asyncio
89 async def test_upgrade_charm_switch(event_loop):
90 async with base.CleanModel() as model:
91 app = await model.deploy('ubuntu-0')
92 assert app.data['charm-url'] == 'cs:ubuntu-0'
93 await app.upgrade_charm(switch='ubuntu-8')
94 assert app.data['charm-url'] == 'cs:ubuntu-8'