9ae92048a5598361145f11332f3a1c372aa9b73b
[osm/N2VC.git] / tests / functional / 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_add_machine(event_loop):
12 from juju.machine import Machine
13
14 async with base.CleanModel() as model:
15 # add a new default machine
16 machine1 = await model.add_machine()
17
18 # add a machine with constraints, disks, and series
19 machine2 = await model.add_machine(
20 constraints={
21 'mem': 256 * MB,
22 },
23 disks=[{
24 'pool': 'rootfs',
25 'size': 10 * GB,
26 'count': 1,
27 }],
28 series='xenial',
29 )
30
31 # add a lxd container to machine2
32 machine3 = await model.add_machine(
33 'lxd:{}'.format(machine2.id))
34
35 for m in (machine1, machine2, machine3):
36 assert isinstance(m, Machine)
37
38 assert len(model.machines) == 3
39
40 await machine3.destroy(force=True)
41 await machine2.destroy(force=True)
42 res = await machine1.destroy(force=True)
43
44 assert res is None
45 assert len(model.machines) == 0