Add integration tests.
[osm/N2VC.git] / tests / integration / test_model.py
1 import pytest
2
3 from .. import base
4
5 MB = 1
6 GB = 1024
7
8
9 @base.bootstrapped
10 @pytest.mark.asyncio
11 async def test_deploy_local_bundle(event_loop):
12 from pathlib import Path
13 tests_dir = Path(__file__).absolute().parent.parent
14 bundle_path = tests_dir / 'bundle'
15
16 async with base.CleanModel() as model:
17 await model.deploy(str(bundle_path))
18
19 for app in ('wordpress', 'mysql'):
20 assert app in model.applications
21
22
23 @base.bootstrapped
24 @pytest.mark.asyncio
25 async def test_deploy_bundle(event_loop):
26 async with base.CleanModel() as model:
27 await model.deploy('bundle/wiki-simple')
28
29 for app in ('wiki', 'mysql'):
30 assert app in model.applications
31
32
33 @base.bootstrapped
34 @pytest.mark.asyncio
35 async def test_add_machine(event_loop):
36 from juju.machine import Machine
37
38 async with base.CleanModel() as model:
39 # add a new default machine
40 machine1 = await model.add_machine()
41
42 # add a machine with constraints, disks, and series
43 machine2 = await model.add_machine(
44 constraints={
45 'mem': 256 * MB,
46 },
47 disks=[{
48 'pool': 'rootfs',
49 'size': 10 * GB,
50 'count': 1,
51 }],
52 series='xenial',
53 )
54
55 # add a lxd container to machine2
56 machine3 = await model.add_machine(
57 'lxd:{}'.format(machine2.id))
58
59 for m in (machine1, machine2, machine3):
60 assert isinstance(m, Machine)
61
62 assert len(model.machines) == 3
63
64 await machine3.destroy(force=True)
65 await machine2.destroy(force=True)
66 res = await machine1.destroy(force=True)
67
68 assert res is None
69 assert len(model.machines) == 0
70
71
72 @base.bootstrapped
73 @pytest.mark.asyncio
74 async def test_relate(event_loop):
75 from juju.relation import Relation
76
77 async with base.CleanModel() as model:
78 await model.deploy(
79 'ubuntu',
80 application_name='ubuntu',
81 series='trusty',
82 channel='stable',
83 )
84 await model.deploy(
85 'nrpe',
86 application_name='nrpe',
87 series='trusty',
88 channel='stable',
89 # subordinates must be deployed without units
90 num_units=0,
91 )
92 my_relation = await model.add_relation(
93 'ubuntu',
94 'nrpe',
95 )
96
97 assert isinstance(my_relation, Relation)