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