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