2
from unittest import TestLoader
4
from testtools import TestCase
5
from testtools.matchers import (
10
from timeout import timeout
16
from maasserver.enum import NODE_STATUS
20
'test_precomposed_machines_commissioned',
21
'test_manually_compose_machine_no_constraints',
22
'test_manually_compose_machine_with_constraints',
23
'test_manually_composed_machines_commissioned',
24
'test_allocate_rsd_machines',
25
'test_deploy_rsd_machines',
26
'test_delete_composed_machine',
27
'test_delete_rsd_pod',
28
'test_composed_machines_removed',
32
def sorting_method(ignored, first_test, second_test):
33
return tests_order.index(first_test) - tests_order.index(second_test)
36
TestLoader.sortTestMethodsUsing = sorting_method
38
RSD_CONFIG = yaml.load(open('rsd.yaml'))
42
class TestRSD(TestCase):
44
def _wait_machines(self, status=None, num_expected=None):
45
if num_expected is None:
46
num_expected = len(RSD_CONFIG['composed_machines'])
47
return wait_machines(self, num_expected, status)
49
def _run_maas_cli(self, args):
50
return run_maas_cli(self, "rsd", args)
52
def test_add_rsd_pod(self):
53
output, _ = self._run_maas_cli([
56
"type={}".format(RSD_POD_TYPE),
57
"power_address={}:{}".format(RSD_CONFIG['ip'],
59
"power_user={}".format(RSD_CONFIG['user']),
60
"power_pass={}".format(RSD_CONFIG['pass']),
62
rsd_pod = loads(output)
63
pod_cfg = RSD_CONFIG['pod']
64
self.assertThat(rsd_pod, ContainsDict(
66
"architectures": Equals(pod_cfg['architectures']),
67
"type": Equals(RSD_POD_TYPE),
70
"cores": Equals(pod_cfg['total']['cores']),
71
"local_storage": Equals(
72
pod_cfg['total']['local_storage']
74
"memory": Equals(pod_cfg['total']['memory']),
75
"local_disks": Equals(pod_cfg['total']['local_disks']),
78
"available": MatchesDict(
80
"cores": Equals(pod_cfg['available']['cores']),
81
"local_storage": Equals(
82
pod_cfg['available']['local_storage']
84
"memory": Equals(pod_cfg['available']['memory']),
85
"local_disks": Equals(
86
pod_cfg['available']['local_disks']
92
"cores": Equals(pod_cfg['used']['cores']),
93
"local_storage": Equals(
94
pod_cfg['used']['local_storage']
96
"memory": Equals(pod_cfg['used']['memory']),
97
"local_disks": Equals(pod_cfg['used']['local_disks']),
100
"capabilities": Equals(pod_cfg['capabilities']),
105
def test_precomposed_machines_commissioned(self):
106
rsd_machines = self._wait_machines(NODE_STATUS.READY)
109
'memory': m['memory'], 'cpu_count': m['cpu_count']
110
} for m in rsd_machines
112
self.assertCountEqual(RSD_CONFIG['composed_machines'], hw)
114
def _get_rsd_pod(self):
115
output, _ = self._run_maas_cli(["pods", "read"])
117
rsd_pods = [p for p in pods if p['type'] == RSD_POD_TYPE]
118
self.assertThat(len(rsd_pods), Equals(1))
121
def test_manually_compose_machine_no_constraints(self):
122
# Create a tag to tag composed machines with
123
output, _ = self._run_maas_cli(["tags", "create", "name=composed"])
125
self.assertThat(tag['name'], Equals('composed'))
126
rsd_pod = self._get_rsd_pod()
127
output, _ = self._run_maas_cli([
130
"%s" % rsd_pod['id'],
132
machine = loads(output)
133
output, _ = self._run_maas_cli([
137
"add=" + machine['system_id'],
140
def test_manually_compose_machine_with_constraints(self):
141
rsd_pod = self._get_rsd_pod()
142
output, _ = self._run_maas_cli([
145
"%s" % rsd_pod['id'],
149
machine = loads(output)
150
output, _ = self._run_maas_cli([
154
"add=" + machine['system_id'],
158
def test_manually_composed_machines_commissioned(self):
159
rsd_machines = self._wait_machines(
161
num_expected=len(RSD_CONFIG['composed_machines']) + 2,
165
def test_allocate_rsd_machines(self):
166
rsd_machines = self._wait_machines(
168
num_expected=len(RSD_CONFIG['composed_machines']) + 2,
170
for machine in rsd_machines:
172
"machines", "allocate", "system_id={}".format(
176
rsd_machines = self._wait_machines(
177
NODE_STATUS.ALLOCATED,
178
num_expected=len(RSD_CONFIG['composed_machines']) + 2,
182
def test_deploy_rsd_machines(self):
183
rsd_machines = self._wait_machines(
184
NODE_STATUS.ALLOCATED,
185
num_expected=len(RSD_CONFIG['composed_machines']) + 2,
187
for machine in rsd_machines:
189
["machine", "deploy", machine['system_id']]
191
rsd_machines = self._wait_machines(
192
NODE_STATUS.DEPLOYED,
193
num_expected=len(RSD_CONFIG['composed_machines']) + 2,
196
def test_delete_composed_machine(self):
197
output, _ = self._run_maas_cli(["tag", "machines", "composed"])
198
machines = loads(output)
199
for machine in machines:
200
self._run_maas_cli(["machine", "delete", machine['system_id']])
201
# Delete the 'composed' tag
202
self._run_maas_cli(["tag", "delete", "composed"])
204
def test_delete_rsd_pod(self):
205
rsd_pod = self._get_rsd_pod()
206
output, err = self._run_maas_cli(
207
["pod", "delete", "%s" % rsd_pod['id']]
209
self.assertThat(err, Equals(""))
210
output, _ = self._run_maas_cli(["pods", "read"])
211
# Verify that the pod was deleted
213
self.assertThat(len(pods), Equals(0))
215
def test_composed_machines_removed(self):
216
output, _ = self._run_maas_cli(["machines", "read"])
217
machines = loads(output)
218
self.assertThat(len(machines), Equals(0))