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