root / test / ganeti.rapi.rlib2_unittest.py @ a52978c7
History | View | Annotate | Download (54.5 kB)
1 | 6395cebb | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | 6395cebb | Michael Hanselmann | #
|
3 | 6395cebb | Michael Hanselmann | |
4 | 6395cebb | Michael Hanselmann | # Copyright (C) 2010 Google Inc.
|
5 | 6395cebb | Michael Hanselmann | #
|
6 | 6395cebb | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | 6395cebb | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | 6395cebb | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | 6395cebb | Michael Hanselmann | # (at your option) any later version.
|
10 | 6395cebb | Michael Hanselmann | #
|
11 | 6395cebb | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | 6395cebb | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 6395cebb | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 6395cebb | Michael Hanselmann | # General Public License for more details.
|
15 | 6395cebb | Michael Hanselmann | #
|
16 | 6395cebb | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | 6395cebb | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | 6395cebb | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 6395cebb | Michael Hanselmann | # 02110-1301, USA.
|
20 | 6395cebb | Michael Hanselmann | |
21 | 6395cebb | Michael Hanselmann | |
22 | 6395cebb | Michael Hanselmann | """Script for unittesting the RAPI rlib2 module
|
23 | 6395cebb | Michael Hanselmann |
|
24 | 6395cebb | Michael Hanselmann | """
|
25 | 6395cebb | Michael Hanselmann | |
26 | 6395cebb | Michael Hanselmann | |
27 | 6395cebb | Michael Hanselmann | import unittest |
28 | 50c7d82e | Michael Hanselmann | import itertools |
29 | 50c7d82e | Michael Hanselmann | import random |
30 | 6395cebb | Michael Hanselmann | |
31 | 6395cebb | Michael Hanselmann | from ganeti import constants |
32 | 6395cebb | Michael Hanselmann | from ganeti import opcodes |
33 | 6395cebb | Michael Hanselmann | from ganeti import compat |
34 | 6395cebb | Michael Hanselmann | from ganeti import http |
35 | b82d4c5e | Michael Hanselmann | from ganeti import query |
36 | e02836d6 | Michael Hanselmann | from ganeti import luxi |
37 | e02836d6 | Michael Hanselmann | from ganeti import errors |
38 | 6395cebb | Michael Hanselmann | |
39 | 6395cebb | Michael Hanselmann | from ganeti.rapi import rlib2 |
40 | 6395cebb | Michael Hanselmann | |
41 | 6395cebb | Michael Hanselmann | import testutils |
42 | 6395cebb | Michael Hanselmann | |
43 | 6395cebb | Michael Hanselmann | |
44 | e02836d6 | Michael Hanselmann | class _FakeRequestPrivateData: |
45 | e02836d6 | Michael Hanselmann | def __init__(self, body_data): |
46 | e02836d6 | Michael Hanselmann | self.body_data = body_data
|
47 | e02836d6 | Michael Hanselmann | |
48 | e02836d6 | Michael Hanselmann | |
49 | e02836d6 | Michael Hanselmann | class _FakeRequest: |
50 | e02836d6 | Michael Hanselmann | def __init__(self, body_data): |
51 | e02836d6 | Michael Hanselmann | self.private = _FakeRequestPrivateData(body_data)
|
52 | e02836d6 | Michael Hanselmann | |
53 | e02836d6 | Michael Hanselmann | |
54 | e02836d6 | Michael Hanselmann | def _CreateHandler(cls, items, queryargs, body_data, client_cls): |
55 | e02836d6 | Michael Hanselmann | return cls(items, queryargs, _FakeRequest(body_data),
|
56 | e02836d6 | Michael Hanselmann | _client_cls=client_cls) |
57 | e02836d6 | Michael Hanselmann | |
58 | e02836d6 | Michael Hanselmann | |
59 | 50c7d82e | Michael Hanselmann | class _FakeClient: |
60 | 50c7d82e | Michael Hanselmann | def __init__(self): |
61 | 50c7d82e | Michael Hanselmann | self._jobs = []
|
62 | 50c7d82e | Michael Hanselmann | |
63 | 50c7d82e | Michael Hanselmann | def GetNextSubmittedJob(self): |
64 | 50c7d82e | Michael Hanselmann | return self._jobs.pop(0) |
65 | 50c7d82e | Michael Hanselmann | |
66 | 50c7d82e | Michael Hanselmann | def SubmitJob(self, ops): |
67 | 50c7d82e | Michael Hanselmann | job_id = str(1 + int(random.random() * 1000000)) |
68 | 50c7d82e | Michael Hanselmann | self._jobs.append((job_id, ops))
|
69 | 50c7d82e | Michael Hanselmann | return job_id
|
70 | 50c7d82e | Michael Hanselmann | |
71 | 50c7d82e | Michael Hanselmann | |
72 | 50c7d82e | Michael Hanselmann | class _FakeClientFactory: |
73 | 50c7d82e | Michael Hanselmann | def __init__(self, cls): |
74 | 50c7d82e | Michael Hanselmann | self._client_cls = cls
|
75 | 50c7d82e | Michael Hanselmann | self._clients = []
|
76 | 50c7d82e | Michael Hanselmann | |
77 | 50c7d82e | Michael Hanselmann | def GetNextClient(self): |
78 | 50c7d82e | Michael Hanselmann | return self._clients.pop(0) |
79 | 50c7d82e | Michael Hanselmann | |
80 | 50c7d82e | Michael Hanselmann | def __call__(self): |
81 | 50c7d82e | Michael Hanselmann | cl = self._client_cls()
|
82 | 50c7d82e | Michael Hanselmann | self._clients.append(cl)
|
83 | 50c7d82e | Michael Hanselmann | return cl
|
84 | 50c7d82e | Michael Hanselmann | |
85 | 50c7d82e | Michael Hanselmann | |
86 | b82d4c5e | Michael Hanselmann | class TestConstants(unittest.TestCase): |
87 | b82d4c5e | Michael Hanselmann | def testConsole(self): |
88 | b82d4c5e | Michael Hanselmann | # Exporting the console field without authentication might expose
|
89 | b82d4c5e | Michael Hanselmann | # information
|
90 | b82d4c5e | Michael Hanselmann | assert "console" in query.INSTANCE_FIELDS |
91 | b82d4c5e | Michael Hanselmann | self.assertTrue("console" not in rlib2.I_FIELDS) |
92 | b82d4c5e | Michael Hanselmann | |
93 | f4e86448 | Michael Hanselmann | def testFields(self): |
94 | f4e86448 | Michael Hanselmann | checks = { |
95 | f4e86448 | Michael Hanselmann | constants.QR_INSTANCE: rlib2.I_FIELDS, |
96 | f4e86448 | Michael Hanselmann | constants.QR_NODE: rlib2.N_FIELDS, |
97 | f4e86448 | Michael Hanselmann | constants.QR_GROUP: rlib2.G_FIELDS, |
98 | f4e86448 | Michael Hanselmann | } |
99 | f4e86448 | Michael Hanselmann | |
100 | f4e86448 | Michael Hanselmann | for (qr, fields) in checks.items(): |
101 | f4e86448 | Michael Hanselmann | self.assertFalse(set(fields) - set(query.ALL_FIELDS[qr].keys())) |
102 | f4e86448 | Michael Hanselmann | |
103 | b82d4c5e | Michael Hanselmann | |
104 | e02836d6 | Michael Hanselmann | class TestClientConnectError(unittest.TestCase): |
105 | e02836d6 | Michael Hanselmann | @staticmethod
|
106 | e02836d6 | Michael Hanselmann | def _FailingClient(): |
107 | e02836d6 | Michael Hanselmann | raise luxi.NoMasterError("test") |
108 | e02836d6 | Michael Hanselmann | |
109 | e02836d6 | Michael Hanselmann | def test(self): |
110 | e02836d6 | Michael Hanselmann | resources = [ |
111 | e02836d6 | Michael Hanselmann | rlib2.R_2_groups, |
112 | e02836d6 | Michael Hanselmann | rlib2.R_2_instances, |
113 | e02836d6 | Michael Hanselmann | rlib2.R_2_nodes, |
114 | e02836d6 | Michael Hanselmann | ] |
115 | e02836d6 | Michael Hanselmann | for cls in resources: |
116 | e02836d6 | Michael Hanselmann | handler = _CreateHandler(cls, ["name"], [], None, self._FailingClient) |
117 | e02836d6 | Michael Hanselmann | self.assertRaises(http.HttpBadGateway, handler.GET)
|
118 | e02836d6 | Michael Hanselmann | |
119 | e02836d6 | Michael Hanselmann | |
120 | e02836d6 | Michael Hanselmann | class TestJobSubmitError(unittest.TestCase): |
121 | e02836d6 | Michael Hanselmann | class _SubmitErrorClient: |
122 | e02836d6 | Michael Hanselmann | @staticmethod
|
123 | e02836d6 | Michael Hanselmann | def SubmitJob(ops): |
124 | e02836d6 | Michael Hanselmann | raise errors.JobQueueFull("test") |
125 | e02836d6 | Michael Hanselmann | |
126 | e02836d6 | Michael Hanselmann | def test(self): |
127 | e02836d6 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_redist_config, [], [], None,
|
128 | e02836d6 | Michael Hanselmann | self._SubmitErrorClient)
|
129 | e02836d6 | Michael Hanselmann | self.assertRaises(http.HttpServiceUnavailable, handler.PUT)
|
130 | e02836d6 | Michael Hanselmann | |
131 | e02836d6 | Michael Hanselmann | |
132 | 50c7d82e | Michael Hanselmann | class TestClusterModify(unittest.TestCase): |
133 | 50c7d82e | Michael Hanselmann | def test(self): |
134 | 50c7d82e | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
135 | 50c7d82e | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_cluster_modify, [], [], { |
136 | 50c7d82e | Michael Hanselmann | "vg_name": "testvg", |
137 | 50c7d82e | Michael Hanselmann | "candidate_pool_size": 100, |
138 | 50c7d82e | Michael Hanselmann | }, clfactory) |
139 | 50c7d82e | Michael Hanselmann | job_id = handler.PUT() |
140 | 50c7d82e | Michael Hanselmann | |
141 | 50c7d82e | Michael Hanselmann | cl = clfactory.GetNextClient() |
142 | 50c7d82e | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
143 | 50c7d82e | Michael Hanselmann | |
144 | 50c7d82e | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
145 | 50c7d82e | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
146 | 50c7d82e | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpClusterSetParams)) |
147 | 50c7d82e | Michael Hanselmann | self.assertEqual(op.vg_name, "testvg") |
148 | 50c7d82e | Michael Hanselmann | self.assertEqual(op.candidate_pool_size, 100) |
149 | 50c7d82e | Michael Hanselmann | |
150 | 50c7d82e | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
151 | 50c7d82e | Michael Hanselmann | |
152 | 50c7d82e | Michael Hanselmann | def testInvalidValue(self): |
153 | 50c7d82e | Michael Hanselmann | for attr in ["vg_name", "candidate_pool_size", "beparams", "_-Unknown#"]: |
154 | 50c7d82e | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
155 | 50c7d82e | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_cluster_modify, [], [], { |
156 | 50c7d82e | Michael Hanselmann | attr: True,
|
157 | 50c7d82e | Michael Hanselmann | }, clfactory) |
158 | 50c7d82e | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
159 | 50c7d82e | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
160 | 50c7d82e | Michael Hanselmann | |
161 | 50c7d82e | Michael Hanselmann | |
162 | 8fd625fc | Michael Hanselmann | class TestRedistConfig(unittest.TestCase): |
163 | 8fd625fc | Michael Hanselmann | def test(self): |
164 | 8fd625fc | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
165 | 8fd625fc | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_redist_config, [], [], None, clfactory)
|
166 | 8fd625fc | Michael Hanselmann | job_id = handler.PUT() |
167 | 8fd625fc | Michael Hanselmann | |
168 | 8fd625fc | Michael Hanselmann | cl = clfactory.GetNextClient() |
169 | 8fd625fc | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
170 | 8fd625fc | Michael Hanselmann | |
171 | 8fd625fc | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
172 | 8fd625fc | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
173 | 8fd625fc | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpClusterRedistConf)) |
174 | 8fd625fc | Michael Hanselmann | |
175 | 8fd625fc | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
176 | 8fd625fc | Michael Hanselmann | |
177 | 8fd625fc | Michael Hanselmann | |
178 | 55168cc7 | Michael Hanselmann | class TestNodeMigrate(unittest.TestCase): |
179 | 55168cc7 | Michael Hanselmann | def test(self): |
180 | 55168cc7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
181 | 55168cc7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_migrate, ["node1"], {}, {
|
182 | 55168cc7 | Michael Hanselmann | "iallocator": "fooalloc", |
183 | 55168cc7 | Michael Hanselmann | }, clfactory) |
184 | 55168cc7 | Michael Hanselmann | job_id = handler.POST() |
185 | 55168cc7 | Michael Hanselmann | |
186 | 55168cc7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
187 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
188 | 55168cc7 | Michael Hanselmann | |
189 | 55168cc7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
190 | 55168cc7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
191 | 55168cc7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeMigrate)) |
192 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.node_name, "node1") |
193 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.iallocator, "fooalloc") |
194 | 55168cc7 | Michael Hanselmann | |
195 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
196 | 55168cc7 | Michael Hanselmann | |
197 | 55168cc7 | Michael Hanselmann | def testQueryArgsConflict(self): |
198 | 55168cc7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
199 | 55168cc7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_migrate, ["node2"], {
|
200 | 55168cc7 | Michael Hanselmann | "live": True, |
201 | 55168cc7 | Michael Hanselmann | "mode": constants.HT_MIGRATION_NONLIVE,
|
202 | 55168cc7 | Michael Hanselmann | }, None, clfactory)
|
203 | 55168cc7 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
204 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
205 | 55168cc7 | Michael Hanselmann | |
206 | 55168cc7 | Michael Hanselmann | def testQueryArgsMode(self): |
207 | 55168cc7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
208 | 55168cc7 | Michael Hanselmann | queryargs = { |
209 | 55168cc7 | Michael Hanselmann | "mode": [constants.HT_MIGRATION_LIVE],
|
210 | 55168cc7 | Michael Hanselmann | } |
211 | 55168cc7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_migrate, ["node17292"],
|
212 | 55168cc7 | Michael Hanselmann | queryargs, None, clfactory)
|
213 | 55168cc7 | Michael Hanselmann | job_id = handler.POST() |
214 | 55168cc7 | Michael Hanselmann | |
215 | 55168cc7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
216 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
217 | 55168cc7 | Michael Hanselmann | |
218 | 55168cc7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
219 | 55168cc7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
220 | 55168cc7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeMigrate)) |
221 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.node_name, "node17292") |
222 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.mode, constants.HT_MIGRATION_LIVE)
|
223 | 55168cc7 | Michael Hanselmann | |
224 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
225 | 55168cc7 | Michael Hanselmann | |
226 | 55168cc7 | Michael Hanselmann | def testQueryArgsLive(self): |
227 | 55168cc7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
228 | 55168cc7 | Michael Hanselmann | |
229 | 55168cc7 | Michael Hanselmann | for live in [False, True]: |
230 | 55168cc7 | Michael Hanselmann | queryargs = { |
231 | 55168cc7 | Michael Hanselmann | "live": [str(int(live))], |
232 | 55168cc7 | Michael Hanselmann | } |
233 | 55168cc7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_migrate, ["node6940"],
|
234 | 55168cc7 | Michael Hanselmann | queryargs, None, clfactory)
|
235 | 55168cc7 | Michael Hanselmann | job_id = handler.POST() |
236 | 55168cc7 | Michael Hanselmann | |
237 | 55168cc7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
238 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
239 | 55168cc7 | Michael Hanselmann | |
240 | 55168cc7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
241 | 55168cc7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
242 | 55168cc7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeMigrate)) |
243 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.node_name, "node6940") |
244 | 55168cc7 | Michael Hanselmann | if live:
|
245 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.mode, constants.HT_MIGRATION_LIVE)
|
246 | 55168cc7 | Michael Hanselmann | else:
|
247 | 55168cc7 | Michael Hanselmann | self.assertEqual(op.mode, constants.HT_MIGRATION_NONLIVE)
|
248 | 55168cc7 | Michael Hanselmann | |
249 | 55168cc7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
250 | 55168cc7 | Michael Hanselmann | |
251 | 55168cc7 | Michael Hanselmann | |
252 | 7fa91722 | Michael Hanselmann | class TestNodeEvacuate(unittest.TestCase): |
253 | 7fa91722 | Michael Hanselmann | def test(self): |
254 | 7fa91722 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
255 | 7fa91722 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_evacuate, ["node92"], {
|
256 | 7fa91722 | Michael Hanselmann | "dry-run": ["1"], |
257 | 7fa91722 | Michael Hanselmann | }, { |
258 | 7fa91722 | Michael Hanselmann | "mode": constants.IALLOCATOR_NEVAC_SEC,
|
259 | 7fa91722 | Michael Hanselmann | }, clfactory) |
260 | 7fa91722 | Michael Hanselmann | job_id = handler.POST() |
261 | 7fa91722 | Michael Hanselmann | |
262 | 7fa91722 | Michael Hanselmann | cl = clfactory.GetNextClient() |
263 | 7fa91722 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
264 | 7fa91722 | Michael Hanselmann | |
265 | 7fa91722 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
266 | 7fa91722 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
267 | 7fa91722 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeEvacuate)) |
268 | 7fa91722 | Michael Hanselmann | self.assertEqual(op.node_name, "node92") |
269 | 7fa91722 | Michael Hanselmann | self.assertEqual(op.mode, constants.IALLOCATOR_NEVAC_SEC)
|
270 | 7fa91722 | Michael Hanselmann | self.assertTrue(op.dry_run)
|
271 | 7fa91722 | Michael Hanselmann | |
272 | 7fa91722 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
273 | 7fa91722 | Michael Hanselmann | |
274 | 7fa91722 | Michael Hanselmann | |
275 | 87fd3ec7 | Michael Hanselmann | class TestGroupAssignNodes(unittest.TestCase): |
276 | 87fd3ec7 | Michael Hanselmann | def test(self): |
277 | 87fd3ec7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
278 | 87fd3ec7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_assign_nodes, ["grp-a"], {
|
279 | 87fd3ec7 | Michael Hanselmann | "dry-run": ["1"], |
280 | 87fd3ec7 | Michael Hanselmann | "force": ["1"], |
281 | 87fd3ec7 | Michael Hanselmann | }, { |
282 | 87fd3ec7 | Michael Hanselmann | "nodes": ["n2", "n3"], |
283 | 87fd3ec7 | Michael Hanselmann | }, clfactory) |
284 | 87fd3ec7 | Michael Hanselmann | job_id = handler.PUT() |
285 | 87fd3ec7 | Michael Hanselmann | |
286 | 87fd3ec7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
287 | 87fd3ec7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
288 | 87fd3ec7 | Michael Hanselmann | |
289 | 87fd3ec7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
290 | 87fd3ec7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
291 | 87fd3ec7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupAssignNodes)) |
292 | 87fd3ec7 | Michael Hanselmann | self.assertEqual(op.group_name, "grp-a") |
293 | 87fd3ec7 | Michael Hanselmann | self.assertEqual(op.nodes, ["n2", "n3"]) |
294 | 87fd3ec7 | Michael Hanselmann | self.assertTrue(op.dry_run)
|
295 | 87fd3ec7 | Michael Hanselmann | self.assertTrue(op.force)
|
296 | 87fd3ec7 | Michael Hanselmann | |
297 | 87fd3ec7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
298 | 87fd3ec7 | Michael Hanselmann | |
299 | 87fd3ec7 | Michael Hanselmann | |
300 | a6fa7892 | Michael Hanselmann | class TestInstanceDelete(unittest.TestCase): |
301 | a6fa7892 | Michael Hanselmann | def test(self): |
302 | a6fa7892 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
303 | a6fa7892 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name, ["inst30965"], {
|
304 | a6fa7892 | Michael Hanselmann | "dry-run": ["1"], |
305 | a6fa7892 | Michael Hanselmann | }, {}, clfactory) |
306 | a6fa7892 | Michael Hanselmann | job_id = handler.DELETE() |
307 | a6fa7892 | Michael Hanselmann | |
308 | a6fa7892 | Michael Hanselmann | cl = clfactory.GetNextClient() |
309 | a6fa7892 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
310 | a6fa7892 | Michael Hanselmann | |
311 | a6fa7892 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
312 | a6fa7892 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
313 | a6fa7892 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceRemove)) |
314 | a6fa7892 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst30965") |
315 | a6fa7892 | Michael Hanselmann | self.assertTrue(op.dry_run)
|
316 | a6fa7892 | Michael Hanselmann | self.assertFalse(op.ignore_failures)
|
317 | a6fa7892 | Michael Hanselmann | |
318 | a6fa7892 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
319 | a6fa7892 | Michael Hanselmann | |
320 | a6fa7892 | Michael Hanselmann | |
321 | 7b3df961 | Michael Hanselmann | class TestInstanceInfo(unittest.TestCase): |
322 | 7b3df961 | Michael Hanselmann | def test(self): |
323 | 7b3df961 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
324 | 7b3df961 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_info, ["inst31217"], {
|
325 | 7b3df961 | Michael Hanselmann | "static": ["1"], |
326 | 7b3df961 | Michael Hanselmann | }, {}, clfactory) |
327 | 7b3df961 | Michael Hanselmann | job_id = handler.GET() |
328 | 7b3df961 | Michael Hanselmann | |
329 | 7b3df961 | Michael Hanselmann | cl = clfactory.GetNextClient() |
330 | 7b3df961 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
331 | 7b3df961 | Michael Hanselmann | |
332 | 7b3df961 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
333 | 7b3df961 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
334 | 7b3df961 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceQueryData)) |
335 | 7b3df961 | Michael Hanselmann | self.assertEqual(op.instances, ["inst31217"]) |
336 | 7b3df961 | Michael Hanselmann | self.assertTrue(op.static)
|
337 | 7b3df961 | Michael Hanselmann | |
338 | 7b3df961 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
339 | 7b3df961 | Michael Hanselmann | |
340 | 7b3df961 | Michael Hanselmann | |
341 | ac4888c1 | Michael Hanselmann | class TestInstanceReboot(unittest.TestCase): |
342 | ac4888c1 | Michael Hanselmann | def test(self): |
343 | ac4888c1 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
344 | ac4888c1 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], {
|
345 | ac4888c1 | Michael Hanselmann | "dry-run": ["1"], |
346 | ac4888c1 | Michael Hanselmann | "ignore_secondaries": ["1"], |
347 | ac4888c1 | Michael Hanselmann | }, {}, clfactory) |
348 | ac4888c1 | Michael Hanselmann | job_id = handler.POST() |
349 | ac4888c1 | Michael Hanselmann | |
350 | ac4888c1 | Michael Hanselmann | cl = clfactory.GetNextClient() |
351 | ac4888c1 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
352 | ac4888c1 | Michael Hanselmann | |
353 | ac4888c1 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
354 | ac4888c1 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
355 | ac4888c1 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceReboot)) |
356 | ac4888c1 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst847") |
357 | ac4888c1 | Michael Hanselmann | self.assertEqual(op.reboot_type, constants.INSTANCE_REBOOT_HARD)
|
358 | ac4888c1 | Michael Hanselmann | self.assertTrue(op.ignore_secondaries)
|
359 | ac4888c1 | Michael Hanselmann | self.assertTrue(op.dry_run)
|
360 | ac4888c1 | Michael Hanselmann | |
361 | ac4888c1 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
362 | ac4888c1 | Michael Hanselmann | |
363 | ac4888c1 | Michael Hanselmann | |
364 | 4717e6eb | Michael Hanselmann | class TestInstanceStartup(unittest.TestCase): |
365 | 4717e6eb | Michael Hanselmann | def test(self): |
366 | 4717e6eb | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
367 | 4717e6eb | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_startup, ["inst31083"], {
|
368 | 4717e6eb | Michael Hanselmann | "force": ["1"], |
369 | 4717e6eb | Michael Hanselmann | "no_remember": ["1"], |
370 | 4717e6eb | Michael Hanselmann | }, {}, clfactory) |
371 | 4717e6eb | Michael Hanselmann | job_id = handler.PUT() |
372 | 4717e6eb | Michael Hanselmann | |
373 | 4717e6eb | Michael Hanselmann | cl = clfactory.GetNextClient() |
374 | 4717e6eb | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
375 | 4717e6eb | Michael Hanselmann | |
376 | 4717e6eb | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
377 | 4717e6eb | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
378 | 4717e6eb | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceStartup)) |
379 | 4717e6eb | Michael Hanselmann | self.assertEqual(op.instance_name, "inst31083") |
380 | 4717e6eb | Michael Hanselmann | self.assertTrue(op.no_remember)
|
381 | 4717e6eb | Michael Hanselmann | self.assertTrue(op.force)
|
382 | 4717e6eb | Michael Hanselmann | self.assertFalse(op.dry_run)
|
383 | 4717e6eb | Michael Hanselmann | |
384 | 4717e6eb | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
385 | 4717e6eb | Michael Hanselmann | |
386 | 4717e6eb | Michael Hanselmann | |
387 | 3175ade6 | Michael Hanselmann | class TestInstanceShutdown(unittest.TestCase): |
388 | 3175ade6 | Michael Hanselmann | def test(self): |
389 | 3175ade6 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
390 | 3175ade6 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_shutdown, ["inst26791"], {
|
391 | 3175ade6 | Michael Hanselmann | "no_remember": ["0"], |
392 | 3175ade6 | Michael Hanselmann | }, {}, clfactory) |
393 | 3175ade6 | Michael Hanselmann | job_id = handler.PUT() |
394 | 3175ade6 | Michael Hanselmann | |
395 | 3175ade6 | Michael Hanselmann | cl = clfactory.GetNextClient() |
396 | 3175ade6 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
397 | 3175ade6 | Michael Hanselmann | |
398 | 3175ade6 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
399 | 3175ade6 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
400 | 3175ade6 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceShutdown)) |
401 | 3175ade6 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst26791") |
402 | 3175ade6 | Michael Hanselmann | self.assertFalse(op.no_remember)
|
403 | 3175ade6 | Michael Hanselmann | self.assertFalse(op.dry_run)
|
404 | 3175ade6 | Michael Hanselmann | |
405 | 3175ade6 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
406 | 3175ade6 | Michael Hanselmann | |
407 | 3175ade6 | Michael Hanselmann | |
408 | 1824a7a1 | Michael Hanselmann | class TestInstanceActivateDisks(unittest.TestCase): |
409 | 1824a7a1 | Michael Hanselmann | def test(self): |
410 | 1824a7a1 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
411 | 1824a7a1 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_activate_disks, ["xyz"], {
|
412 | 1824a7a1 | Michael Hanselmann | "ignore_size": ["1"], |
413 | 1824a7a1 | Michael Hanselmann | }, {}, clfactory) |
414 | 1824a7a1 | Michael Hanselmann | job_id = handler.PUT() |
415 | 1824a7a1 | Michael Hanselmann | |
416 | 1824a7a1 | Michael Hanselmann | cl = clfactory.GetNextClient() |
417 | 1824a7a1 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
418 | 1824a7a1 | Michael Hanselmann | |
419 | 1824a7a1 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
420 | 1824a7a1 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
421 | 1824a7a1 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceActivateDisks)) |
422 | 1824a7a1 | Michael Hanselmann | self.assertEqual(op.instance_name, "xyz") |
423 | 1824a7a1 | Michael Hanselmann | self.assertTrue(op.ignore_size)
|
424 | 1824a7a1 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
425 | 1824a7a1 | Michael Hanselmann | |
426 | 1824a7a1 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
427 | 1824a7a1 | Michael Hanselmann | |
428 | 1824a7a1 | Michael Hanselmann | |
429 | 973ec124 | Michael Hanselmann | class TestInstanceDeactivateDisks(unittest.TestCase): |
430 | 973ec124 | Michael Hanselmann | def test(self): |
431 | 973ec124 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
432 | 973ec124 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_deactivate_disks, |
433 | 973ec124 | Michael Hanselmann | ["inst22357"], {}, {}, clfactory)
|
434 | 973ec124 | Michael Hanselmann | job_id = handler.PUT() |
435 | 973ec124 | Michael Hanselmann | |
436 | 973ec124 | Michael Hanselmann | cl = clfactory.GetNextClient() |
437 | 973ec124 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
438 | 973ec124 | Michael Hanselmann | |
439 | 973ec124 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
440 | 973ec124 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
441 | 973ec124 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceDeactivateDisks)) |
442 | 973ec124 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst22357") |
443 | 973ec124 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
444 | 973ec124 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
445 | a52978c7 | Michael Hanselmann | |
446 | a52978c7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
447 | a52978c7 | Michael Hanselmann | |
448 | a52978c7 | Michael Hanselmann | |
449 | a52978c7 | Michael Hanselmann | class TestInstanceRecreateDisks(unittest.TestCase): |
450 | a52978c7 | Michael Hanselmann | def test(self): |
451 | a52978c7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
452 | a52978c7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_recreate_disks, |
453 | a52978c7 | Michael Hanselmann | ["inst22357"], {}, {}, clfactory)
|
454 | a52978c7 | Michael Hanselmann | job_id = handler.POST() |
455 | a52978c7 | Michael Hanselmann | |
456 | a52978c7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
457 | a52978c7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
458 | a52978c7 | Michael Hanselmann | |
459 | a52978c7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
460 | a52978c7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
461 | a52978c7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceRecreateDisks)) |
462 | a52978c7 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst22357") |
463 | a52978c7 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
464 | a52978c7 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
465 | 973ec124 | Michael Hanselmann | |
466 | 973ec124 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
467 | 973ec124 | Michael Hanselmann | |
468 | 973ec124 | Michael Hanselmann | |
469 | b5f2ab80 | Michael Hanselmann | class TestInstanceFailover(unittest.TestCase): |
470 | b5f2ab80 | Michael Hanselmann | def test(self): |
471 | b5f2ab80 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
472 | b5f2ab80 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_failover, |
473 | b5f2ab80 | Michael Hanselmann | ["inst12794"], {}, {}, clfactory)
|
474 | b5f2ab80 | Michael Hanselmann | job_id = handler.PUT() |
475 | b5f2ab80 | Michael Hanselmann | |
476 | b5f2ab80 | Michael Hanselmann | cl = clfactory.GetNextClient() |
477 | b5f2ab80 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
478 | b5f2ab80 | Michael Hanselmann | |
479 | b5f2ab80 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
480 | b5f2ab80 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
481 | b5f2ab80 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceFailover)) |
482 | b5f2ab80 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst12794") |
483 | b5f2ab80 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
484 | b5f2ab80 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
485 | b5f2ab80 | Michael Hanselmann | |
486 | b5f2ab80 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
487 | b5f2ab80 | Michael Hanselmann | |
488 | b5f2ab80 | Michael Hanselmann | |
489 | 335965b9 | Michael Hanselmann | class TestInstanceDiskGrow(unittest.TestCase): |
490 | 335965b9 | Michael Hanselmann | def test(self): |
491 | 335965b9 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
492 | 335965b9 | Michael Hanselmann | data = { |
493 | 335965b9 | Michael Hanselmann | "amount": 1024, |
494 | 335965b9 | Michael Hanselmann | } |
495 | 335965b9 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_disk_grow, |
496 | 335965b9 | Michael Hanselmann | ["inst10742", "3"], {}, data, clfactory) |
497 | 335965b9 | Michael Hanselmann | job_id = handler.POST() |
498 | 335965b9 | Michael Hanselmann | |
499 | 335965b9 | Michael Hanselmann | cl = clfactory.GetNextClient() |
500 | 335965b9 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
501 | 335965b9 | Michael Hanselmann | |
502 | 335965b9 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
503 | 335965b9 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
504 | 335965b9 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceGrowDisk)) |
505 | 335965b9 | Michael Hanselmann | self.assertEqual(op.instance_name, "inst10742") |
506 | 335965b9 | Michael Hanselmann | self.assertEqual(op.disk, 3) |
507 | 335965b9 | Michael Hanselmann | self.assertEqual(op.amount, 1024) |
508 | 335965b9 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
509 | 335965b9 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
510 | 335965b9 | Michael Hanselmann | |
511 | 335965b9 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
512 | 335965b9 | Michael Hanselmann | |
513 | 335965b9 | Michael Hanselmann | |
514 | 1c63311d | Michael Hanselmann | class TestBackupPrepare(unittest.TestCase): |
515 | 1c63311d | Michael Hanselmann | def test(self): |
516 | 1c63311d | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
517 | 1c63311d | Michael Hanselmann | queryargs = { |
518 | 1c63311d | Michael Hanselmann | "mode": constants.EXPORT_MODE_REMOTE,
|
519 | 1c63311d | Michael Hanselmann | } |
520 | 1c63311d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_prepare_export, |
521 | 1c63311d | Michael Hanselmann | ["inst17925"], queryargs, {}, clfactory)
|
522 | 1c63311d | Michael Hanselmann | job_id = handler.PUT() |
523 | 1c63311d | Michael Hanselmann | |
524 | 1c63311d | Michael Hanselmann | cl = clfactory.GetNextClient() |
525 | 1c63311d | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
526 | 1c63311d | Michael Hanselmann | |
527 | 1c63311d | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
528 | 1c63311d | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
529 | 1c63311d | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpBackupPrepare)) |
530 | 1c63311d | Michael Hanselmann | self.assertEqual(op.instance_name, "inst17925") |
531 | 1c63311d | Michael Hanselmann | self.assertEqual(op.mode, constants.EXPORT_MODE_REMOTE)
|
532 | 1c63311d | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
533 | 1c63311d | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
534 | 1c63311d | Michael Hanselmann | |
535 | 1c63311d | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
536 | 1c63311d | Michael Hanselmann | |
537 | 1c63311d | Michael Hanselmann | |
538 | 86f1f5d4 | Michael Hanselmann | class TestGroupRemove(unittest.TestCase): |
539 | 86f1f5d4 | Michael Hanselmann | def test(self): |
540 | 86f1f5d4 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
541 | 86f1f5d4 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name, |
542 | 86f1f5d4 | Michael Hanselmann | ["grp28575"], {}, {}, clfactory)
|
543 | 86f1f5d4 | Michael Hanselmann | job_id = handler.DELETE() |
544 | 86f1f5d4 | Michael Hanselmann | |
545 | 86f1f5d4 | Michael Hanselmann | cl = clfactory.GetNextClient() |
546 | 86f1f5d4 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
547 | 86f1f5d4 | Michael Hanselmann | |
548 | 86f1f5d4 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
549 | 86f1f5d4 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
550 | 86f1f5d4 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupRemove)) |
551 | 86f1f5d4 | Michael Hanselmann | self.assertEqual(op.group_name, "grp28575") |
552 | 86f1f5d4 | Michael Hanselmann | self.assertFalse(op.dry_run)
|
553 | 86f1f5d4 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
554 | 86f1f5d4 | Michael Hanselmann | |
555 | 86f1f5d4 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
556 | 86f1f5d4 | Michael Hanselmann | |
557 | 86f1f5d4 | Michael Hanselmann | |
558 | eb08e09d | Michael Hanselmann | class TestStorageQuery(unittest.TestCase): |
559 | eb08e09d | Michael Hanselmann | def test(self): |
560 | eb08e09d | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
561 | eb08e09d | Michael Hanselmann | queryargs = { |
562 | eb08e09d | Michael Hanselmann | "storage_type": constants.ST_LVM_PV,
|
563 | eb08e09d | Michael Hanselmann | "output_fields": "name,other", |
564 | eb08e09d | Michael Hanselmann | } |
565 | eb08e09d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage, |
566 | eb08e09d | Michael Hanselmann | ["node21075"], queryargs, {}, clfactory)
|
567 | eb08e09d | Michael Hanselmann | job_id = handler.GET() |
568 | eb08e09d | Michael Hanselmann | |
569 | eb08e09d | Michael Hanselmann | cl = clfactory.GetNextClient() |
570 | eb08e09d | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
571 | eb08e09d | Michael Hanselmann | |
572 | eb08e09d | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
573 | eb08e09d | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
574 | eb08e09d | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeQueryStorage)) |
575 | eb08e09d | Michael Hanselmann | self.assertEqual(op.nodes, ["node21075"]) |
576 | eb08e09d | Michael Hanselmann | self.assertEqual(op.storage_type, constants.ST_LVM_PV)
|
577 | eb08e09d | Michael Hanselmann | self.assertEqual(op.output_fields, ["name", "other"]) |
578 | eb08e09d | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
579 | eb08e09d | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
580 | eb08e09d | Michael Hanselmann | |
581 | eb08e09d | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
582 | eb08e09d | Michael Hanselmann | |
583 | eb08e09d | Michael Hanselmann | def testErrors(self): |
584 | eb08e09d | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
585 | eb08e09d | Michael Hanselmann | |
586 | eb08e09d | Michael Hanselmann | queryargs = { |
587 | eb08e09d | Michael Hanselmann | "output_fields": "name,other", |
588 | eb08e09d | Michael Hanselmann | } |
589 | eb08e09d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage, |
590 | eb08e09d | Michael Hanselmann | ["node10538"], queryargs, {}, clfactory)
|
591 | eb08e09d | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.GET)
|
592 | eb08e09d | Michael Hanselmann | |
593 | eb08e09d | Michael Hanselmann | queryargs = { |
594 | eb08e09d | Michael Hanselmann | "storage_type": constants.ST_LVM_VG,
|
595 | eb08e09d | Michael Hanselmann | } |
596 | eb08e09d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage, |
597 | eb08e09d | Michael Hanselmann | ["node21273"], queryargs, {}, clfactory)
|
598 | eb08e09d | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.GET)
|
599 | eb08e09d | Michael Hanselmann | |
600 | eb08e09d | Michael Hanselmann | queryargs = { |
601 | eb08e09d | Michael Hanselmann | "storage_type": "##unknown_storage##", |
602 | eb08e09d | Michael Hanselmann | "output_fields": "name,other", |
603 | eb08e09d | Michael Hanselmann | } |
604 | eb08e09d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage, |
605 | eb08e09d | Michael Hanselmann | ["node10315"], queryargs, {}, clfactory)
|
606 | eb08e09d | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.GET)
|
607 | eb08e09d | Michael Hanselmann | |
608 | eb08e09d | Michael Hanselmann | |
609 | 8d232068 | Michael Hanselmann | class TestStorageModify(unittest.TestCase): |
610 | 8d232068 | Michael Hanselmann | def test(self): |
611 | 8d232068 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
612 | 8d232068 | Michael Hanselmann | |
613 | 8d232068 | Michael Hanselmann | for allocatable in [None, "1", "0"]: |
614 | 8d232068 | Michael Hanselmann | queryargs = { |
615 | 8d232068 | Michael Hanselmann | "storage_type": constants.ST_LVM_VG,
|
616 | 8d232068 | Michael Hanselmann | "name": "pv-a", |
617 | 8d232068 | Michael Hanselmann | } |
618 | 8d232068 | Michael Hanselmann | |
619 | 8d232068 | Michael Hanselmann | if allocatable is not None: |
620 | 8d232068 | Michael Hanselmann | queryargs["allocatable"] = allocatable
|
621 | 8d232068 | Michael Hanselmann | |
622 | 8d232068 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
623 | 8d232068 | Michael Hanselmann | ["node9292"], queryargs, {}, clfactory)
|
624 | 8d232068 | Michael Hanselmann | job_id = handler.PUT() |
625 | 8d232068 | Michael Hanselmann | |
626 | 8d232068 | Michael Hanselmann | cl = clfactory.GetNextClient() |
627 | 8d232068 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
628 | 8d232068 | Michael Hanselmann | |
629 | 8d232068 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
630 | 8d232068 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
631 | 8d232068 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeModifyStorage)) |
632 | 8d232068 | Michael Hanselmann | self.assertEqual(op.node_name, "node9292") |
633 | 8d232068 | Michael Hanselmann | self.assertEqual(op.storage_type, constants.ST_LVM_VG)
|
634 | 8d232068 | Michael Hanselmann | self.assertEqual(op.name, "pv-a") |
635 | 8d232068 | Michael Hanselmann | if allocatable is None: |
636 | 8d232068 | Michael Hanselmann | self.assertFalse(op.changes)
|
637 | 8d232068 | Michael Hanselmann | else:
|
638 | 8d232068 | Michael Hanselmann | assert allocatable in ("0", "1") |
639 | 8d232068 | Michael Hanselmann | self.assertEqual(op.changes, {
|
640 | 8d232068 | Michael Hanselmann | constants.SF_ALLOCATABLE: (allocatable == "1"),
|
641 | 8d232068 | Michael Hanselmann | }) |
642 | 8d232068 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
643 | 8d232068 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
644 | 8d232068 | Michael Hanselmann | |
645 | 8d232068 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
646 | 8d232068 | Michael Hanselmann | |
647 | 8d232068 | Michael Hanselmann | def testErrors(self): |
648 | 8d232068 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
649 | 8d232068 | Michael Hanselmann | |
650 | 8d232068 | Michael Hanselmann | # No storage type
|
651 | 8d232068 | Michael Hanselmann | queryargs = { |
652 | 8d232068 | Michael Hanselmann | "name": "xyz", |
653 | 8d232068 | Michael Hanselmann | } |
654 | 8d232068 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
655 | 8d232068 | Michael Hanselmann | ["node26016"], queryargs, {}, clfactory)
|
656 | 8d232068 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
657 | 8d232068 | Michael Hanselmann | |
658 | 8d232068 | Michael Hanselmann | # No name
|
659 | 8d232068 | Michael Hanselmann | queryargs = { |
660 | 8d232068 | Michael Hanselmann | "storage_type": constants.ST_LVM_VG,
|
661 | 8d232068 | Michael Hanselmann | } |
662 | 8d232068 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
663 | 8d232068 | Michael Hanselmann | ["node21218"], queryargs, {}, clfactory)
|
664 | 8d232068 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
665 | 8d232068 | Michael Hanselmann | |
666 | 8d232068 | Michael Hanselmann | # Invalid value
|
667 | 8d232068 | Michael Hanselmann | queryargs = { |
668 | 8d232068 | Michael Hanselmann | "storage_type": constants.ST_LVM_VG,
|
669 | 8d232068 | Michael Hanselmann | "name": "pv-b", |
670 | 8d232068 | Michael Hanselmann | "allocatable": "noint", |
671 | 8d232068 | Michael Hanselmann | } |
672 | 8d232068 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
673 | 8d232068 | Michael Hanselmann | ["node30685"], queryargs, {}, clfactory)
|
674 | 8d232068 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
675 | 8d232068 | Michael Hanselmann | |
676 | 8d232068 | Michael Hanselmann | |
677 | 98270691 | Michael Hanselmann | class TestStorageRepair(unittest.TestCase): |
678 | 98270691 | Michael Hanselmann | def test(self): |
679 | 98270691 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
680 | 98270691 | Michael Hanselmann | queryargs = { |
681 | 98270691 | Michael Hanselmann | "storage_type": constants.ST_LVM_PV,
|
682 | 98270691 | Michael Hanselmann | "name": "pv16611", |
683 | 98270691 | Michael Hanselmann | } |
684 | 98270691 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_repair, |
685 | 98270691 | Michael Hanselmann | ["node19265"], queryargs, {}, clfactory)
|
686 | 98270691 | Michael Hanselmann | job_id = handler.PUT() |
687 | 98270691 | Michael Hanselmann | |
688 | 98270691 | Michael Hanselmann | cl = clfactory.GetNextClient() |
689 | 98270691 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
690 | 98270691 | Michael Hanselmann | |
691 | 98270691 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
692 | 98270691 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
693 | 98270691 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpRepairNodeStorage)) |
694 | 98270691 | Michael Hanselmann | self.assertEqual(op.node_name, "node19265") |
695 | 98270691 | Michael Hanselmann | self.assertEqual(op.storage_type, constants.ST_LVM_PV)
|
696 | 98270691 | Michael Hanselmann | self.assertEqual(op.name, "pv16611") |
697 | 98270691 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
698 | 98270691 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
699 | 98270691 | Michael Hanselmann | |
700 | 98270691 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
701 | 98270691 | Michael Hanselmann | |
702 | 98270691 | Michael Hanselmann | def testErrors(self): |
703 | 98270691 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
704 | 98270691 | Michael Hanselmann | |
705 | 98270691 | Michael Hanselmann | # No storage type
|
706 | 98270691 | Michael Hanselmann | queryargs = { |
707 | 98270691 | Michael Hanselmann | "name": "xyz", |
708 | 98270691 | Michael Hanselmann | } |
709 | 98270691 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_repair, |
710 | 98270691 | Michael Hanselmann | ["node11275"], queryargs, {}, clfactory)
|
711 | 98270691 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
712 | 98270691 | Michael Hanselmann | |
713 | 98270691 | Michael Hanselmann | # No name
|
714 | 98270691 | Michael Hanselmann | queryargs = { |
715 | 98270691 | Michael Hanselmann | "storage_type": constants.ST_LVM_VG,
|
716 | 98270691 | Michael Hanselmann | } |
717 | 98270691 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_storage_repair, |
718 | 98270691 | Michael Hanselmann | ["node21218"], queryargs, {}, clfactory)
|
719 | 98270691 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
720 | 98270691 | Michael Hanselmann | |
721 | 98270691 | Michael Hanselmann | |
722 | 460ef073 | Michael Hanselmann | class TestTags(unittest.TestCase): |
723 | 460ef073 | Michael Hanselmann | TAG_HANDLERS = [ |
724 | 460ef073 | Michael Hanselmann | rlib2.R_2_instances_name_tags, |
725 | 460ef073 | Michael Hanselmann | rlib2.R_2_nodes_name_tags, |
726 | 460ef073 | Michael Hanselmann | rlib2.R_2_groups_name_tags, |
727 | 460ef073 | Michael Hanselmann | rlib2.R_2_tags, |
728 | 460ef073 | Michael Hanselmann | ] |
729 | 460ef073 | Michael Hanselmann | |
730 | 460ef073 | Michael Hanselmann | def testSetAndDelete(self): |
731 | 460ef073 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
732 | 460ef073 | Michael Hanselmann | |
733 | 460ef073 | Michael Hanselmann | for method, opcls in [("PUT", opcodes.OpTagsSet), |
734 | 460ef073 | Michael Hanselmann | ("DELETE", opcodes.OpTagsDel)]:
|
735 | 460ef073 | Michael Hanselmann | for idx, handler in enumerate(self.TAG_HANDLERS): |
736 | 460ef073 | Michael Hanselmann | dry_run = bool(idx % 2) |
737 | 460ef073 | Michael Hanselmann | name = "test%s" % idx
|
738 | 460ef073 | Michael Hanselmann | queryargs = { |
739 | 460ef073 | Michael Hanselmann | "tag": ["foo", "bar", "baz"], |
740 | 460ef073 | Michael Hanselmann | "dry-run": str(int(dry_run)), |
741 | 460ef073 | Michael Hanselmann | } |
742 | 460ef073 | Michael Hanselmann | |
743 | 460ef073 | Michael Hanselmann | handler = _CreateHandler(handler, [name], queryargs, {}, clfactory) |
744 | 460ef073 | Michael Hanselmann | job_id = getattr(handler, method)()
|
745 | 460ef073 | Michael Hanselmann | |
746 | 460ef073 | Michael Hanselmann | cl = clfactory.GetNextClient() |
747 | 460ef073 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
748 | 460ef073 | Michael Hanselmann | |
749 | 460ef073 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
750 | 460ef073 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
751 | 460ef073 | Michael Hanselmann | self.assertTrue(isinstance(op, opcls)) |
752 | 460ef073 | Michael Hanselmann | self.assertEqual(op.kind, handler.TAG_LEVEL)
|
753 | 460ef073 | Michael Hanselmann | if handler.TAG_LEVEL == constants.TAG_CLUSTER:
|
754 | 460ef073 | Michael Hanselmann | self.assertTrue(op.name is None) |
755 | 460ef073 | Michael Hanselmann | else:
|
756 | 460ef073 | Michael Hanselmann | self.assertEqual(op.name, name)
|
757 | 460ef073 | Michael Hanselmann | self.assertEqual(op.tags, ["foo", "bar", "baz"]) |
758 | 460ef073 | Michael Hanselmann | self.assertEqual(op.dry_run, dry_run)
|
759 | 460ef073 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
760 | 460ef073 | Michael Hanselmann | |
761 | 460ef073 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
762 | 460ef073 | Michael Hanselmann | |
763 | 460ef073 | Michael Hanselmann | |
764 | 09a43b39 | Michael Hanselmann | class TestInstanceCreation(testutils.GanetiTestCase): |
765 | 09a43b39 | Michael Hanselmann | def test(self): |
766 | 09a43b39 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
767 | 6395cebb | Michael Hanselmann | |
768 | 09a43b39 | Michael Hanselmann | name = "inst863.example.com"
|
769 | 6395cebb | Michael Hanselmann | |
770 | 6395cebb | Michael Hanselmann | disk_variants = [ |
771 | 6395cebb | Michael Hanselmann | # No disks
|
772 | 6395cebb | Michael Hanselmann | [], |
773 | 6395cebb | Michael Hanselmann | |
774 | 6395cebb | Michael Hanselmann | # Two disks
|
775 | 6395cebb | Michael Hanselmann | [{"size": 5, }, {"size": 100, }], |
776 | 6395cebb | Michael Hanselmann | |
777 | 6395cebb | Michael Hanselmann | # Disk with mode
|
778 | 6395cebb | Michael Hanselmann | [{"size": 123, "mode": constants.DISK_RDWR, }], |
779 | 6395cebb | Michael Hanselmann | ] |
780 | 6395cebb | Michael Hanselmann | |
781 | 6395cebb | Michael Hanselmann | nic_variants = [ |
782 | 6395cebb | Michael Hanselmann | # No NIC
|
783 | 6395cebb | Michael Hanselmann | [], |
784 | 6395cebb | Michael Hanselmann | |
785 | 6395cebb | Michael Hanselmann | # Three NICs
|
786 | 6395cebb | Michael Hanselmann | [{}, {}, {}], |
787 | 6395cebb | Michael Hanselmann | |
788 | 6395cebb | Michael Hanselmann | # Two NICs
|
789 | 6395cebb | Michael Hanselmann | [ |
790 | 54dc4fdb | Michael Hanselmann | { "ip": "192.0.2.6", "mode": constants.NIC_MODE_ROUTED, |
791 | 7be048f0 | Michael Hanselmann | "mac": "01:23:45:67:68:9A", |
792 | 7be048f0 | Michael Hanselmann | }, |
793 | ba05464f | Guido Trotter | { "mode": constants.NIC_MODE_BRIDGED, "link": "br1" }, |
794 | 6395cebb | Michael Hanselmann | ], |
795 | 6395cebb | Michael Hanselmann | ] |
796 | 6395cebb | Michael Hanselmann | |
797 | 6395cebb | Michael Hanselmann | beparam_variants = [ |
798 | 6395cebb | Michael Hanselmann | None,
|
799 | 6395cebb | Michael Hanselmann | {}, |
800 | 6395cebb | Michael Hanselmann | { constants.BE_VCPUS: 2, },
|
801 | 6395cebb | Michael Hanselmann | { constants.BE_MEMORY: 123, },
|
802 | 6395cebb | Michael Hanselmann | { constants.BE_VCPUS: 2,
|
803 | 6395cebb | Michael Hanselmann | constants.BE_MEMORY: 1024,
|
804 | 6395cebb | Michael Hanselmann | constants.BE_AUTO_BALANCE: True, }
|
805 | 6395cebb | Michael Hanselmann | ] |
806 | 6395cebb | Michael Hanselmann | |
807 | 6395cebb | Michael Hanselmann | hvparam_variants = [ |
808 | 6395cebb | Michael Hanselmann | None,
|
809 | 6395cebb | Michael Hanselmann | { constants.HV_BOOT_ORDER: "anc", },
|
810 | 6395cebb | Michael Hanselmann | { constants.HV_KERNEL_PATH: "/boot/fookernel",
|
811 | 6395cebb | Michael Hanselmann | constants.HV_ROOT_PATH: "/dev/hda1", },
|
812 | 6395cebb | Michael Hanselmann | ] |
813 | 6395cebb | Michael Hanselmann | |
814 | 6395cebb | Michael Hanselmann | for mode in [constants.INSTANCE_CREATE, constants.INSTANCE_IMPORT]: |
815 | 6395cebb | Michael Hanselmann | for nics in nic_variants: |
816 | 6395cebb | Michael Hanselmann | for disk_template in constants.DISK_TEMPLATES: |
817 | 6395cebb | Michael Hanselmann | for disks in disk_variants: |
818 | 6395cebb | Michael Hanselmann | for beparams in beparam_variants: |
819 | 6395cebb | Michael Hanselmann | for hvparams in hvparam_variants: |
820 | 6395cebb | Michael Hanselmann | for dry_run in [False, True]: |
821 | 09a43b39 | Michael Hanselmann | queryargs = { |
822 | 09a43b39 | Michael Hanselmann | "dry-run": str(int(dry_run)), |
823 | 09a43b39 | Michael Hanselmann | } |
824 | 09a43b39 | Michael Hanselmann | |
825 | 09a43b39 | Michael Hanselmann | data = { |
826 | 09a43b39 | Michael Hanselmann | rlib2._REQ_DATA_VERSION: 1,
|
827 | 09a43b39 | Michael Hanselmann | "name": name,
|
828 | 09a43b39 | Michael Hanselmann | "hypervisor": constants.HT_FAKE,
|
829 | 09a43b39 | Michael Hanselmann | "disks": disks,
|
830 | 09a43b39 | Michael Hanselmann | "nics": nics,
|
831 | 09a43b39 | Michael Hanselmann | "mode": mode,
|
832 | 09a43b39 | Michael Hanselmann | "disk_template": disk_template,
|
833 | 09a43b39 | Michael Hanselmann | "os": "debootstrap", |
834 | 09a43b39 | Michael Hanselmann | } |
835 | 09a43b39 | Michael Hanselmann | |
836 | 09a43b39 | Michael Hanselmann | if beparams is not None: |
837 | 09a43b39 | Michael Hanselmann | data["beparams"] = beparams
|
838 | 09a43b39 | Michael Hanselmann | |
839 | 09a43b39 | Michael Hanselmann | if hvparams is not None: |
840 | 09a43b39 | Michael Hanselmann | data["hvparams"] = hvparams
|
841 | 09a43b39 | Michael Hanselmann | |
842 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], |
843 | 09a43b39 | Michael Hanselmann | queryargs, data, clfactory) |
844 | 09a43b39 | Michael Hanselmann | job_id = handler.POST() |
845 | 09a43b39 | Michael Hanselmann | |
846 | 09a43b39 | Michael Hanselmann | cl = clfactory.GetNextClient() |
847 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
848 | 09a43b39 | Michael Hanselmann | |
849 | 09a43b39 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
850 | 09a43b39 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
851 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
852 | 09a43b39 | Michael Hanselmann | |
853 | 09a43b39 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceCreate)) |
854 | 09a43b39 | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
855 | 6395cebb | Michael Hanselmann | self.assertEqual(op.mode, mode)
|
856 | 6395cebb | Michael Hanselmann | self.assertEqual(op.disk_template, disk_template)
|
857 | 6395cebb | Michael Hanselmann | self.assertEqual(op.dry_run, dry_run)
|
858 | 6395cebb | Michael Hanselmann | self.assertEqual(len(op.disks), len(disks)) |
859 | 6395cebb | Michael Hanselmann | self.assertEqual(len(op.nics), len(nics)) |
860 | 6395cebb | Michael Hanselmann | |
861 | 7be048f0 | Michael Hanselmann | for opdisk, disk in zip(op.disks, disks): |
862 | 7be048f0 | Michael Hanselmann | for key in constants.IDISK_PARAMS: |
863 | 7be048f0 | Michael Hanselmann | self.assertEqual(opdisk.get(key), disk.get(key))
|
864 | 7be048f0 | Michael Hanselmann | self.assertFalse("unknown" in opdisk) |
865 | 7be048f0 | Michael Hanselmann | |
866 | 7be048f0 | Michael Hanselmann | for opnic, nic in zip(op.nics, nics): |
867 | 7be048f0 | Michael Hanselmann | for key in constants.INIC_PARAMS: |
868 | 7be048f0 | Michael Hanselmann | self.assertEqual(opnic.get(key), nic.get(key))
|
869 | 7be048f0 | Michael Hanselmann | self.assertFalse("unknown" in opnic) |
870 | 7be048f0 | Michael Hanselmann | self.assertFalse("foobar" in opnic) |
871 | 6395cebb | Michael Hanselmann | |
872 | 6395cebb | Michael Hanselmann | if beparams is None: |
873 | 526a662a | Michael Hanselmann | self.assertFalse(hasattr(op, "beparams")) |
874 | 6395cebb | Michael Hanselmann | else:
|
875 | 6395cebb | Michael Hanselmann | self.assertEqualValues(op.beparams, beparams)
|
876 | 6395cebb | Michael Hanselmann | |
877 | 6395cebb | Michael Hanselmann | if hvparams is None: |
878 | 526a662a | Michael Hanselmann | self.assertFalse(hasattr(op, "hvparams")) |
879 | 6395cebb | Michael Hanselmann | else:
|
880 | 6395cebb | Michael Hanselmann | self.assertEqualValues(op.hvparams, hvparams)
|
881 | 6395cebb | Michael Hanselmann | |
882 | 526a662a | Michael Hanselmann | def testLegacyName(self): |
883 | 09a43b39 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
884 | 09a43b39 | Michael Hanselmann | |
885 | 526a662a | Michael Hanselmann | name = "inst29128.example.com"
|
886 | 526a662a | Michael Hanselmann | data = { |
887 | 09a43b39 | Michael Hanselmann | rlib2._REQ_DATA_VERSION: 1,
|
888 | 526a662a | Michael Hanselmann | "name": name,
|
889 | 526a662a | Michael Hanselmann | "disks": [],
|
890 | 526a662a | Michael Hanselmann | "nics": [],
|
891 | 526a662a | Michael Hanselmann | "mode": constants.INSTANCE_CREATE,
|
892 | 526a662a | Michael Hanselmann | "disk_template": constants.DT_PLAIN,
|
893 | 526a662a | Michael Hanselmann | } |
894 | 09a43b39 | Michael Hanselmann | |
895 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
896 | 09a43b39 | Michael Hanselmann | job_id = handler.POST() |
897 | 09a43b39 | Michael Hanselmann | |
898 | 09a43b39 | Michael Hanselmann | cl = clfactory.GetNextClient() |
899 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
900 | 09a43b39 | Michael Hanselmann | |
901 | 09a43b39 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
902 | 09a43b39 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
903 | 09a43b39 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceCreate)) |
904 | 526a662a | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
905 | 526a662a | Michael Hanselmann | self.assertFalse(hasattr(op, "name")) |
906 | 09a43b39 | Michael Hanselmann | self.assertFalse(op.dry_run)
|
907 | 09a43b39 | Michael Hanselmann | |
908 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
909 | 526a662a | Michael Hanselmann | |
910 | 526a662a | Michael Hanselmann | # Define both
|
911 | 09a43b39 | Michael Hanselmann | data["instance_name"] = "other.example.com" |
912 | 09a43b39 | Michael Hanselmann | assert "name" in data and "instance_name" in data |
913 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
914 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
915 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
916 | 526a662a | Michael Hanselmann | |
917 | 526a662a | Michael Hanselmann | def testLegacyOs(self): |
918 | 09a43b39 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
919 | 09a43b39 | Michael Hanselmann | |
920 | 526a662a | Michael Hanselmann | name = "inst4673.example.com"
|
921 | 526a662a | Michael Hanselmann | os = "linux29206"
|
922 | 526a662a | Michael Hanselmann | data = { |
923 | 09a43b39 | Michael Hanselmann | rlib2._REQ_DATA_VERSION: 1,
|
924 | 526a662a | Michael Hanselmann | "name": name,
|
925 | 526a662a | Michael Hanselmann | "os_type": os,
|
926 | 526a662a | Michael Hanselmann | "disks": [],
|
927 | 526a662a | Michael Hanselmann | "nics": [],
|
928 | 526a662a | Michael Hanselmann | "mode": constants.INSTANCE_CREATE,
|
929 | 526a662a | Michael Hanselmann | "disk_template": constants.DT_PLAIN,
|
930 | 526a662a | Michael Hanselmann | } |
931 | 09a43b39 | Michael Hanselmann | |
932 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
933 | 09a43b39 | Michael Hanselmann | job_id = handler.POST() |
934 | 09a43b39 | Michael Hanselmann | |
935 | 09a43b39 | Michael Hanselmann | cl = clfactory.GetNextClient() |
936 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
937 | 09a43b39 | Michael Hanselmann | |
938 | 09a43b39 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
939 | 09a43b39 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
940 | 09a43b39 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceCreate)) |
941 | 526a662a | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
942 | 526a662a | Michael Hanselmann | self.assertEqual(op.os_type, os)
|
943 | 526a662a | Michael Hanselmann | self.assertFalse(hasattr(op, "os")) |
944 | 09a43b39 | Michael Hanselmann | self.assertFalse(op.dry_run)
|
945 | 09a43b39 | Michael Hanselmann | |
946 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
947 | 526a662a | Michael Hanselmann | |
948 | 526a662a | Michael Hanselmann | # Define both
|
949 | 09a43b39 | Michael Hanselmann | data["os"] = "linux9584" |
950 | 09a43b39 | Michael Hanselmann | assert "os" in data and "os_type" in data |
951 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
952 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
953 | 526a662a | Michael Hanselmann | |
954 | 6395cebb | Michael Hanselmann | def testErrors(self): |
955 | 09a43b39 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
956 | 09a43b39 | Michael Hanselmann | |
957 | 6395cebb | Michael Hanselmann | # Test all required fields
|
958 | 6395cebb | Michael Hanselmann | reqfields = { |
959 | 09a43b39 | Michael Hanselmann | rlib2._REQ_DATA_VERSION: 1,
|
960 | 6395cebb | Michael Hanselmann | "name": "inst1.example.com", |
961 | 6395cebb | Michael Hanselmann | "disks": [],
|
962 | 6395cebb | Michael Hanselmann | "nics": [],
|
963 | 6395cebb | Michael Hanselmann | "mode": constants.INSTANCE_CREATE,
|
964 | 130f0966 | Iustin Pop | "disk_template": constants.DT_PLAIN,
|
965 | 6395cebb | Michael Hanselmann | } |
966 | 6395cebb | Michael Hanselmann | |
967 | 6395cebb | Michael Hanselmann | for name in reqfields.keys(): |
968 | 09a43b39 | Michael Hanselmann | data = dict(i for i in reqfields.iteritems() if i[0] != name) |
969 | 09a43b39 | Michael Hanselmann | |
970 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
971 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
972 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
973 | 6395cebb | Michael Hanselmann | |
974 | 6395cebb | Michael Hanselmann | # Invalid disks and nics
|
975 | 6395cebb | Michael Hanselmann | for field in ["disks", "nics"]: |
976 | 526a662a | Michael Hanselmann | invalid_values = [None, 1, "", {}, [1, 2, 3], ["hda1", "hda2"], |
977 | 526a662a | Michael Hanselmann | [{"_unknown_": 999, }]] |
978 | 6395cebb | Michael Hanselmann | |
979 | 6395cebb | Michael Hanselmann | for invvalue in invalid_values: |
980 | 6395cebb | Michael Hanselmann | data = reqfields.copy() |
981 | 6395cebb | Michael Hanselmann | data[field] = invvalue |
982 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
983 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
984 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
985 | 09a43b39 | Michael Hanselmann | |
986 | 09a43b39 | Michael Hanselmann | def testVersion(self): |
987 | 09a43b39 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
988 | 09a43b39 | Michael Hanselmann | |
989 | 09a43b39 | Michael Hanselmann | # No version field
|
990 | 09a43b39 | Michael Hanselmann | data = { |
991 | 09a43b39 | Michael Hanselmann | "name": "inst1.example.com", |
992 | 09a43b39 | Michael Hanselmann | "disks": [],
|
993 | 09a43b39 | Michael Hanselmann | "nics": [],
|
994 | 09a43b39 | Michael Hanselmann | "mode": constants.INSTANCE_CREATE,
|
995 | 09a43b39 | Michael Hanselmann | "disk_template": constants.DT_PLAIN,
|
996 | 09a43b39 | Michael Hanselmann | } |
997 | 09a43b39 | Michael Hanselmann | |
998 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
999 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
1000 | 09a43b39 | Michael Hanselmann | |
1001 | 09a43b39 | Michael Hanselmann | # Old and incorrect versions
|
1002 | 09a43b39 | Michael Hanselmann | for version in [0, -1, 10483, "Hello World"]: |
1003 | 09a43b39 | Michael Hanselmann | data[rlib2._REQ_DATA_VERSION] = version |
1004 | 09a43b39 | Michael Hanselmann | |
1005 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
1006 | 09a43b39 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
1007 | 09a43b39 | Michael Hanselmann | |
1008 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1009 | 09a43b39 | Michael Hanselmann | |
1010 | 09a43b39 | Michael Hanselmann | # Correct version
|
1011 | 09a43b39 | Michael Hanselmann | data[rlib2._REQ_DATA_VERSION] = 1
|
1012 | 09a43b39 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances, [], {}, data, clfactory) |
1013 | 09a43b39 | Michael Hanselmann | job_id = handler.POST() |
1014 | 09a43b39 | Michael Hanselmann | |
1015 | 09a43b39 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1016 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1017 | 09a43b39 | Michael Hanselmann | |
1018 | 09a43b39 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1019 | 09a43b39 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1020 | 09a43b39 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceCreate)) |
1021 | 09a43b39 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1022 | 6395cebb | Michael Hanselmann | |
1023 | 6395cebb | Michael Hanselmann | |
1024 | 134afbe7 | Michael Hanselmann | class TestBackupExport(unittest.TestCase): |
1025 | ebeb600f | Michael Hanselmann | def test(self): |
1026 | 134afbe7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1027 | 134afbe7 | Michael Hanselmann | |
1028 | ebeb600f | Michael Hanselmann | name = "instmoo"
|
1029 | ebeb600f | Michael Hanselmann | data = { |
1030 | ebeb600f | Michael Hanselmann | "mode": constants.EXPORT_MODE_REMOTE,
|
1031 | ebeb600f | Michael Hanselmann | "destination": [(1, 2, 3), (99, 99, 99)], |
1032 | ebeb600f | Michael Hanselmann | "shutdown": True, |
1033 | ebeb600f | Michael Hanselmann | "remove_instance": True, |
1034 | 07ce3e70 | Michael Hanselmann | "x509_key_name": ["name", "hash"], |
1035 | 07ce3e70 | Michael Hanselmann | "destination_x509_ca": "---cert---" |
1036 | ebeb600f | Michael Hanselmann | } |
1037 | 134afbe7 | Michael Hanselmann | |
1038 | 134afbe7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_export, [name], {}, |
1039 | 134afbe7 | Michael Hanselmann | data, clfactory) |
1040 | 134afbe7 | Michael Hanselmann | job_id = handler.PUT() |
1041 | 134afbe7 | Michael Hanselmann | |
1042 | 134afbe7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1043 | 134afbe7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1044 | 134afbe7 | Michael Hanselmann | |
1045 | 134afbe7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1046 | 134afbe7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1047 | 134afbe7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpBackupExport)) |
1048 | ebeb600f | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1049 | ebeb600f | Michael Hanselmann | self.assertEqual(op.mode, constants.EXPORT_MODE_REMOTE)
|
1050 | 134afbe7 | Michael Hanselmann | self.assertEqual(op.target_node, [(1, 2, 3), (99, 99, 99)]) |
1051 | ebeb600f | Michael Hanselmann | self.assertEqual(op.shutdown, True) |
1052 | ebeb600f | Michael Hanselmann | self.assertEqual(op.remove_instance, True) |
1053 | 134afbe7 | Michael Hanselmann | self.assertEqual(op.x509_key_name, ["name", "hash"]) |
1054 | 07ce3e70 | Michael Hanselmann | self.assertEqual(op.destination_x509_ca, "---cert---") |
1055 | 134afbe7 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1056 | 134afbe7 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1057 | 134afbe7 | Michael Hanselmann | |
1058 | 134afbe7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1059 | ebeb600f | Michael Hanselmann | |
1060 | ebeb600f | Michael Hanselmann | def testDefaults(self): |
1061 | 134afbe7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1062 | 134afbe7 | Michael Hanselmann | |
1063 | ebeb600f | Michael Hanselmann | name = "inst1"
|
1064 | ebeb600f | Michael Hanselmann | data = { |
1065 | ebeb600f | Michael Hanselmann | "destination": "node2", |
1066 | ebeb600f | Michael Hanselmann | "shutdown": False, |
1067 | ebeb600f | Michael Hanselmann | } |
1068 | 134afbe7 | Michael Hanselmann | |
1069 | 134afbe7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_export, [name], {}, |
1070 | 134afbe7 | Michael Hanselmann | data, clfactory) |
1071 | 134afbe7 | Michael Hanselmann | job_id = handler.PUT() |
1072 | 134afbe7 | Michael Hanselmann | |
1073 | 134afbe7 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1074 | 134afbe7 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1075 | 134afbe7 | Michael Hanselmann | |
1076 | 134afbe7 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1077 | 134afbe7 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1078 | 134afbe7 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpBackupExport)) |
1079 | ebeb600f | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1080 | 07ce3e70 | Michael Hanselmann | self.assertEqual(op.target_node, "node2") |
1081 | 07ce3e70 | Michael Hanselmann | self.assertFalse(hasattr(op, "mode")) |
1082 | 07ce3e70 | Michael Hanselmann | self.assertFalse(hasattr(op, "remove_instance")) |
1083 | 07ce3e70 | Michael Hanselmann | self.assertFalse(hasattr(op, "destination")) |
1084 | 134afbe7 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1085 | 134afbe7 | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1086 | 134afbe7 | Michael Hanselmann | |
1087 | 134afbe7 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1088 | ebeb600f | Michael Hanselmann | |
1089 | ebeb600f | Michael Hanselmann | def testErrors(self): |
1090 | 134afbe7 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1091 | 134afbe7 | Michael Hanselmann | |
1092 | 134afbe7 | Michael Hanselmann | for value in ["True", "False"]: |
1093 | 134afbe7 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_export, ["err1"], {}, {
|
1094 | 134afbe7 | Michael Hanselmann | "remove_instance": value,
|
1095 | 134afbe7 | Michael Hanselmann | }, clfactory) |
1096 | 134afbe7 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
1097 | ebeb600f | Michael Hanselmann | |
1098 | ebeb600f | Michael Hanselmann | |
1099 | 075a29be | Michael Hanselmann | class TestInstanceMigrate(testutils.GanetiTestCase): |
1100 | 5823e0d2 | Michael Hanselmann | def test(self): |
1101 | 075a29be | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1102 | 075a29be | Michael Hanselmann | |
1103 | 5823e0d2 | Michael Hanselmann | name = "instYooho6ek"
|
1104 | 5823e0d2 | Michael Hanselmann | |
1105 | 5823e0d2 | Michael Hanselmann | for cleanup in [False, True]: |
1106 | 5823e0d2 | Michael Hanselmann | for mode in constants.HT_MIGRATION_MODES: |
1107 | 5823e0d2 | Michael Hanselmann | data = { |
1108 | 5823e0d2 | Michael Hanselmann | "cleanup": cleanup,
|
1109 | 5823e0d2 | Michael Hanselmann | "mode": mode,
|
1110 | 5823e0d2 | Michael Hanselmann | } |
1111 | 075a29be | Michael Hanselmann | |
1112 | 075a29be | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_migrate, [name], {}, |
1113 | 075a29be | Michael Hanselmann | data, clfactory) |
1114 | 075a29be | Michael Hanselmann | job_id = handler.PUT() |
1115 | 075a29be | Michael Hanselmann | |
1116 | 075a29be | Michael Hanselmann | cl = clfactory.GetNextClient() |
1117 | 075a29be | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1118 | 075a29be | Michael Hanselmann | |
1119 | 075a29be | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1120 | 075a29be | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1121 | 075a29be | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceMigrate)) |
1122 | 5823e0d2 | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1123 | 5823e0d2 | Michael Hanselmann | self.assertEqual(op.mode, mode)
|
1124 | 5823e0d2 | Michael Hanselmann | self.assertEqual(op.cleanup, cleanup)
|
1125 | 075a29be | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1126 | 075a29be | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1127 | 075a29be | Michael Hanselmann | |
1128 | 075a29be | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1129 | 5823e0d2 | Michael Hanselmann | |
1130 | 5823e0d2 | Michael Hanselmann | def testDefaults(self): |
1131 | 075a29be | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1132 | 075a29be | Michael Hanselmann | |
1133 | 5823e0d2 | Michael Hanselmann | name = "instnohZeex0"
|
1134 | 5823e0d2 | Michael Hanselmann | |
1135 | 075a29be | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_migrate, [name], {}, {}, |
1136 | 075a29be | Michael Hanselmann | clfactory) |
1137 | 075a29be | Michael Hanselmann | job_id = handler.PUT() |
1138 | 075a29be | Michael Hanselmann | |
1139 | 075a29be | Michael Hanselmann | cl = clfactory.GetNextClient() |
1140 | 075a29be | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1141 | 075a29be | Michael Hanselmann | |
1142 | 075a29be | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1143 | 075a29be | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1144 | 075a29be | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceMigrate)) |
1145 | 5823e0d2 | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1146 | c1a27c9a | Michael Hanselmann | self.assertFalse(hasattr(op, "mode")) |
1147 | c1a27c9a | Michael Hanselmann | self.assertFalse(hasattr(op, "cleanup")) |
1148 | 075a29be | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1149 | 075a29be | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1150 | 075a29be | Michael Hanselmann | |
1151 | 075a29be | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1152 | 5823e0d2 | Michael Hanselmann | |
1153 | 5823e0d2 | Michael Hanselmann | |
1154 | d56e7dc7 | Michael Hanselmann | class TestParseRenameInstanceRequest(testutils.GanetiTestCase): |
1155 | d56e7dc7 | Michael Hanselmann | def test(self): |
1156 | d76f9b5d | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1157 | d76f9b5d | Michael Hanselmann | |
1158 | d56e7dc7 | Michael Hanselmann | name = "instij0eeph7"
|
1159 | d56e7dc7 | Michael Hanselmann | |
1160 | d56e7dc7 | Michael Hanselmann | for new_name in ["ua0aiyoo", "fai3ongi"]: |
1161 | d56e7dc7 | Michael Hanselmann | for ip_check in [False, True]: |
1162 | d56e7dc7 | Michael Hanselmann | for name_check in [False, True]: |
1163 | d56e7dc7 | Michael Hanselmann | data = { |
1164 | d56e7dc7 | Michael Hanselmann | "new_name": new_name,
|
1165 | d56e7dc7 | Michael Hanselmann | "ip_check": ip_check,
|
1166 | d56e7dc7 | Michael Hanselmann | "name_check": name_check,
|
1167 | d56e7dc7 | Michael Hanselmann | } |
1168 | d56e7dc7 | Michael Hanselmann | |
1169 | d76f9b5d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_rename, [name], |
1170 | d76f9b5d | Michael Hanselmann | {}, data, clfactory) |
1171 | d76f9b5d | Michael Hanselmann | job_id = handler.PUT() |
1172 | d76f9b5d | Michael Hanselmann | |
1173 | d76f9b5d | Michael Hanselmann | cl = clfactory.GetNextClient() |
1174 | d76f9b5d | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1175 | d76f9b5d | Michael Hanselmann | |
1176 | d76f9b5d | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1177 | d76f9b5d | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1178 | d76f9b5d | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceRename)) |
1179 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1180 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.new_name, new_name)
|
1181 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.ip_check, ip_check)
|
1182 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.name_check, name_check)
|
1183 | d76f9b5d | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1184 | d76f9b5d | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1185 | d76f9b5d | Michael Hanselmann | |
1186 | d76f9b5d | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1187 | d56e7dc7 | Michael Hanselmann | |
1188 | d56e7dc7 | Michael Hanselmann | def testDefaults(self): |
1189 | d76f9b5d | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1190 | d76f9b5d | Michael Hanselmann | |
1191 | d56e7dc7 | Michael Hanselmann | name = "instahchie3t"
|
1192 | d56e7dc7 | Michael Hanselmann | |
1193 | d56e7dc7 | Michael Hanselmann | for new_name in ["thag9mek", "quees7oh"]: |
1194 | d56e7dc7 | Michael Hanselmann | data = { |
1195 | d56e7dc7 | Michael Hanselmann | "new_name": new_name,
|
1196 | d56e7dc7 | Michael Hanselmann | } |
1197 | d56e7dc7 | Michael Hanselmann | |
1198 | d76f9b5d | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_rename, [name], |
1199 | d76f9b5d | Michael Hanselmann | {}, data, clfactory) |
1200 | d76f9b5d | Michael Hanselmann | job_id = handler.PUT() |
1201 | d76f9b5d | Michael Hanselmann | |
1202 | d76f9b5d | Michael Hanselmann | cl = clfactory.GetNextClient() |
1203 | d76f9b5d | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1204 | d76f9b5d | Michael Hanselmann | |
1205 | d76f9b5d | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1206 | d76f9b5d | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1207 | d76f9b5d | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceRename)) |
1208 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1209 | d56e7dc7 | Michael Hanselmann | self.assertEqual(op.new_name, new_name)
|
1210 | 88bc199a | Michael Hanselmann | self.assertFalse(hasattr(op, "ip_check")) |
1211 | 88bc199a | Michael Hanselmann | self.assertFalse(hasattr(op, "name_check")) |
1212 | d76f9b5d | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1213 | d76f9b5d | Michael Hanselmann | self.assertFalse(hasattr(op, "force")) |
1214 | d76f9b5d | Michael Hanselmann | |
1215 | d76f9b5d | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1216 | d56e7dc7 | Michael Hanselmann | |
1217 | d56e7dc7 | Michael Hanselmann | |
1218 | f3db88ba | Michael Hanselmann | class TestParseModifyInstanceRequest(unittest.TestCase): |
1219 | 3882937a | Michael Hanselmann | def test(self): |
1220 | f3db88ba | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1221 | f3db88ba | Michael Hanselmann | |
1222 | 3882937a | Michael Hanselmann | name = "instush8gah"
|
1223 | 3882937a | Michael Hanselmann | |
1224 | 3882937a | Michael Hanselmann | test_disks = [ |
1225 | 3882937a | Michael Hanselmann | [], |
1226 | 3882937a | Michael Hanselmann | [(1, { constants.IDISK_MODE: constants.DISK_RDWR, })],
|
1227 | 3882937a | Michael Hanselmann | ] |
1228 | 3882937a | Michael Hanselmann | |
1229 | 3882937a | Michael Hanselmann | for osparams in [{}, { "some": "value", "other": "Hello World", }]: |
1230 | 3882937a | Michael Hanselmann | for hvparams in [{}, { constants.HV_KERNEL_PATH: "/some/kernel", }]: |
1231 | 3882937a | Michael Hanselmann | for beparams in [{}, { constants.BE_MEMORY: 128, }]: |
1232 | 3882937a | Michael Hanselmann | for force in [False, True]: |
1233 | 3882937a | Michael Hanselmann | for nics in [[], [(0, { constants.INIC_IP: "192.0.2.1", })]]: |
1234 | 3882937a | Michael Hanselmann | for disks in test_disks: |
1235 | 3882937a | Michael Hanselmann | for disk_template in constants.DISK_TEMPLATES: |
1236 | 3882937a | Michael Hanselmann | data = { |
1237 | 3882937a | Michael Hanselmann | "osparams": osparams,
|
1238 | 3882937a | Michael Hanselmann | "hvparams": hvparams,
|
1239 | 3882937a | Michael Hanselmann | "beparams": beparams,
|
1240 | 3882937a | Michael Hanselmann | "nics": nics,
|
1241 | 3882937a | Michael Hanselmann | "disks": disks,
|
1242 | 3882937a | Michael Hanselmann | "force": force,
|
1243 | 3882937a | Michael Hanselmann | "disk_template": disk_template,
|
1244 | 3882937a | Michael Hanselmann | } |
1245 | 3882937a | Michael Hanselmann | |
1246 | f3db88ba | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_modify, |
1247 | f3db88ba | Michael Hanselmann | [name], {}, data, clfactory) |
1248 | f3db88ba | Michael Hanselmann | job_id = handler.PUT() |
1249 | f3db88ba | Michael Hanselmann | |
1250 | f3db88ba | Michael Hanselmann | cl = clfactory.GetNextClient() |
1251 | f3db88ba | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1252 | f3db88ba | Michael Hanselmann | |
1253 | f3db88ba | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1254 | f3db88ba | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1255 | f3db88ba | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceSetParams)) |
1256 | 3882937a | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1257 | 3882937a | Michael Hanselmann | self.assertEqual(op.hvparams, hvparams)
|
1258 | 3882937a | Michael Hanselmann | self.assertEqual(op.beparams, beparams)
|
1259 | 3882937a | Michael Hanselmann | self.assertEqual(op.osparams, osparams)
|
1260 | 3882937a | Michael Hanselmann | self.assertEqual(op.force, force)
|
1261 | 3882937a | Michael Hanselmann | self.assertEqual(op.nics, nics)
|
1262 | 3882937a | Michael Hanselmann | self.assertEqual(op.disks, disks)
|
1263 | 3882937a | Michael Hanselmann | self.assertEqual(op.disk_template, disk_template)
|
1264 | ee5549c7 | Michael Hanselmann | self.assertFalse(hasattr(op, "remote_node")) |
1265 | ee5549c7 | Michael Hanselmann | self.assertFalse(hasattr(op, "os_name")) |
1266 | ee5549c7 | Michael Hanselmann | self.assertFalse(hasattr(op, "force_variant")) |
1267 | f3db88ba | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1268 | f3db88ba | Michael Hanselmann | |
1269 | f3db88ba | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1270 | 3882937a | Michael Hanselmann | |
1271 | 3882937a | Michael Hanselmann | def testDefaults(self): |
1272 | f3db88ba | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1273 | f3db88ba | Michael Hanselmann | |
1274 | 3882937a | Michael Hanselmann | name = "instir8aish31"
|
1275 | 3882937a | Michael Hanselmann | |
1276 | f3db88ba | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_modify, |
1277 | f3db88ba | Michael Hanselmann | [name], {}, {}, clfactory) |
1278 | f3db88ba | Michael Hanselmann | job_id = handler.PUT() |
1279 | f3db88ba | Michael Hanselmann | |
1280 | f3db88ba | Michael Hanselmann | cl = clfactory.GetNextClient() |
1281 | f3db88ba | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1282 | f3db88ba | Michael Hanselmann | |
1283 | f3db88ba | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1284 | f3db88ba | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1285 | f3db88ba | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceSetParams)) |
1286 | 3882937a | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1287 | f3db88ba | Michael Hanselmann | |
1288 | ee5549c7 | Michael Hanselmann | for i in ["hvparams", "beparams", "osparams", "force", "nics", "disks", |
1289 | ee5549c7 | Michael Hanselmann | "disk_template", "remote_node", "os_name", "force_variant"]: |
1290 | ee5549c7 | Michael Hanselmann | self.assertFalse(hasattr(op, i)) |
1291 | 3882937a | Michael Hanselmann | |
1292 | 3882937a | Michael Hanselmann | |
1293 | c744425f | Michael Hanselmann | class TestParseInstanceReinstallRequest(testutils.GanetiTestCase): |
1294 | c744425f | Michael Hanselmann | def setUp(self): |
1295 | c744425f | Michael Hanselmann | testutils.GanetiTestCase.setUp(self)
|
1296 | c744425f | Michael Hanselmann | |
1297 | c744425f | Michael Hanselmann | self.Parse = rlib2._ParseInstanceReinstallRequest
|
1298 | c744425f | Michael Hanselmann | |
1299 | c744425f | Michael Hanselmann | def _Check(self, ops, name): |
1300 | c744425f | Michael Hanselmann | expcls = [ |
1301 | ee3e37a7 | Iustin Pop | opcodes.OpInstanceShutdown, |
1302 | 5073fd8f | Iustin Pop | opcodes.OpInstanceReinstall, |
1303 | c873d91c | Iustin Pop | opcodes.OpInstanceStartup, |
1304 | c744425f | Michael Hanselmann | ] |
1305 | c744425f | Michael Hanselmann | |
1306 | c744425f | Michael Hanselmann | self.assert_(compat.all(isinstance(op, exp) |
1307 | c744425f | Michael Hanselmann | for op, exp in zip(ops, expcls))) |
1308 | c744425f | Michael Hanselmann | self.assert_(compat.all(op.instance_name == name for op in ops)) |
1309 | c744425f | Michael Hanselmann | |
1310 | c744425f | Michael Hanselmann | def test(self): |
1311 | c744425f | Michael Hanselmann | name = "shoo0tihohma"
|
1312 | c744425f | Michael Hanselmann | |
1313 | c744425f | Michael Hanselmann | ops = self.Parse(name, {"os": "sys1", "start": True,}) |
1314 | c744425f | Michael Hanselmann | self.assertEqual(len(ops), 3) |
1315 | c744425f | Michael Hanselmann | self._Check(ops, name)
|
1316 | c744425f | Michael Hanselmann | self.assertEqual(ops[1].os_type, "sys1") |
1317 | c744425f | Michael Hanselmann | self.assertFalse(ops[1].osparams) |
1318 | c744425f | Michael Hanselmann | |
1319 | c744425f | Michael Hanselmann | ops = self.Parse(name, {"os": "sys2", "start": False,}) |
1320 | c744425f | Michael Hanselmann | self.assertEqual(len(ops), 2) |
1321 | c744425f | Michael Hanselmann | self._Check(ops, name)
|
1322 | c744425f | Michael Hanselmann | self.assertEqual(ops[1].os_type, "sys2") |
1323 | c744425f | Michael Hanselmann | |
1324 | c744425f | Michael Hanselmann | osparams = { |
1325 | c744425f | Michael Hanselmann | "reformat": "1", |
1326 | c744425f | Michael Hanselmann | } |
1327 | c744425f | Michael Hanselmann | ops = self.Parse(name, {"os": "sys4035", "start": True, |
1328 | c744425f | Michael Hanselmann | "osparams": osparams,})
|
1329 | c744425f | Michael Hanselmann | self.assertEqual(len(ops), 3) |
1330 | c744425f | Michael Hanselmann | self._Check(ops, name)
|
1331 | c744425f | Michael Hanselmann | self.assertEqual(ops[1].os_type, "sys4035") |
1332 | c744425f | Michael Hanselmann | self.assertEqual(ops[1].osparams, osparams) |
1333 | c744425f | Michael Hanselmann | |
1334 | c744425f | Michael Hanselmann | def testDefaults(self): |
1335 | c744425f | Michael Hanselmann | name = "noolee0g"
|
1336 | c744425f | Michael Hanselmann | |
1337 | c744425f | Michael Hanselmann | ops = self.Parse(name, {"os": "linux1"}) |
1338 | c744425f | Michael Hanselmann | self.assertEqual(len(ops), 3) |
1339 | c744425f | Michael Hanselmann | self._Check(ops, name)
|
1340 | c744425f | Michael Hanselmann | self.assertEqual(ops[1].os_type, "linux1") |
1341 | c744425f | Michael Hanselmann | self.assertFalse(ops[1].osparams) |
1342 | c744425f | Michael Hanselmann | |
1343 | a14b80bc | Michael Hanselmann | def testErrors(self): |
1344 | 97f8e7f0 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, self.Parse, |
1345 | 97f8e7f0 | Michael Hanselmann | "foo", "not a dictionary") |
1346 | a14b80bc | Michael Hanselmann | |
1347 | c744425f | Michael Hanselmann | |
1348 | cd0d4d5a | Michael Hanselmann | class TestGroupRename(unittest.TestCase): |
1349 | 0dbaa9ca | Adeodato Simo | def test(self): |
1350 | cd0d4d5a | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1351 | cd0d4d5a | Michael Hanselmann | |
1352 | cd0d4d5a | Michael Hanselmann | name = "group608242564"
|
1353 | 0dbaa9ca | Adeodato Simo | data = { |
1354 | cd0d4d5a | Michael Hanselmann | "new_name": "ua0aiyoo15112", |
1355 | 0dbaa9ca | Adeodato Simo | } |
1356 | 0dbaa9ca | Adeodato Simo | |
1357 | cd0d4d5a | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_rename, [name], {}, data, |
1358 | cd0d4d5a | Michael Hanselmann | clfactory) |
1359 | cd0d4d5a | Michael Hanselmann | job_id = handler.PUT() |
1360 | cd0d4d5a | Michael Hanselmann | |
1361 | cd0d4d5a | Michael Hanselmann | cl = clfactory.GetNextClient() |
1362 | cd0d4d5a | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1363 | cd0d4d5a | Michael Hanselmann | |
1364 | cd0d4d5a | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1365 | cd0d4d5a | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1366 | 0dbaa9ca | Adeodato Simo | |
1367 | cd0d4d5a | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupRename)) |
1368 | 12da663a | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1369 | cd0d4d5a | Michael Hanselmann | self.assertEqual(op.new_name, "ua0aiyoo15112") |
1370 | 0dbaa9ca | Adeodato Simo | self.assertFalse(op.dry_run)
|
1371 | cd0d4d5a | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1372 | 0dbaa9ca | Adeodato Simo | |
1373 | 0dbaa9ca | Adeodato Simo | def testDryRun(self): |
1374 | cd0d4d5a | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1375 | cd0d4d5a | Michael Hanselmann | |
1376 | cd0d4d5a | Michael Hanselmann | name = "group28548"
|
1377 | 0dbaa9ca | Adeodato Simo | data = { |
1378 | 0dbaa9ca | Adeodato Simo | "new_name": "ua0aiyoo", |
1379 | 0dbaa9ca | Adeodato Simo | } |
1380 | 0dbaa9ca | Adeodato Simo | |
1381 | cd0d4d5a | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_rename, [name], { |
1382 | cd0d4d5a | Michael Hanselmann | "dry-run": ["1"], |
1383 | cd0d4d5a | Michael Hanselmann | }, data, clfactory) |
1384 | cd0d4d5a | Michael Hanselmann | job_id = handler.PUT() |
1385 | 0dbaa9ca | Adeodato Simo | |
1386 | cd0d4d5a | Michael Hanselmann | cl = clfactory.GetNextClient() |
1387 | cd0d4d5a | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1388 | cd0d4d5a | Michael Hanselmann | |
1389 | cd0d4d5a | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1390 | cd0d4d5a | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1391 | cd0d4d5a | Michael Hanselmann | |
1392 | cd0d4d5a | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupRename)) |
1393 | 12da663a | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1394 | 0dbaa9ca | Adeodato Simo | self.assertEqual(op.new_name, "ua0aiyoo") |
1395 | cd0d4d5a | Michael Hanselmann | self.assertTrue(op.dry_run)
|
1396 | cd0d4d5a | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1397 | 0dbaa9ca | Adeodato Simo | |
1398 | 0dbaa9ca | Adeodato Simo | |
1399 | 0dbc732c | Michael Hanselmann | class TestInstanceReplaceDisks(unittest.TestCase): |
1400 | d1c172de | Michael Hanselmann | def test(self): |
1401 | 0dbc732c | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1402 | 0dbc732c | Michael Hanselmann | |
1403 | d1c172de | Michael Hanselmann | name = "inst22568"
|
1404 | d1c172de | Michael Hanselmann | |
1405 | d1c172de | Michael Hanselmann | for disks in [range(1, 4), "1,2,3", "1, 2, 3"]: |
1406 | d1c172de | Michael Hanselmann | data = { |
1407 | d1c172de | Michael Hanselmann | "mode": constants.REPLACE_DISK_SEC,
|
1408 | d1c172de | Michael Hanselmann | "disks": disks,
|
1409 | d1c172de | Michael Hanselmann | "iallocator": "myalloc", |
1410 | d1c172de | Michael Hanselmann | } |
1411 | d1c172de | Michael Hanselmann | |
1412 | 0dbc732c | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_replace_disks, |
1413 | 0dbc732c | Michael Hanselmann | [name], {}, data, clfactory) |
1414 | 0dbc732c | Michael Hanselmann | job_id = handler.POST() |
1415 | 0dbc732c | Michael Hanselmann | |
1416 | 0dbc732c | Michael Hanselmann | cl = clfactory.GetNextClient() |
1417 | 0dbc732c | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1418 | 0dbc732c | Michael Hanselmann | |
1419 | 0dbc732c | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1420 | 0dbc732c | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1421 | 0dbc732c | Michael Hanselmann | |
1422 | 0dbc732c | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceReplaceDisks)) |
1423 | 0dbc732c | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1424 | d1c172de | Michael Hanselmann | self.assertEqual(op.mode, constants.REPLACE_DISK_SEC)
|
1425 | d1c172de | Michael Hanselmann | self.assertEqual(op.disks, [1, 2, 3]) |
1426 | d1c172de | Michael Hanselmann | self.assertEqual(op.iallocator, "myalloc") |
1427 | 0dbc732c | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1428 | d1c172de | Michael Hanselmann | |
1429 | d1c172de | Michael Hanselmann | def testDefaults(self): |
1430 | 0dbc732c | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1431 | 0dbc732c | Michael Hanselmann | |
1432 | d1c172de | Michael Hanselmann | name = "inst11413"
|
1433 | d1c172de | Michael Hanselmann | data = { |
1434 | d1c172de | Michael Hanselmann | "mode": constants.REPLACE_DISK_AUTO,
|
1435 | d1c172de | Michael Hanselmann | } |
1436 | d1c172de | Michael Hanselmann | |
1437 | 0dbc732c | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_replace_disks, |
1438 | 0dbc732c | Michael Hanselmann | [name], {}, data, clfactory) |
1439 | 0dbc732c | Michael Hanselmann | job_id = handler.POST() |
1440 | 0dbc732c | Michael Hanselmann | |
1441 | 0dbc732c | Michael Hanselmann | cl = clfactory.GetNextClient() |
1442 | 0dbc732c | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1443 | 0dbc732c | Michael Hanselmann | |
1444 | 0dbc732c | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1445 | 0dbc732c | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1446 | 0dbc732c | Michael Hanselmann | |
1447 | 0dbc732c | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpInstanceReplaceDisks)) |
1448 | 0dbc732c | Michael Hanselmann | self.assertEqual(op.instance_name, name)
|
1449 | d1c172de | Michael Hanselmann | self.assertEqual(op.mode, constants.REPLACE_DISK_AUTO)
|
1450 | d1c172de | Michael Hanselmann | self.assertFalse(hasattr(op, "iallocator")) |
1451 | d1c172de | Michael Hanselmann | self.assertFalse(hasattr(op, "disks")) |
1452 | 0dbc732c | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1453 | d1c172de | Michael Hanselmann | |
1454 | d1c172de | Michael Hanselmann | def testWrong(self): |
1455 | 0dbc732c | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1456 | 0dbc732c | Michael Hanselmann | |
1457 | 0dbc732c | Michael Hanselmann | data = { |
1458 | 0dbc732c | Michael Hanselmann | "mode": constants.REPLACE_DISK_AUTO,
|
1459 | 0dbc732c | Michael Hanselmann | "disks": "hello world", |
1460 | 0dbc732c | Michael Hanselmann | } |
1461 | 0dbc732c | Michael Hanselmann | |
1462 | 0dbc732c | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_instances_name_replace_disks, |
1463 | 0dbc732c | Michael Hanselmann | ["foo"], {}, data, clfactory)
|
1464 | 0dbc732c | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
1465 | d1c172de | Michael Hanselmann | |
1466 | d1c172de | Michael Hanselmann | |
1467 | d5211458 | Michael Hanselmann | class TestGroupModify(unittest.TestCase): |
1468 | df340fae | Michael Hanselmann | def test(self): |
1469 | d5211458 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1470 | d5211458 | Michael Hanselmann | |
1471 | df340fae | Michael Hanselmann | name = "group6002"
|
1472 | df340fae | Michael Hanselmann | |
1473 | df340fae | Michael Hanselmann | for policy in constants.VALID_ALLOC_POLICIES: |
1474 | df340fae | Michael Hanselmann | data = { |
1475 | df340fae | Michael Hanselmann | "alloc_policy": policy,
|
1476 | df340fae | Michael Hanselmann | } |
1477 | df340fae | Michael Hanselmann | |
1478 | d5211458 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_modify, [name], {}, data, |
1479 | d5211458 | Michael Hanselmann | clfactory) |
1480 | d5211458 | Michael Hanselmann | job_id = handler.PUT() |
1481 | d5211458 | Michael Hanselmann | |
1482 | d5211458 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1483 | d5211458 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1484 | d5211458 | Michael Hanselmann | |
1485 | d5211458 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1486 | d5211458 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1487 | d5211458 | Michael Hanselmann | |
1488 | d5211458 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupSetParams)) |
1489 | df340fae | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1490 | df340fae | Michael Hanselmann | self.assertEqual(op.alloc_policy, policy)
|
1491 | d5211458 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1492 | d5211458 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1493 | df340fae | Michael Hanselmann | |
1494 | df340fae | Michael Hanselmann | def testUnknownPolicy(self): |
1495 | d5211458 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1496 | d5211458 | Michael Hanselmann | |
1497 | df340fae | Michael Hanselmann | data = { |
1498 | df340fae | Michael Hanselmann | "alloc_policy": "_unknown_policy_", |
1499 | df340fae | Michael Hanselmann | } |
1500 | df340fae | Michael Hanselmann | |
1501 | d5211458 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_modify, ["xyz"], {}, data,
|
1502 | d5211458 | Michael Hanselmann | clfactory) |
1503 | d5211458 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
1504 | d5211458 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1505 | df340fae | Michael Hanselmann | |
1506 | df340fae | Michael Hanselmann | def testDefaults(self): |
1507 | d5211458 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1508 | d5211458 | Michael Hanselmann | |
1509 | df340fae | Michael Hanselmann | name = "group6679"
|
1510 | df340fae | Michael Hanselmann | |
1511 | d5211458 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups_name_modify, [name], {}, {}, |
1512 | d5211458 | Michael Hanselmann | clfactory) |
1513 | d5211458 | Michael Hanselmann | job_id = handler.PUT() |
1514 | d5211458 | Michael Hanselmann | |
1515 | d5211458 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1516 | d5211458 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1517 | d5211458 | Michael Hanselmann | |
1518 | d5211458 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1519 | d5211458 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1520 | d5211458 | Michael Hanselmann | |
1521 | d5211458 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupSetParams)) |
1522 | df340fae | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1523 | df340fae | Michael Hanselmann | self.assertFalse(hasattr(op, "alloc_policy")) |
1524 | d5211458 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1525 | d5211458 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1526 | df340fae | Michael Hanselmann | |
1527 | df340fae | Michael Hanselmann | |
1528 | c91407bc | Michael Hanselmann | class TestGroupAdd(unittest.TestCase): |
1529 | 527fbde8 | Michael Hanselmann | def test(self): |
1530 | 527fbde8 | Michael Hanselmann | name = "group3618"
|
1531 | c91407bc | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1532 | 527fbde8 | Michael Hanselmann | |
1533 | 527fbde8 | Michael Hanselmann | for policy in constants.VALID_ALLOC_POLICIES: |
1534 | 527fbde8 | Michael Hanselmann | data = { |
1535 | 527fbde8 | Michael Hanselmann | "group_name": name,
|
1536 | 527fbde8 | Michael Hanselmann | "alloc_policy": policy,
|
1537 | 527fbde8 | Michael Hanselmann | } |
1538 | 527fbde8 | Michael Hanselmann | |
1539 | c91407bc | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups, [], {}, data, |
1540 | c91407bc | Michael Hanselmann | clfactory) |
1541 | c91407bc | Michael Hanselmann | job_id = handler.POST() |
1542 | c91407bc | Michael Hanselmann | |
1543 | c91407bc | Michael Hanselmann | cl = clfactory.GetNextClient() |
1544 | c91407bc | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1545 | c91407bc | Michael Hanselmann | |
1546 | c91407bc | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1547 | c91407bc | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1548 | c91407bc | Michael Hanselmann | |
1549 | c91407bc | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupAdd)) |
1550 | 527fbde8 | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1551 | 527fbde8 | Michael Hanselmann | self.assertEqual(op.alloc_policy, policy)
|
1552 | 527fbde8 | Michael Hanselmann | self.assertFalse(op.dry_run)
|
1553 | c91407bc | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1554 | 527fbde8 | Michael Hanselmann | |
1555 | 527fbde8 | Michael Hanselmann | def testUnknownPolicy(self): |
1556 | c91407bc | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1557 | c91407bc | Michael Hanselmann | |
1558 | 527fbde8 | Michael Hanselmann | data = { |
1559 | 527fbde8 | Michael Hanselmann | "alloc_policy": "_unknown_policy_", |
1560 | 527fbde8 | Michael Hanselmann | } |
1561 | 527fbde8 | Michael Hanselmann | |
1562 | c91407bc | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups, [], {}, data, clfactory) |
1563 | c91407bc | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.POST)
|
1564 | c91407bc | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1565 | 527fbde8 | Michael Hanselmann | |
1566 | 527fbde8 | Michael Hanselmann | def testDefaults(self): |
1567 | c91407bc | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1568 | c91407bc | Michael Hanselmann | |
1569 | 527fbde8 | Michael Hanselmann | name = "group15395"
|
1570 | 527fbde8 | Michael Hanselmann | data = { |
1571 | 527fbde8 | Michael Hanselmann | "group_name": name,
|
1572 | 527fbde8 | Michael Hanselmann | } |
1573 | 527fbde8 | Michael Hanselmann | |
1574 | c91407bc | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups, [], {}, data, clfactory) |
1575 | c91407bc | Michael Hanselmann | job_id = handler.POST() |
1576 | c91407bc | Michael Hanselmann | |
1577 | c91407bc | Michael Hanselmann | cl = clfactory.GetNextClient() |
1578 | c91407bc | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1579 | c91407bc | Michael Hanselmann | |
1580 | c91407bc | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1581 | c91407bc | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1582 | c91407bc | Michael Hanselmann | |
1583 | c91407bc | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupAdd)) |
1584 | 527fbde8 | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1585 | 527fbde8 | Michael Hanselmann | self.assertFalse(hasattr(op, "alloc_policy")) |
1586 | c91407bc | Michael Hanselmann | self.assertFalse(op.dry_run)
|
1587 | 527fbde8 | Michael Hanselmann | |
1588 | 527fbde8 | Michael Hanselmann | def testLegacyName(self): |
1589 | c91407bc | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1590 | c91407bc | Michael Hanselmann | |
1591 | 527fbde8 | Michael Hanselmann | name = "group29852"
|
1592 | 527fbde8 | Michael Hanselmann | data = { |
1593 | 527fbde8 | Michael Hanselmann | "name": name,
|
1594 | 527fbde8 | Michael Hanselmann | } |
1595 | 527fbde8 | Michael Hanselmann | |
1596 | c91407bc | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_groups, [], { |
1597 | c91407bc | Michael Hanselmann | "dry-run": ["1"], |
1598 | c91407bc | Michael Hanselmann | }, data, clfactory) |
1599 | c91407bc | Michael Hanselmann | job_id = handler.POST() |
1600 | c91407bc | Michael Hanselmann | |
1601 | c91407bc | Michael Hanselmann | cl = clfactory.GetNextClient() |
1602 | c91407bc | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1603 | c91407bc | Michael Hanselmann | |
1604 | c91407bc | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1605 | c91407bc | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1606 | c91407bc | Michael Hanselmann | |
1607 | c91407bc | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpGroupAdd)) |
1608 | 527fbde8 | Michael Hanselmann | self.assertEqual(op.group_name, name)
|
1609 | c91407bc | Michael Hanselmann | self.assertFalse(hasattr(op, "alloc_policy")) |
1610 | c91407bc | Michael Hanselmann | self.assertTrue(op.dry_run)
|
1611 | 527fbde8 | Michael Hanselmann | |
1612 | 527fbde8 | Michael Hanselmann | |
1613 | 51cc8637 | Michael Hanselmann | class TestNodeRole(unittest.TestCase): |
1614 | 51cc8637 | Michael Hanselmann | def test(self): |
1615 | 51cc8637 | Michael Hanselmann | clfactory = _FakeClientFactory(_FakeClient) |
1616 | 51cc8637 | Michael Hanselmann | |
1617 | 51cc8637 | Michael Hanselmann | for role in rlib2._NR_MAP.values(): |
1618 | 51cc8637 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_nodes_name_role, |
1619 | 51cc8637 | Michael Hanselmann | ["node-z"], {}, role, clfactory)
|
1620 | 51cc8637 | Michael Hanselmann | if role == rlib2._NR_MASTER:
|
1621 | 51cc8637 | Michael Hanselmann | self.assertRaises(http.HttpBadRequest, handler.PUT)
|
1622 | 51cc8637 | Michael Hanselmann | else:
|
1623 | 51cc8637 | Michael Hanselmann | job_id = handler.PUT() |
1624 | 51cc8637 | Michael Hanselmann | |
1625 | 51cc8637 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1626 | 51cc8637 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1627 | 51cc8637 | Michael Hanselmann | |
1628 | 51cc8637 | Michael Hanselmann | (exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
1629 | 51cc8637 | Michael Hanselmann | self.assertEqual(job_id, exp_job_id)
|
1630 | 51cc8637 | Michael Hanselmann | self.assertTrue(isinstance(op, opcodes.OpNodeSetParams)) |
1631 | 51cc8637 | Michael Hanselmann | self.assertEqual(op.node_name, "node-z") |
1632 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.force)
|
1633 | 51cc8637 | Michael Hanselmann | self.assertFalse(hasattr(op, "dry_run")) |
1634 | 51cc8637 | Michael Hanselmann | |
1635 | 51cc8637 | Michael Hanselmann | if role == rlib2._NR_REGULAR:
|
1636 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.drained)
|
1637 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.offline)
|
1638 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.master_candidate)
|
1639 | 51cc8637 | Michael Hanselmann | elif role == rlib2._NR_MASTER_CANDIDATE:
|
1640 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.drained)
|
1641 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.offline)
|
1642 | 51cc8637 | Michael Hanselmann | self.assertTrue(op.master_candidate)
|
1643 | 51cc8637 | Michael Hanselmann | elif role == rlib2._NR_DRAINED:
|
1644 | 51cc8637 | Michael Hanselmann | self.assertTrue(op.drained)
|
1645 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.offline)
|
1646 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.master_candidate)
|
1647 | 51cc8637 | Michael Hanselmann | elif role == rlib2._NR_OFFLINE:
|
1648 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.drained)
|
1649 | 51cc8637 | Michael Hanselmann | self.assertTrue(op.offline)
|
1650 | 51cc8637 | Michael Hanselmann | self.assertFalse(op.master_candidate)
|
1651 | 51cc8637 | Michael Hanselmann | else:
|
1652 | 51cc8637 | Michael Hanselmann | self.fail("Unknown role '%s'" % role) |
1653 | 51cc8637 | Michael Hanselmann | |
1654 | 51cc8637 | Michael Hanselmann | self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
1655 | 51cc8637 | Michael Hanselmann | |
1656 | 51cc8637 | Michael Hanselmann | |
1657 | 3429bc89 | Michael Hanselmann | class TestSimpleResources(unittest.TestCase): |
1658 | 3429bc89 | Michael Hanselmann | def setUp(self): |
1659 | 3429bc89 | Michael Hanselmann | self.clfactory = _FakeClientFactory(_FakeClient)
|
1660 | 3429bc89 | Michael Hanselmann | |
1661 | 3429bc89 | Michael Hanselmann | def tearDown(self): |
1662 | 3429bc89 | Michael Hanselmann | self.assertRaises(IndexError, self.clfactory.GetNextClient) |
1663 | 3429bc89 | Michael Hanselmann | |
1664 | 3429bc89 | Michael Hanselmann | def testFeatures(self): |
1665 | 3429bc89 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_features, [], {}, None, self.clfactory) |
1666 | 3429bc89 | Michael Hanselmann | self.assertEqual(set(handler.GET()), rlib2.ALL_FEATURES) |
1667 | 3429bc89 | Michael Hanselmann | |
1668 | 132cdb87 | Michael Hanselmann | def testEmpty(self): |
1669 | 132cdb87 | Michael Hanselmann | for cls in [rlib2.R_root, rlib2.R_2]: |
1670 | 132cdb87 | Michael Hanselmann | handler = _CreateHandler(cls, [], {}, None, self.clfactory) |
1671 | 132cdb87 | Michael Hanselmann | self.assertTrue(handler.GET() is None) |
1672 | 3429bc89 | Michael Hanselmann | |
1673 | 3429bc89 | Michael Hanselmann | def testVersion(self): |
1674 | 3429bc89 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_version, [], {}, None, self.clfactory) |
1675 | 3429bc89 | Michael Hanselmann | self.assertEqual(handler.GET(), constants.RAPI_VERSION)
|
1676 | 3429bc89 | Michael Hanselmann | |
1677 | 3429bc89 | Michael Hanselmann | |
1678 | f75ab789 | Michael Hanselmann | class TestClusterInfo(unittest.TestCase): |
1679 | f75ab789 | Michael Hanselmann | class _ClusterInfoClient: |
1680 | f75ab789 | Michael Hanselmann | def __init__(self): |
1681 | f75ab789 | Michael Hanselmann | self.cluster_info = None |
1682 | f75ab789 | Michael Hanselmann | |
1683 | f75ab789 | Michael Hanselmann | def QueryClusterInfo(self): |
1684 | f75ab789 | Michael Hanselmann | assert self.cluster_info is None |
1685 | f75ab789 | Michael Hanselmann | self.cluster_info = object() |
1686 | f75ab789 | Michael Hanselmann | return self.cluster_info |
1687 | f75ab789 | Michael Hanselmann | |
1688 | f75ab789 | Michael Hanselmann | def test(self): |
1689 | f75ab789 | Michael Hanselmann | clfactory = _FakeClientFactory(self._ClusterInfoClient)
|
1690 | f75ab789 | Michael Hanselmann | handler = _CreateHandler(rlib2.R_2_info, [], {}, None, clfactory)
|
1691 | f75ab789 | Michael Hanselmann | result = handler.GET() |
1692 | f75ab789 | Michael Hanselmann | cl = clfactory.GetNextClient() |
1693 | f75ab789 | Michael Hanselmann | self.assertRaises(IndexError, clfactory.GetNextClient) |
1694 | f75ab789 | Michael Hanselmann | self.assertEqual(result, cl.cluster_info)
|
1695 | f75ab789 | Michael Hanselmann | |
1696 | f75ab789 | Michael Hanselmann | |
1697 | 6395cebb | Michael Hanselmann | if __name__ == '__main__': |
1698 | 6395cebb | Michael Hanselmann | testutils.GanetiTestProgram() |