52d8a037821084990d1b1c9d38196923abf7ce05
[osm/N2VC.git] / tests / functional / test_model.py
1 import uuid
2
3 import pytest
4
5 from juju.controller import Controller
6
7 from ..base import bootstrapped
8
9 MB = 1
10 GB = 1024
11
12
13 class CleanModel():
14 def __init__(self):
15 self.controller = None
16 self.model = None
17
18 async def __aenter__(self):
19 self.controller = Controller()
20 await self.controller.connect_current()
21
22 model_name = 'model-{}'.format(uuid.uuid4())
23 self.model = await self.controller.add_model(model_name)
24
25 return self.model
26
27 async def __aexit__(self, exc_type, exc, tb):
28 await self.model.disconnect()
29 await self.controller.destroy_model(self.model.info.uuid)
30 await self.controller.disconnect()
31
32
33 @bootstrapped
34 @pytest.mark.asyncio
35 async def test_add_machine(event_loop):
36 from juju.machine import Machine
37
38 async with 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