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