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