summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_aggregates.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_aggregates.py')
-rw-r--r--novaclient/tests/unit/v2/test_aggregates.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_aggregates.py b/novaclient/tests/unit/v2/test_aggregates.py
new file mode 100644
index 0000000..97a3ffc
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_aggregates.py
@@ -0,0 +1,141 @@
1# Copyright 2012 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient.tests.unit.fixture_data import aggregates as data
17from novaclient.tests.unit.fixture_data import client
18from novaclient.tests.unit import utils
19from novaclient.v2 import aggregates
20
21
22class AggregatesTest(utils.FixturedTestCase):
23
24 data_fixture_class = data.Fixture
25
26 scenarios = [('original', {'client_fixture_class': client.V1}),
27 ('session', {'client_fixture_class': client.SessionV1})]
28
29 def test_list_aggregates(self):
30 result = self.cs.aggregates.list()
31 self.assert_called('GET', '/os-aggregates')
32 for aggregate in result:
33 self.assertIsInstance(aggregate, aggregates.Aggregate)
34
35 def test_create_aggregate(self):
36 body = {"aggregate": {"name": "test", "availability_zone": "nova1"}}
37 aggregate = self.cs.aggregates.create("test", "nova1")
38 self.assert_called('POST', '/os-aggregates', body)
39 self.assertIsInstance(aggregate, aggregates.Aggregate)
40
41 def test_get(self):
42 aggregate = self.cs.aggregates.get("1")
43 self.assert_called('GET', '/os-aggregates/1')
44 self.assertIsInstance(aggregate, aggregates.Aggregate)
45
46 aggregate2 = self.cs.aggregates.get(aggregate)
47 self.assert_called('GET', '/os-aggregates/1')
48 self.assertIsInstance(aggregate2, aggregates.Aggregate)
49
50 def test_get_details(self):
51 aggregate = self.cs.aggregates.get_details("1")
52 self.assert_called('GET', '/os-aggregates/1')
53 self.assertIsInstance(aggregate, aggregates.Aggregate)
54
55 aggregate2 = self.cs.aggregates.get_details(aggregate)
56 self.assert_called('GET', '/os-aggregates/1')
57 self.assertIsInstance(aggregate2, aggregates.Aggregate)
58
59 def test_update(self):
60 aggregate = self.cs.aggregates.get("1")
61 values = {"name": "foo"}
62 body = {"aggregate": values}
63
64 result1 = aggregate.update(values)
65 self.assert_called('PUT', '/os-aggregates/1', body)
66 self.assertIsInstance(result1, aggregates.Aggregate)
67
68 result2 = self.cs.aggregates.update(2, values)
69 self.assert_called('PUT', '/os-aggregates/2', body)
70 self.assertIsInstance(result2, aggregates.Aggregate)
71
72 def test_update_with_availability_zone(self):
73 aggregate = self.cs.aggregates.get("1")
74 values = {"name": "foo", "availability_zone": "new_zone"}
75 body = {"aggregate": values}
76
77 result3 = self.cs.aggregates.update(aggregate, values)
78 self.assert_called('PUT', '/os-aggregates/1', body)
79 self.assertIsInstance(result3, aggregates.Aggregate)
80
81 def test_add_host(self):
82 aggregate = self.cs.aggregates.get("1")
83 host = "host1"
84 body = {"add_host": {"host": "host1"}}
85
86 result1 = aggregate.add_host(host)
87 self.assert_called('POST', '/os-aggregates/1/action', body)
88 self.assertIsInstance(result1, aggregates.Aggregate)
89
90 result2 = self.cs.aggregates.add_host("2", host)
91 self.assert_called('POST', '/os-aggregates/2/action', body)
92 self.assertIsInstance(result2, aggregates.Aggregate)
93
94 result3 = self.cs.aggregates.add_host(aggregate, host)
95 self.assert_called('POST', '/os-aggregates/1/action', body)
96 self.assertIsInstance(result3, aggregates.Aggregate)
97
98 def test_remove_host(self):
99 aggregate = self.cs.aggregates.get("1")
100 host = "host1"
101 body = {"remove_host": {"host": "host1"}}
102
103 result1 = aggregate.remove_host(host)
104 self.assert_called('POST', '/os-aggregates/1/action', body)
105 self.assertIsInstance(result1, aggregates.Aggregate)
106
107 result2 = self.cs.aggregates.remove_host("2", host)
108 self.assert_called('POST', '/os-aggregates/2/action', body)
109 self.assertIsInstance(result2, aggregates.Aggregate)
110
111 result3 = self.cs.aggregates.remove_host(aggregate, host)
112 self.assert_called('POST', '/os-aggregates/1/action', body)
113 self.assertIsInstance(result3, aggregates.Aggregate)
114
115 def test_set_metadata(self):
116 aggregate = self.cs.aggregates.get("1")
117 metadata = {"foo": "bar"}
118 body = {"set_metadata": {"metadata": metadata}}
119
120 result1 = aggregate.set_metadata(metadata)
121 self.assert_called('POST', '/os-aggregates/1/action', body)
122 self.assertIsInstance(result1, aggregates.Aggregate)
123
124 result2 = self.cs.aggregates.set_metadata(2, metadata)
125 self.assert_called('POST', '/os-aggregates/2/action', body)
126 self.assertIsInstance(result2, aggregates.Aggregate)
127
128 result3 = self.cs.aggregates.set_metadata(aggregate, metadata)
129 self.assert_called('POST', '/os-aggregates/1/action', body)
130 self.assertIsInstance(result3, aggregates.Aggregate)
131
132 def test_delete_aggregate(self):
133 aggregate = self.cs.aggregates.list()[0]
134 aggregate.delete()
135 self.assert_called('DELETE', '/os-aggregates/1')
136
137 self.cs.aggregates.delete('1')
138 self.assert_called('DELETE', '/os-aggregates/1')
139
140 self.cs.aggregates.delete(aggregate)
141 self.assert_called('DELETE', '/os-aggregates/1')