1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Compute API Test (Host Aggregates)"""
18
19
20 import time
21
22 from yakumo.smoketest import *
23 from yakumo import utils
24
25
26 -def main(c, **kwargs):
27
28 metadata = {'foo': 'bar', 'foo2': 'bar2'}
29 LOG.info("Metadata: %s", metadata)
30
31 hosts = [_.host for _ in c.nova.service.find(binary='nova-compute')]
32
33 LOG.info("Create Aggregate #1")
34 name = get_random_str('aggregate')
35 with c.aggregate.create(name=name,
36 availability_zone='foo',
37 metadata=metadata) as a:
38
39 LOG.debug("list aggregates: %s", [_.name for _ in c.aggregate.list()])
40
41 test("Aggregate #1 name is " + name, a.name == name)
42 test("Aggregate #1 is availability_zone",
43 a.availability_zone == 'foo')
44
45 LOG.debug("Initial metadata: %s", a.metadata)
46 test("Metadata has %s" % metadata, a.metadata == metadata)
47
48 m = {'foo2': 'bar4', 'foo3': 'bar3'}
49 LOG.debug("Set metadata : %s", m)
50 metadata.update(m)
51 a.set_metadata(**m)
52 LOG.debug("Updated metadata: %s", a.metadata)
53 test("Metadata has %s" % metadata, a.metadata == metadata)
54
55 m = ['foo', 'foo2']
56 LOG.debug("Unset metadata : %s", m)
57 for key in m:
58 metadata.pop(key)
59 a.unset_metadata(*m)
60 LOG.debug("Updated metadata: %s", a.metadata)
61 test("Metadata has %s" % metadata, a.metadata == metadata)
62
63 LOG.debug("Initial hosts: %s", a.hosts)
64
65 LOG.debug("Register hosts: %s", hosts)
66 a.add_hosts(*hosts)
67 LOG.debug("Updated hosts: %s", a.hosts)
68 test("Aggregate has hosts: %s" % hosts, a.hosts == hosts)
69
70 LOG.debug("Unregister hosts: %s", hosts)
71 a.remove_hosts(*hosts)
72 LOG.debug("Updated hosts: %s", a.hosts)
73 test("Aggregate has no hosts", a.hosts == [])
74
75 test("Aggregate #1 is deleted", a not in c.server.list())
76
77
78 if __name__ == '__main__':
79 c = utils.get_client()
80
81 LOG.debug("list aggregates: %s", [_.name for _ in c.aggregate.list()])
82 main(c)
83 LOG.debug("list aggregates: %s", [_.name for _ in c.aggregate.list()])
84
85 show_test_summary()
86