~brendan-donegan/maas/qa-lab-tests_remove_arm64_temp

« back to all changes in this revision

Viewing changes to maas-rsd.py

  • Committer: MAAS Lander
  • Author(s): Brendan Donegan
  • Date: 2017-02-24 21:50:48 UTC
  • mfrom: (474.2.14 rsd-tests)
  • Revision ID: maas_lander-20170224215048-wcedablotdgn7d6i
[r=brendan-donegan][bug=][author=brendan-donegan] RSD tests and instructions for use

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from json import loads
 
2
from unittest import TestLoader
 
3
import yaml
 
4
from testtools import TestCase
 
5
from testtools.matchers import (
 
6
    ContainsDict,
 
7
    Equals,
 
8
    MatchesDict,
 
9
)
 
10
from timeout import timeout
 
11
from utils import (
 
12
    run_maas_cli,
 
13
    wait_machines,
 
14
)
 
15
 
 
16
from maasserver.enum import NODE_STATUS
 
17
 
 
18
tests_order = [
 
19
    'test_add_rsd_pod',
 
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',
 
29
]
 
30
 
 
31
 
 
32
def sorting_method(ignored, first_test, second_test):
 
33
    return tests_order.index(first_test) - tests_order.index(second_test)
 
34
 
 
35
 
 
36
TestLoader.sortTestMethodsUsing = sorting_method
 
37
 
 
38
RSD_CONFIG = yaml.load(open('rsd.yaml'))
 
39
RSD_POD_TYPE = 'rsd'
 
40
 
 
41
 
 
42
class TestRSD(TestCase):
 
43
 
 
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)
 
48
 
 
49
    def _run_maas_cli(self, args):
 
50
        return run_maas_cli(self, "rsd", args)
 
51
 
 
52
    def test_add_rsd_pod(self):
 
53
        output, _ = self._run_maas_cli([
 
54
            "pods",
 
55
            "create",
 
56
            "type={}".format(RSD_POD_TYPE),
 
57
            "power_address={}:{}".format(RSD_CONFIG['ip'],
 
58
                                         RSD_CONFIG['port']),
 
59
            "power_user={}".format(RSD_CONFIG['user']),
 
60
            "power_pass={}".format(RSD_CONFIG['pass']),
 
61
        ])
 
62
        rsd_pod = loads(output)
 
63
        pod_cfg = RSD_CONFIG['pod']
 
64
        self.assertThat(rsd_pod, ContainsDict(
 
65
            {
 
66
                "architectures": Equals(pod_cfg['architectures']),
 
67
                "type": Equals(RSD_POD_TYPE),
 
68
                "total": MatchesDict(
 
69
                    {
 
70
                        "cores": Equals(pod_cfg['total']['cores']),
 
71
                        "local_storage": Equals(
 
72
                            pod_cfg['total']['local_storage']
 
73
                        ),
 
74
                        "memory": Equals(pod_cfg['total']['memory']),
 
75
                        "local_disks": Equals(pod_cfg['total']['local_disks']),
 
76
                    }
 
77
                ),
 
78
                "available": MatchesDict(
 
79
                    {
 
80
                        "cores": Equals(pod_cfg['available']['cores']),
 
81
                        "local_storage": Equals(
 
82
                            pod_cfg['available']['local_storage']
 
83
                        ),
 
84
                        "memory": Equals(pod_cfg['available']['memory']),
 
85
                        "local_disks": Equals(
 
86
                            pod_cfg['available']['local_disks']
 
87
                        ),
 
88
                    }
 
89
                ),
 
90
                "used": MatchesDict(
 
91
                    {
 
92
                        "cores": Equals(pod_cfg['used']['cores']),
 
93
                        "local_storage": Equals(
 
94
                            pod_cfg['used']['local_storage']
 
95
                        ),
 
96
                        "memory": Equals(pod_cfg['used']['memory']),
 
97
                        "local_disks": Equals(pod_cfg['used']['local_disks']),
 
98
                    }
 
99
                ),
 
100
                "capabilities": Equals(pod_cfg['capabilities']),
 
101
            }
 
102
        ))
 
103
 
 
104
    @timeout(20*60)
 
105
    def test_precomposed_machines_commissioned(self):
 
106
        rsd_machines = self._wait_machines(NODE_STATUS.READY)
 
107
        hw = [
 
108
            {
 
109
                'memory': m['memory'], 'cpu_count': m['cpu_count']
 
110
            } for m in rsd_machines
 
111
        ]
 
112
        self.assertCountEqual(RSD_CONFIG['composed_machines'], hw)
 
113
 
 
114
    def _get_rsd_pod(self):
 
115
        output, _ = self._run_maas_cli(["pods", "read"])
 
116
        pods = loads(output)
 
117
        rsd_pods = [p for p in pods if p['type'] == RSD_POD_TYPE]
 
118
        self.assertThat(len(rsd_pods), Equals(1))
 
119
        return rsd_pods[0]
 
120
 
 
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"])
 
124
        tag = loads(output)
 
125
        self.assertThat(tag['name'], Equals('composed'))
 
126
        rsd_pod = self._get_rsd_pod()
 
127
        output, _ = self._run_maas_cli([
 
128
            "pod",
 
129
            "compose",
 
130
            "%s" % rsd_pod['id'],
 
131
        ])
 
132
        machine = loads(output)
 
133
        output, _ = self._run_maas_cli([
 
134
            "tag",
 
135
            "update-nodes",
 
136
            "composed",
 
137
            "add=" + machine['system_id'],
 
138
        ])
 
139
 
 
140
    def test_manually_compose_machine_with_constraints(self):
 
141
        rsd_pod = self._get_rsd_pod()
 
142
        output, _ = self._run_maas_cli([
 
143
            "pod",
 
144
            "compose",
 
145
            "%s" % rsd_pod['id'],
 
146
            "memory=31248",
 
147
            "cores=40",
 
148
        ])
 
149
        machine = loads(output)
 
150
        output, _ = self._run_maas_cli([
 
151
            "tag",
 
152
            "update-nodes",
 
153
            "composed",
 
154
            "add=" + machine['system_id'],
 
155
        ])
 
156
 
 
157
    @timeout(20*60)
 
158
    def test_manually_composed_machines_commissioned(self):
 
159
        rsd_machines = self._wait_machines(
 
160
            NODE_STATUS.READY,
 
161
            num_expected=len(RSD_CONFIG['composed_machines']) + 2,
 
162
        )
 
163
 
 
164
    @timeout(20*60)
 
165
    def test_allocate_rsd_machines(self):
 
166
        rsd_machines = self._wait_machines(
 
167
            NODE_STATUS.READY,
 
168
            num_expected=len(RSD_CONFIG['composed_machines']) + 2,
 
169
        )
 
170
        for machine in rsd_machines:
 
171
            self._run_maas_cli([
 
172
                "machines", "allocate", "system_id={}".format(
 
173
                    machine['system_id']
 
174
                )
 
175
            ])
 
176
        rsd_machines = self._wait_machines(
 
177
            NODE_STATUS.ALLOCATED,
 
178
            num_expected=len(RSD_CONFIG['composed_machines']) + 2,
 
179
        )
 
180
 
 
181
    @timeout(20*60)
 
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,
 
186
        )
 
187
        for machine in rsd_machines:
 
188
            self._run_maas_cli(
 
189
                ["machine", "deploy", machine['system_id']]
 
190
            )
 
191
        rsd_machines = self._wait_machines(
 
192
            NODE_STATUS.DEPLOYED,
 
193
            num_expected=len(RSD_CONFIG['composed_machines']) + 2,
 
194
        )
 
195
 
 
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"])
 
203
 
 
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']]
 
208
        )
 
209
        self.assertThat(err, Equals(""))
 
210
        output, _ = self._run_maas_cli(["pods", "read"])
 
211
        # Verify that the pod was deleted
 
212
        pods = loads(output)
 
213
        self.assertThat(len(pods), Equals(0))
 
214
 
 
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))