root / qa / qa_rapi.py @ a07ae57f
History | View | Annotate | Download (28.9 kB)
1 | a47f574c | Oleksiy Mishchenko | #
|
---|---|---|---|
2 | fd7b69c0 | Michael Hanselmann | #
|
3 | a47f574c | Oleksiy Mishchenko | |
4 | 906a0346 | Bernardo Dal Seno | # Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
5 | a47f574c | Oleksiy Mishchenko | #
|
6 | a47f574c | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify
|
7 | a47f574c | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by
|
8 | a47f574c | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or
|
9 | a47f574c | Oleksiy Mishchenko | # (at your option) any later version.
|
10 | a47f574c | Oleksiy Mishchenko | #
|
11 | a47f574c | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but
|
12 | a47f574c | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a47f574c | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a47f574c | Oleksiy Mishchenko | # General Public License for more details.
|
15 | a47f574c | Oleksiy Mishchenko | #
|
16 | a47f574c | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License
|
17 | a47f574c | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software
|
18 | a47f574c | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a47f574c | Oleksiy Mishchenko | # 02110-1301, USA.
|
20 | a47f574c | Oleksiy Mishchenko | |
21 | a47f574c | Oleksiy Mishchenko | |
22 | a47f574c | Oleksiy Mishchenko | """Remote API QA tests.
|
23 | a47f574c | Oleksiy Mishchenko |
|
24 | a47f574c | Oleksiy Mishchenko | """
|
25 | a47f574c | Oleksiy Mishchenko | |
26 | c1513c7f | Michael Hanselmann | import itertools |
27 | 2ee9171a | Hrvoje Ribicic | import functools |
28 | 6b924ca3 | Hrvoje Ribicic | import random |
29 | 6b924ca3 | Hrvoje Ribicic | import re |
30 | 6b924ca3 | Hrvoje Ribicic | import tempfile |
31 | a47f574c | Oleksiy Mishchenko | |
32 | 6b924ca3 | Hrvoje Ribicic | from ganeti import cli |
33 | 6b924ca3 | Hrvoje Ribicic | from ganeti import compat |
34 | a47f574c | Oleksiy Mishchenko | from ganeti import constants |
35 | a47f574c | Oleksiy Mishchenko | from ganeti import errors |
36 | 6b924ca3 | Hrvoje Ribicic | from ganeti import locking |
37 | 6b924ca3 | Hrvoje Ribicic | from ganeti import pathutils |
38 | b82d4c5e | Michael Hanselmann | from ganeti import objects |
39 | 4fab7cab | Michael Hanselmann | from ganeti import qlang |
40 | 6b924ca3 | Hrvoje Ribicic | from ganeti import query |
41 | 6b924ca3 | Hrvoje Ribicic | from ganeti import rapi |
42 | 6b924ca3 | Hrvoje Ribicic | from ganeti import utils |
43 | 2771835c | Michael Hanselmann | |
44 | fcd2359a | Hrvoje Ribicic | from ganeti.http.auth import ParsePasswordFile |
45 | b459a848 | Andrea Spadaccini | import ganeti.rapi.client # pylint: disable=W0611 |
46 | 2771835c | Michael Hanselmann | import ganeti.rapi.client_utils |
47 | a47f574c | Oleksiy Mishchenko | |
48 | a47f574c | Oleksiy Mishchenko | import qa_config |
49 | a47f574c | Oleksiy Mishchenko | import qa_error |
50 | 6b924ca3 | Hrvoje Ribicic | import qa_utils |
51 | a47f574c | Oleksiy Mishchenko | |
52 | 6b924ca3 | Hrvoje Ribicic | from qa_instance import IsDiskReplacingSupported |
53 | 5de31440 | Bernardo Dal Seno | from qa_instance import IsFailoverSupported |
54 | 5de31440 | Bernardo Dal Seno | from qa_instance import IsMigrationSupported |
55 | 343c9ed2 | Hrvoje Ribicic | from qa_job_utils import RunWithLocks |
56 | 3582eef6 | Iustin Pop | from qa_utils import (AssertEqual, AssertIn, AssertMatch, StartLocalCommand) |
57 | 5fa0375e | Michael Hanselmann | from qa_utils import InstanceCheck, INST_DOWN, INST_UP, FIRST_ARG |
58 | a47f574c | Oleksiy Mishchenko | |
59 | a47f574c | Oleksiy Mishchenko | |
60 | 2771835c | Michael Hanselmann | _rapi_ca = None
|
61 | 2771835c | Michael Hanselmann | _rapi_client = None
|
62 | 5d831182 | Michael Hanselmann | _rapi_username = None
|
63 | 5d831182 | Michael Hanselmann | _rapi_password = None
|
64 | e6ce18ac | René Nussbaumer | |
65 | e6ce18ac | René Nussbaumer | |
66 | 2771835c | Michael Hanselmann | def Setup(username, password): |
67 | 2771835c | Michael Hanselmann | """Configures the RAPI client.
|
68 | 725ec2f1 | René Nussbaumer |
|
69 | 2771835c | Michael Hanselmann | """
|
70 | b459a848 | Andrea Spadaccini | # pylint: disable=W0603
|
71 | 3582eef6 | Iustin Pop | # due to global usage
|
72 | 2771835c | Michael Hanselmann | global _rapi_ca
|
73 | 2771835c | Michael Hanselmann | global _rapi_client
|
74 | 5d831182 | Michael Hanselmann | global _rapi_username
|
75 | 5d831182 | Michael Hanselmann | global _rapi_password
|
76 | 5d831182 | Michael Hanselmann | |
77 | 5d831182 | Michael Hanselmann | _rapi_username = username |
78 | 5d831182 | Michael Hanselmann | _rapi_password = password |
79 | e6ce18ac | René Nussbaumer | |
80 | 2771835c | Michael Hanselmann | master = qa_config.GetMasterNode() |
81 | e6ce18ac | René Nussbaumer | |
82 | 2771835c | Michael Hanselmann | # Load RAPI certificate from master node
|
83 | dcd85eef | Michael Hanselmann | cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_CERT_FILE)]
|
84 | e6ce18ac | René Nussbaumer | |
85 | 2771835c | Michael Hanselmann | # Write to temporary file
|
86 | 2771835c | Michael Hanselmann | _rapi_ca = tempfile.NamedTemporaryFile() |
87 | aecba21e | Michael Hanselmann | _rapi_ca.write(qa_utils.GetCommandOutput(master.primary, |
88 | 2771835c | Michael Hanselmann | utils.ShellQuoteArgs(cmd))) |
89 | 2771835c | Michael Hanselmann | _rapi_ca.flush() |
90 | e6ce18ac | René Nussbaumer | |
91 | 2771835c | Michael Hanselmann | port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
|
92 | 2a7c3583 | Michael Hanselmann | cfg_curl = rapi.client.GenericCurlConfig(cafile=_rapi_ca.name, |
93 | 2a7c3583 | Michael Hanselmann | proxy="")
|
94 | e6ce18ac | René Nussbaumer | |
95 | 301adaae | Michael Hanselmann | if qa_config.UseVirtualCluster():
|
96 | 301adaae | Michael Hanselmann | # TODO: Implement full support for RAPI on virtual clusters
|
97 | 301adaae | Michael Hanselmann | print qa_utils.FormatWarning("RAPI tests are not yet supported on" |
98 | 301adaae | Michael Hanselmann | " virtual clusters and will be disabled")
|
99 | e6ce18ac | René Nussbaumer | |
100 | 301adaae | Michael Hanselmann | assert _rapi_client is None |
101 | 301adaae | Michael Hanselmann | else:
|
102 | 301adaae | Michael Hanselmann | _rapi_client = rapi.client.GanetiRapiClient(master.primary, port=port, |
103 | 301adaae | Michael Hanselmann | username=username, |
104 | 301adaae | Michael Hanselmann | password=password, |
105 | 301adaae | Michael Hanselmann | curl_config_fn=cfg_curl) |
106 | 301adaae | Michael Hanselmann | |
107 | 301adaae | Michael Hanselmann | print "RAPI protocol version: %s" % _rapi_client.GetVersion() |
108 | a47f574c | Oleksiy Mishchenko | |
109 | a784d28c | Hrvoje Ribicic | return _rapi_client
|
110 | a784d28c | Hrvoje Ribicic | |
111 | a47f574c | Oleksiy Mishchenko | |
112 | fcd2359a | Hrvoje Ribicic | def LookupRapiSecret(rapi_user): |
113 | fcd2359a | Hrvoje Ribicic | """Find the RAPI secret for the given user.
|
114 | fcd2359a | Hrvoje Ribicic |
|
115 | fcd2359a | Hrvoje Ribicic | @param rapi_user: Login user
|
116 | fcd2359a | Hrvoje Ribicic | @return: Login secret for the user
|
117 | fcd2359a | Hrvoje Ribicic |
|
118 | fcd2359a | Hrvoje Ribicic | """
|
119 | fcd2359a | Hrvoje Ribicic | CTEXT = "{CLEARTEXT}"
|
120 | fcd2359a | Hrvoje Ribicic | master = qa_config.GetMasterNode() |
121 | fcd2359a | Hrvoje Ribicic | cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
|
122 | fcd2359a | Hrvoje Ribicic | file_content = qa_utils.GetCommandOutput(master.primary, |
123 | fcd2359a | Hrvoje Ribicic | utils.ShellQuoteArgs(cmd)) |
124 | fcd2359a | Hrvoje Ribicic | users = ParsePasswordFile(file_content) |
125 | fcd2359a | Hrvoje Ribicic | entry = users.get(rapi_user) |
126 | fcd2359a | Hrvoje Ribicic | if not entry: |
127 | fcd2359a | Hrvoje Ribicic | raise qa_error.Error("User %s not found in RAPI users file" % rapi_user) |
128 | fcd2359a | Hrvoje Ribicic | secret = entry.password |
129 | fcd2359a | Hrvoje Ribicic | if secret.upper().startswith(CTEXT):
|
130 | fcd2359a | Hrvoje Ribicic | secret = secret[len(CTEXT):]
|
131 | fcd2359a | Hrvoje Ribicic | elif secret.startswith("{"): |
132 | fcd2359a | Hrvoje Ribicic | raise qa_error.Error("Unsupported password schema for RAPI user %s:" |
133 | fcd2359a | Hrvoje Ribicic | " not a clear text password" % rapi_user)
|
134 | fcd2359a | Hrvoje Ribicic | return secret
|
135 | fcd2359a | Hrvoje Ribicic | |
136 | fcd2359a | Hrvoje Ribicic | |
137 | a47f574c | Oleksiy Mishchenko | INSTANCE_FIELDS = ("name", "os", "pnode", "snodes", |
138 | a5b9d725 | Iustin Pop | "admin_state",
|
139 | 0e514de1 | Bernardo Dal Seno | "disk_template", "disk.sizes", "disk.spindles", |
140 | 22482387 | Iustin Pop | "nic.ips", "nic.macs", "nic.modes", "nic.links", |
141 | a5b9d725 | Iustin Pop | "beparams", "hvparams", |
142 | 4ea3de4e | Balazs Lecz | "oper_state", "oper_ram", "oper_vcpus", "status", "tags") |
143 | a47f574c | Oleksiy Mishchenko | |
144 | 06fb92cf | Bernardo Dal Seno | NODE_FIELDS = ("name", "dtotal", "dfree", "sptotal", "spfree", |
145 | a47f574c | Oleksiy Mishchenko | "mtotal", "mnode", "mfree", |
146 | a47f574c | Oleksiy Mishchenko | "pinst_cnt", "sinst_cnt", "tags") |
147 | a47f574c | Oleksiy Mishchenko | |
148 | b8028dcf | Michael Hanselmann | GROUP_FIELDS = compat.UniqueFrozenset([ |
149 | 30131294 | Adeodato Simo | "name", "uuid", |
150 | 90e99856 | Adeodato Simo | "alloc_policy",
|
151 | 30131294 | Adeodato Simo | "node_cnt", "node_list", |
152 | 30131294 | Adeodato Simo | ]) |
153 | 30131294 | Adeodato Simo | |
154 | b8028dcf | Michael Hanselmann | JOB_FIELDS = compat.UniqueFrozenset([ |
155 | 94e63ca1 | Michael Hanselmann | "id", "ops", "status", "summary", |
156 | 94e63ca1 | Michael Hanselmann | "opstatus", "opresult", "oplog", |
157 | 94e63ca1 | Michael Hanselmann | "received_ts", "start_ts", "end_ts", |
158 | 94e63ca1 | Michael Hanselmann | ]) |
159 | 94e63ca1 | Michael Hanselmann | |
160 | 68289c75 | Iustin Pop | LIST_FIELDS = ("id", "uri") |
161 | a47f574c | Oleksiy Mishchenko | |
162 | a47f574c | Oleksiy Mishchenko | |
163 | a47f574c | Oleksiy Mishchenko | def Enabled(): |
164 | a47f574c | Oleksiy Mishchenko | """Return whether remote API tests should be run.
|
165 | a47f574c | Oleksiy Mishchenko |
|
166 | a47f574c | Oleksiy Mishchenko | """
|
167 | 301adaae | Michael Hanselmann | # TODO: Implement RAPI tests for virtual clusters
|
168 | 301adaae | Michael Hanselmann | return (qa_config.TestEnabled("rapi") and |
169 | 301adaae | Michael Hanselmann | not qa_config.UseVirtualCluster())
|
170 | a47f574c | Oleksiy Mishchenko | |
171 | a47f574c | Oleksiy Mishchenko | |
172 | a47f574c | Oleksiy Mishchenko | def _DoTests(uris): |
173 | b459a848 | Andrea Spadaccini | # pylint: disable=W0212
|
174 | 3582eef6 | Iustin Pop | # due to _SendRequest usage
|
175 | 94e63ca1 | Michael Hanselmann | results = [] |
176 | a47f574c | Oleksiy Mishchenko | |
177 | 94e63ca1 | Michael Hanselmann | for uri, verify, method, body in uris: |
178 | a47f574c | Oleksiy Mishchenko | assert uri.startswith("/") |
179 | a47f574c | Oleksiy Mishchenko | |
180 | c326b4ef | Michael Hanselmann | print "%s %s" % (method, uri) |
181 | 2771835c | Michael Hanselmann | data = _rapi_client._SendRequest(method, uri, None, body)
|
182 | a47f574c | Oleksiy Mishchenko | |
183 | a47f574c | Oleksiy Mishchenko | if verify is not None: |
184 | a47f574c | Oleksiy Mishchenko | if callable(verify): |
185 | a47f574c | Oleksiy Mishchenko | verify(data) |
186 | a47f574c | Oleksiy Mishchenko | else:
|
187 | a47f574c | Oleksiy Mishchenko | AssertEqual(data, verify) |
188 | a47f574c | Oleksiy Mishchenko | |
189 | fd837171 | Michael Hanselmann | results.append(data) |
190 | 94e63ca1 | Michael Hanselmann | |
191 | 94e63ca1 | Michael Hanselmann | return results
|
192 | 94e63ca1 | Michael Hanselmann | |
193 | 94e63ca1 | Michael Hanselmann | |
194 | 94e63ca1 | Michael Hanselmann | def _VerifyReturnsJob(data): |
195 | 76b62028 | Iustin Pop | if not isinstance(data, int): |
196 | 76b62028 | Iustin Pop | AssertMatch(data, r"^\d+$")
|
197 | 94e63ca1 | Michael Hanselmann | |
198 | a47f574c | Oleksiy Mishchenko | |
199 | a47f574c | Oleksiy Mishchenko | def TestVersion(): |
200 | a47f574c | Oleksiy Mishchenko | """Testing remote API version.
|
201 | a47f574c | Oleksiy Mishchenko |
|
202 | a47f574c | Oleksiy Mishchenko | """
|
203 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
204 | d0c8c01d | Iustin Pop | ("/version", constants.RAPI_VERSION, "GET", None), |
205 | a47f574c | Oleksiy Mishchenko | ]) |
206 | a47f574c | Oleksiy Mishchenko | |
207 | a47f574c | Oleksiy Mishchenko | |
208 | a47f574c | Oleksiy Mishchenko | def TestEmptyCluster(): |
209 | a47f574c | Oleksiy Mishchenko | """Testing remote API on an empty cluster.
|
210 | a47f574c | Oleksiy Mishchenko |
|
211 | a47f574c | Oleksiy Mishchenko | """
|
212 | 94e63ca1 | Michael Hanselmann | master = qa_config.GetMasterNode() |
213 | 94e63ca1 | Michael Hanselmann | master_full = qa_utils.ResolveNodeName(master) |
214 | a47f574c | Oleksiy Mishchenko | |
215 | a47f574c | Oleksiy Mishchenko | def _VerifyInfo(data): |
216 | a47f574c | Oleksiy Mishchenko | AssertIn("name", data)
|
217 | a47f574c | Oleksiy Mishchenko | AssertIn("master", data)
|
218 | 94e63ca1 | Michael Hanselmann | AssertEqual(data["master"], master_full)
|
219 | a47f574c | Oleksiy Mishchenko | |
220 | a47f574c | Oleksiy Mishchenko | def _VerifyNodes(data): |
221 | a47f574c | Oleksiy Mishchenko | master_entry = { |
222 | 94e63ca1 | Michael Hanselmann | "id": master_full,
|
223 | 94e63ca1 | Michael Hanselmann | "uri": "/2/nodes/%s" % master_full, |
224 | a47f574c | Oleksiy Mishchenko | } |
225 | a47f574c | Oleksiy Mishchenko | AssertIn(master_entry, data) |
226 | a47f574c | Oleksiy Mishchenko | |
227 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
228 | a47f574c | Oleksiy Mishchenko | for node in data: |
229 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
230 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
231 | a47f574c | Oleksiy Mishchenko | |
232 | 30131294 | Adeodato Simo | def _VerifyGroups(data): |
233 | 30131294 | Adeodato Simo | default_group = { |
234 | 75cf411a | Adeodato Simo | "name": constants.INITIAL_NODE_GROUP_NAME,
|
235 | 75cf411a | Adeodato Simo | "uri": "/2/groups/" + constants.INITIAL_NODE_GROUP_NAME, |
236 | 30131294 | Adeodato Simo | } |
237 | 30131294 | Adeodato Simo | AssertIn(default_group, data) |
238 | 30131294 | Adeodato Simo | |
239 | 30131294 | Adeodato Simo | def _VerifyGroupsBulk(data): |
240 | 30131294 | Adeodato Simo | for group in data: |
241 | 30131294 | Adeodato Simo | for field in GROUP_FIELDS: |
242 | 30131294 | Adeodato Simo | AssertIn(field, group) |
243 | 30131294 | Adeodato Simo | |
244 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
245 | d0c8c01d | Iustin Pop | ("/", None, "GET", None), |
246 | d0c8c01d | Iustin Pop | ("/2/info", _VerifyInfo, "GET", None), |
247 | d0c8c01d | Iustin Pop | ("/2/tags", None, "GET", None), |
248 | d0c8c01d | Iustin Pop | ("/2/nodes", _VerifyNodes, "GET", None), |
249 | d0c8c01d | Iustin Pop | ("/2/nodes?bulk=1", _VerifyNodesBulk, "GET", None), |
250 | d0c8c01d | Iustin Pop | ("/2/groups", _VerifyGroups, "GET", None), |
251 | d0c8c01d | Iustin Pop | ("/2/groups?bulk=1", _VerifyGroupsBulk, "GET", None), |
252 | d0c8c01d | Iustin Pop | ("/2/instances", [], "GET", None), |
253 | d0c8c01d | Iustin Pop | ("/2/instances?bulk=1", [], "GET", None), |
254 | d0c8c01d | Iustin Pop | ("/2/os", None, "GET", None), |
255 | a47f574c | Oleksiy Mishchenko | ]) |
256 | a47f574c | Oleksiy Mishchenko | |
257 | 4d2bd00a | Michael Hanselmann | # Test HTTP Not Found
|
258 | 4d2bd00a | Michael Hanselmann | for method in ["GET", "PUT", "POST", "DELETE"]: |
259 | 4d2bd00a | Michael Hanselmann | try:
|
260 | 4d2bd00a | Michael Hanselmann | _DoTests([("/99/resource/not/here/99", None, method, None)]) |
261 | 4d2bd00a | Michael Hanselmann | except rapi.client.GanetiApiError, err:
|
262 | 4d2bd00a | Michael Hanselmann | AssertEqual(err.code, 404)
|
263 | 4d2bd00a | Michael Hanselmann | else:
|
264 | 4d2bd00a | Michael Hanselmann | raise qa_error.Error("Non-existent resource didn't return HTTP 404") |
265 | 4d2bd00a | Michael Hanselmann | |
266 | 4d2bd00a | Michael Hanselmann | # Test HTTP Not Implemented
|
267 | 4d2bd00a | Michael Hanselmann | for method in ["PUT", "POST", "DELETE"]: |
268 | 4d2bd00a | Michael Hanselmann | try:
|
269 | 4d2bd00a | Michael Hanselmann | _DoTests([("/version", None, method, None)]) |
270 | 4d2bd00a | Michael Hanselmann | except rapi.client.GanetiApiError, err:
|
271 | 4d2bd00a | Michael Hanselmann | AssertEqual(err.code, 501)
|
272 | 4d2bd00a | Michael Hanselmann | else:
|
273 | 4d2bd00a | Michael Hanselmann | raise qa_error.Error("Non-implemented method didn't fail") |
274 | 4d2bd00a | Michael Hanselmann | |
275 | a47f574c | Oleksiy Mishchenko | |
276 | 4fab7cab | Michael Hanselmann | def TestRapiQuery(): |
277 | 4fab7cab | Michael Hanselmann | """Testing resource queries via remote API.
|
278 | 4fab7cab | Michael Hanselmann |
|
279 | 4fab7cab | Michael Hanselmann | """
|
280 | bab4f56a | Helga Velroyen | # FIXME: the tests are failing if no LVM is enabled, investigate
|
281 | bab4f56a | Helga Velroyen | # if it is a bug in the QA or in the code
|
282 | bab4f56a | Helga Velroyen | if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG): |
283 | bab4f56a | Helga Velroyen | return
|
284 | bab4f56a | Helga Velroyen | |
285 | 4fab7cab | Michael Hanselmann | master_name = qa_utils.ResolveNodeName(qa_config.GetMasterNode()) |
286 | 4fab7cab | Michael Hanselmann | rnd = random.Random(7818)
|
287 | 4fab7cab | Michael Hanselmann | |
288 | 4fab7cab | Michael Hanselmann | for what in constants.QR_VIA_RAPI: |
289 | 4faa4861 | Iustin Pop | if what == constants.QR_JOB:
|
290 | 4faa4861 | Iustin Pop | namefield = "id"
|
291 | b5ae26cd | Klaus Aehlig | trivial_filter = [qlang.OP_GE, namefield, 0]
|
292 | 496d5ac8 | Michael Hanselmann | elif what == constants.QR_EXPORT:
|
293 | 496d5ac8 | Michael Hanselmann | namefield = "export"
|
294 | b5ae26cd | Klaus Aehlig | trivial_filter = [qlang.OP_REGEXP, ".*", namefield]
|
295 | 4faa4861 | Iustin Pop | else:
|
296 | 4faa4861 | Iustin Pop | namefield = "name"
|
297 | b5ae26cd | Klaus Aehlig | trivial_filter = [qlang.OP_REGEXP, ".*", namefield]
|
298 | 4faa4861 | Iustin Pop | |
299 | 4fab7cab | Michael Hanselmann | all_fields = query.ALL_FIELDS[what].keys() |
300 | 4fab7cab | Michael Hanselmann | rnd.shuffle(all_fields) |
301 | 4fab7cab | Michael Hanselmann | |
302 | 4fab7cab | Michael Hanselmann | # No fields, should return everything
|
303 | 4fab7cab | Michael Hanselmann | result = _rapi_client.QueryFields(what) |
304 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryFieldsResponse.FromDict(result) |
305 | 4fab7cab | Michael Hanselmann | AssertEqual(len(qresult.fields), len(all_fields)) |
306 | 4fab7cab | Michael Hanselmann | |
307 | 4fab7cab | Michael Hanselmann | # One field
|
308 | 4faa4861 | Iustin Pop | result = _rapi_client.QueryFields(what, fields=[namefield]) |
309 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryFieldsResponse.FromDict(result) |
310 | 4fab7cab | Michael Hanselmann | AssertEqual(len(qresult.fields), 1) |
311 | 4fab7cab | Michael Hanselmann | |
312 | 4fab7cab | Michael Hanselmann | # Specify all fields, order must be correct
|
313 | 4fab7cab | Michael Hanselmann | result = _rapi_client.QueryFields(what, fields=all_fields) |
314 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryFieldsResponse.FromDict(result) |
315 | 4fab7cab | Michael Hanselmann | AssertEqual(len(qresult.fields), len(all_fields)) |
316 | 4fab7cab | Michael Hanselmann | AssertEqual([fdef.name for fdef in qresult.fields], all_fields) |
317 | 4fab7cab | Michael Hanselmann | |
318 | 4fab7cab | Michael Hanselmann | # Unknown field
|
319 | 4fab7cab | Michael Hanselmann | result = _rapi_client.QueryFields(what, fields=["_unknown!"])
|
320 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryFieldsResponse.FromDict(result) |
321 | 4fab7cab | Michael Hanselmann | AssertEqual(len(qresult.fields), 1) |
322 | 4fab7cab | Michael Hanselmann | AssertEqual(qresult.fields[0].name, "_unknown!") |
323 | 4fab7cab | Michael Hanselmann | AssertEqual(qresult.fields[0].kind, constants.QFT_UNKNOWN)
|
324 | 4fab7cab | Michael Hanselmann | |
325 | 4fab7cab | Michael Hanselmann | # Try once more, this time without the client
|
326 | 4fab7cab | Michael Hanselmann | _DoTests([ |
327 | 4fab7cab | Michael Hanselmann | ("/2/query/%s/fields" % what, None, "GET", None), |
328 | 4fab7cab | Michael Hanselmann | ("/2/query/%s/fields?fields=name,name,%s" % (what, all_fields[0]), |
329 | 4fab7cab | Michael Hanselmann | None, "GET", None), |
330 | 4fab7cab | Michael Hanselmann | ]) |
331 | 4fab7cab | Michael Hanselmann | |
332 | 4fab7cab | Michael Hanselmann | # Try missing query argument
|
333 | 4fab7cab | Michael Hanselmann | try:
|
334 | 4fab7cab | Michael Hanselmann | _DoTests([ |
335 | 4fab7cab | Michael Hanselmann | ("/2/query/%s" % what, None, "GET", None), |
336 | 4fab7cab | Michael Hanselmann | ]) |
337 | 4fab7cab | Michael Hanselmann | except rapi.client.GanetiApiError, err:
|
338 | 4fab7cab | Michael Hanselmann | AssertEqual(err.code, 400)
|
339 | 4fab7cab | Michael Hanselmann | else:
|
340 | 4fab7cab | Michael Hanselmann | raise qa_error.Error("Request missing 'fields' parameter didn't fail") |
341 | 4fab7cab | Michael Hanselmann | |
342 | 4fab7cab | Michael Hanselmann | def _Check(exp_fields, data): |
343 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryResponse.FromDict(data) |
344 | 4fab7cab | Michael Hanselmann | AssertEqual([fdef.name for fdef in qresult.fields], exp_fields) |
345 | 4fab7cab | Michael Hanselmann | if not isinstance(qresult.data, list): |
346 | 4fab7cab | Michael Hanselmann | raise qa_error.Error("Query did not return a list") |
347 | 4fab7cab | Michael Hanselmann | |
348 | 4fab7cab | Michael Hanselmann | _DoTests([ |
349 | 4fab7cab | Michael Hanselmann | # Specify fields in query
|
350 | 4fab7cab | Michael Hanselmann | ("/2/query/%s?fields=%s" % (what, ",".join(all_fields)), |
351 | 4fab7cab | Michael Hanselmann | compat.partial(_Check, all_fields), "GET", None), |
352 | 4fab7cab | Michael Hanselmann | |
353 | 4faa4861 | Iustin Pop | ("/2/query/%s?fields=%s" % (what, namefield),
|
354 | 4faa4861 | Iustin Pop | compat.partial(_Check, [namefield]), "GET", None), |
355 | 4fab7cab | Michael Hanselmann | |
356 | 4fab7cab | Michael Hanselmann | # Note the spaces
|
357 | 4faa4861 | Iustin Pop | ("/2/query/%s?fields=%s,%%20%s%%09,%s%%20" %
|
358 | 4faa4861 | Iustin Pop | (what, namefield, namefield, namefield), |
359 | cfb3116d | Helga Velroyen | compat.partial(_Check, [namefield] * 3), "GET", None)]) |
360 | 4fab7cab | Michael Hanselmann | |
361 | cfb3116d | Helga Velroyen | if what in constants.QR_VIA_RAPI_PUT: |
362 | cfb3116d | Helga Velroyen | _DoTests([ |
363 | cfb3116d | Helga Velroyen | # PUT with fields in query
|
364 | cfb3116d | Helga Velroyen | ("/2/query/%s?fields=%s" % (what, namefield),
|
365 | cfb3116d | Helga Velroyen | compat.partial(_Check, [namefield]), "PUT", {}),
|
366 | 4fab7cab | Michael Hanselmann | |
367 | cfb3116d | Helga Velroyen | ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4), "PUT", { |
368 | cfb3116d | Helga Velroyen | "fields": [namefield] * 4, |
369 | cfb3116d | Helga Velroyen | }), |
370 | bab4f56a | Helga Velroyen | |
371 | cfb3116d | Helga Velroyen | ("/2/query/%s" % what, compat.partial(_Check, all_fields), "PUT", { |
372 | cfb3116d | Helga Velroyen | "fields": all_fields,
|
373 | cfb3116d | Helga Velroyen | }), |
374 | 4fab7cab | Michael Hanselmann | |
375 | cfb3116d | Helga Velroyen | ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4), "PUT", { |
376 | cfb3116d | Helga Velroyen | "fields": [namefield] * 4 |
377 | bab4f56a | Helga Velroyen | })]) |
378 | 4fab7cab | Michael Hanselmann | |
379 | 4fab7cab | Michael Hanselmann | def _CheckFilter(): |
380 | 4fab7cab | Michael Hanselmann | _DoTests([ |
381 | 4fab7cab | Michael Hanselmann | # With filter
|
382 | 4fab7cab | Michael Hanselmann | ("/2/query/%s" % what, compat.partial(_Check, all_fields), "PUT", { |
383 | 4fab7cab | Michael Hanselmann | "fields": all_fields,
|
384 | b5ae26cd | Klaus Aehlig | "filter": trivial_filter
|
385 | 4fab7cab | Michael Hanselmann | }), |
386 | 4fab7cab | Michael Hanselmann | ]) |
387 | 4fab7cab | Michael Hanselmann | |
388 | 4fab7cab | Michael Hanselmann | if what == constants.QR_LOCK:
|
389 | 4fab7cab | Michael Hanselmann | # Locks can't be filtered
|
390 | 4fab7cab | Michael Hanselmann | try:
|
391 | 4fab7cab | Michael Hanselmann | _CheckFilter() |
392 | 4fab7cab | Michael Hanselmann | except rapi.client.GanetiApiError, err:
|
393 | 4fab7cab | Michael Hanselmann | AssertEqual(err.code, 500)
|
394 | 4fab7cab | Michael Hanselmann | else:
|
395 | 4fab7cab | Michael Hanselmann | raise qa_error.Error("Filtering locks didn't fail") |
396 | 4fab7cab | Michael Hanselmann | else:
|
397 | cfb3116d | Helga Velroyen | if what in constants.QR_VIA_RAPI_PUT: |
398 | cfb3116d | Helga Velroyen | _CheckFilter() |
399 | 4fab7cab | Michael Hanselmann | |
400 | 4fab7cab | Michael Hanselmann | if what == constants.QR_NODE:
|
401 | 4fab7cab | Michael Hanselmann | # Test with filter
|
402 | 5ae4945a | Iustin Pop | (nodes, ) = _DoTests( |
403 | 5ae4945a | Iustin Pop | [("/2/query/%s" % what,
|
404 | 5ae4945a | Iustin Pop | compat.partial(_Check, ["name", "master"]), "PUT", |
405 | 5ae4945a | Iustin Pop | {"fields": ["name", "master"], |
406 | 5ae4945a | Iustin Pop | "filter": [qlang.OP_TRUE, "master"], |
407 | 5ae4945a | Iustin Pop | })]) |
408 | 4fab7cab | Michael Hanselmann | qresult = objects.QueryResponse.FromDict(nodes) |
409 | 4fab7cab | Michael Hanselmann | AssertEqual(qresult.data, [ |
410 | 4fab7cab | Michael Hanselmann | [[constants.RS_NORMAL, master_name], [constants.RS_NORMAL, True]],
|
411 | 4fab7cab | Michael Hanselmann | ]) |
412 | 4fab7cab | Michael Hanselmann | |
413 | 4fab7cab | Michael Hanselmann | |
414 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
415 | a47f574c | Oleksiy Mishchenko | def TestInstance(instance): |
416 | a47f574c | Oleksiy Mishchenko | """Testing getting instance(s) info via remote API.
|
417 | a47f574c | Oleksiy Mishchenko |
|
418 | a47f574c | Oleksiy Mishchenko | """
|
419 | a47f574c | Oleksiy Mishchenko | def _VerifyInstance(data): |
420 | a47f574c | Oleksiy Mishchenko | for entry in INSTANCE_FIELDS: |
421 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
422 | c85d3b64 | Michael Hanselmann | |
423 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesList(data): |
424 | a47f574c | Oleksiy Mishchenko | for instance in data: |
425 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
426 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, instance) |
427 | c85d3b64 | Michael Hanselmann | |
428 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesBulk(data): |
429 | a47f574c | Oleksiy Mishchenko | for instance_data in data: |
430 | a47f574c | Oleksiy Mishchenko | _VerifyInstance(instance_data) |
431 | a47f574c | Oleksiy Mishchenko | |
432 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
433 | b5f33afa | Michael Hanselmann | ("/2/instances/%s" % instance.name, _VerifyInstance, "GET", None), |
434 | d0c8c01d | Iustin Pop | ("/2/instances", _VerifyInstancesList, "GET", None), |
435 | d0c8c01d | Iustin Pop | ("/2/instances?bulk=1", _VerifyInstancesBulk, "GET", None), |
436 | b5f33afa | Michael Hanselmann | ("/2/instances/%s/activate-disks" % instance.name,
|
437 | d0c8c01d | Iustin Pop | _VerifyReturnsJob, "PUT", None), |
438 | b5f33afa | Michael Hanselmann | ("/2/instances/%s/deactivate-disks" % instance.name,
|
439 | d0c8c01d | Iustin Pop | _VerifyReturnsJob, "PUT", None), |
440 | a47f574c | Oleksiy Mishchenko | ]) |
441 | a47f574c | Oleksiy Mishchenko | |
442 | 71910715 | Iustin Pop | # Test OpBackupPrepare
|
443 | ebeb600f | Michael Hanselmann | (job_id, ) = _DoTests([ |
444 | ebeb600f | Michael Hanselmann | ("/2/instances/%s/prepare-export?mode=%s" %
|
445 | b5f33afa | Michael Hanselmann | (instance.name, constants.EXPORT_MODE_REMOTE), |
446 | ebeb600f | Michael Hanselmann | _VerifyReturnsJob, "PUT", None), |
447 | ebeb600f | Michael Hanselmann | ]) |
448 | ebeb600f | Michael Hanselmann | |
449 | ebeb600f | Michael Hanselmann | result = _WaitForRapiJob(job_id)[0]
|
450 | ebeb600f | Michael Hanselmann | AssertEqual(len(result["handshake"]), 3) |
451 | ebeb600f | Michael Hanselmann | AssertEqual(result["handshake"][0], constants.RIE_VERSION) |
452 | ebeb600f | Michael Hanselmann | AssertEqual(len(result["x509_key_name"]), 3) |
453 | ebeb600f | Michael Hanselmann | AssertIn("-----BEGIN CERTIFICATE-----", result["x509_ca"]) |
454 | ebeb600f | Michael Hanselmann | |
455 | a47f574c | Oleksiy Mishchenko | |
456 | a47f574c | Oleksiy Mishchenko | def TestNode(node): |
457 | a47f574c | Oleksiy Mishchenko | """Testing getting node(s) info via remote API.
|
458 | a47f574c | Oleksiy Mishchenko |
|
459 | a47f574c | Oleksiy Mishchenko | """
|
460 | a47f574c | Oleksiy Mishchenko | def _VerifyNode(data): |
461 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
462 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
463 | c85d3b64 | Michael Hanselmann | |
464 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesList(data): |
465 | a47f574c | Oleksiy Mishchenko | for node in data: |
466 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
467 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
468 | c85d3b64 | Michael Hanselmann | |
469 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
470 | a47f574c | Oleksiy Mishchenko | for node_data in data: |
471 | a47f574c | Oleksiy Mishchenko | _VerifyNode(node_data) |
472 | a47f574c | Oleksiy Mishchenko | |
473 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
474 | aecba21e | Michael Hanselmann | ("/2/nodes/%s" % node.primary, _VerifyNode, "GET", None), |
475 | d0c8c01d | Iustin Pop | ("/2/nodes", _VerifyNodesList, "GET", None), |
476 | d0c8c01d | Iustin Pop | ("/2/nodes?bulk=1", _VerifyNodesBulk, "GET", None), |
477 | a47f574c | Oleksiy Mishchenko | ]) |
478 | a47f574c | Oleksiy Mishchenko | |
479 | a47f574c | Oleksiy Mishchenko | |
480 | c1513c7f | Michael Hanselmann | def _FilterTags(seq): |
481 | c1513c7f | Michael Hanselmann | """Removes unwanted tags from a sequence.
|
482 | c1513c7f | Michael Hanselmann |
|
483 | c1513c7f | Michael Hanselmann | """
|
484 | c1513c7f | Michael Hanselmann | ignore_re = qa_config.get("ignore-tags-re", None) |
485 | c1513c7f | Michael Hanselmann | |
486 | c1513c7f | Michael Hanselmann | if ignore_re:
|
487 | c1513c7f | Michael Hanselmann | return itertools.ifilterfalse(re.compile(ignore_re).match, seq)
|
488 | c1513c7f | Michael Hanselmann | else:
|
489 | c1513c7f | Michael Hanselmann | return seq
|
490 | c1513c7f | Michael Hanselmann | |
491 | c1513c7f | Michael Hanselmann | |
492 | a47f574c | Oleksiy Mishchenko | def TestTags(kind, name, tags): |
493 | a47f574c | Oleksiy Mishchenko | """Tests .../tags resources.
|
494 | a47f574c | Oleksiy Mishchenko |
|
495 | a47f574c | Oleksiy Mishchenko | """
|
496 | a47f574c | Oleksiy Mishchenko | if kind == constants.TAG_CLUSTER:
|
497 | a5b9d725 | Iustin Pop | uri = "/2/tags"
|
498 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_NODE:
|
499 | a5b9d725 | Iustin Pop | uri = "/2/nodes/%s/tags" % name
|
500 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_INSTANCE:
|
501 | a5b9d725 | Iustin Pop | uri = "/2/instances/%s/tags" % name
|
502 | fe508a9d | Michael Hanselmann | elif kind == constants.TAG_NODEGROUP:
|
503 | fe508a9d | Michael Hanselmann | uri = "/2/groups/%s/tags" % name
|
504 | a4c589d2 | Hrvoje Ribicic | elif kind == constants.TAG_NETWORK:
|
505 | a4c589d2 | Hrvoje Ribicic | uri = "/2/networks/%s/tags" % name
|
506 | a47f574c | Oleksiy Mishchenko | else:
|
507 | a47f574c | Oleksiy Mishchenko | raise errors.ProgrammerError("Unknown tag kind") |
508 | a47f574c | Oleksiy Mishchenko | |
509 | a47f574c | Oleksiy Mishchenko | def _VerifyTags(data): |
510 | c1513c7f | Michael Hanselmann | AssertEqual(sorted(tags), sorted(_FilterTags(data))) |
511 | a47f574c | Oleksiy Mishchenko | |
512 | 4fab7cab | Michael Hanselmann | queryargs = "&".join("tag=%s" % i for i in tags) |
513 | c326b4ef | Michael Hanselmann | |
514 | c326b4ef | Michael Hanselmann | # Add tags
|
515 | c326b4ef | Michael Hanselmann | (job_id, ) = _DoTests([ |
516 | 4fab7cab | Michael Hanselmann | ("%s?%s" % (uri, queryargs), _VerifyReturnsJob, "PUT", None), |
517 | c326b4ef | Michael Hanselmann | ]) |
518 | c326b4ef | Michael Hanselmann | _WaitForRapiJob(job_id) |
519 | c326b4ef | Michael Hanselmann | |
520 | c326b4ef | Michael Hanselmann | # Retrieve tags
|
521 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
522 | d0c8c01d | Iustin Pop | (uri, _VerifyTags, "GET", None), |
523 | a47f574c | Oleksiy Mishchenko | ]) |
524 | 8cb70e56 | Michael Hanselmann | |
525 | c326b4ef | Michael Hanselmann | # Remove tags
|
526 | c326b4ef | Michael Hanselmann | (job_id, ) = _DoTests([ |
527 | 4fab7cab | Michael Hanselmann | ("%s?%s" % (uri, queryargs), _VerifyReturnsJob, "DELETE", None), |
528 | c326b4ef | Michael Hanselmann | ]) |
529 | c326b4ef | Michael Hanselmann | _WaitForRapiJob(job_id) |
530 | c326b4ef | Michael Hanselmann | |
531 | 8cb70e56 | Michael Hanselmann | |
532 | 8cb70e56 | Michael Hanselmann | def _WaitForRapiJob(job_id): |
533 | 8cb70e56 | Michael Hanselmann | """Waits for a job to finish.
|
534 | 8cb70e56 | Michael Hanselmann |
|
535 | 8cb70e56 | Michael Hanselmann | """
|
536 | 8cb70e56 | Michael Hanselmann | def _VerifyJob(data): |
537 | 8cb70e56 | Michael Hanselmann | AssertEqual(data["id"], job_id)
|
538 | 8cb70e56 | Michael Hanselmann | for field in JOB_FIELDS: |
539 | 8cb70e56 | Michael Hanselmann | AssertIn(field, data) |
540 | 8cb70e56 | Michael Hanselmann | |
541 | 8cb70e56 | Michael Hanselmann | _DoTests([ |
542 | 8cb70e56 | Michael Hanselmann | ("/2/jobs/%s" % job_id, _VerifyJob, "GET", None), |
543 | 8cb70e56 | Michael Hanselmann | ]) |
544 | 8cb70e56 | Michael Hanselmann | |
545 | ebeb600f | Michael Hanselmann | return rapi.client_utils.PollJob(_rapi_client, job_id,
|
546 | ebeb600f | Michael Hanselmann | cli.StdioJobPollReportCb()) |
547 | 8cb70e56 | Michael Hanselmann | |
548 | 8cb70e56 | Michael Hanselmann | |
549 | 4b10fb65 | Adeodato Simo | def TestRapiNodeGroups(): |
550 | 4b10fb65 | Adeodato Simo | """Test several node group operations using RAPI.
|
551 | 4b10fb65 | Adeodato Simo |
|
552 | 4b10fb65 | Adeodato Simo | """
|
553 | b4d2d2cb | Michael Hanselmann | (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
|
554 | 4b10fb65 | Adeodato Simo | |
555 | 4b10fb65 | Adeodato Simo | # Create a group with no attributes
|
556 | 4b10fb65 | Adeodato Simo | body = { |
557 | 4b10fb65 | Adeodato Simo | "name": group1,
|
558 | 4b10fb65 | Adeodato Simo | } |
559 | 4b10fb65 | Adeodato Simo | |
560 | 4b10fb65 | Adeodato Simo | (job_id, ) = _DoTests([ |
561 | 4b10fb65 | Adeodato Simo | ("/2/groups", _VerifyReturnsJob, "POST", body), |
562 | 4b10fb65 | Adeodato Simo | ]) |
563 | 4b10fb65 | Adeodato Simo | |
564 | 4b10fb65 | Adeodato Simo | _WaitForRapiJob(job_id) |
565 | 4b10fb65 | Adeodato Simo | |
566 | 4b10fb65 | Adeodato Simo | # Create a group specifying alloc_policy
|
567 | 4b10fb65 | Adeodato Simo | body = { |
568 | 4b10fb65 | Adeodato Simo | "name": group2,
|
569 | 4b10fb65 | Adeodato Simo | "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
|
570 | 4b10fb65 | Adeodato Simo | } |
571 | 4b10fb65 | Adeodato Simo | |
572 | 4b10fb65 | Adeodato Simo | (job_id, ) = _DoTests([ |
573 | 4b10fb65 | Adeodato Simo | ("/2/groups", _VerifyReturnsJob, "POST", body), |
574 | 4b10fb65 | Adeodato Simo | ]) |
575 | 4b10fb65 | Adeodato Simo | |
576 | 4b10fb65 | Adeodato Simo | _WaitForRapiJob(job_id) |
577 | 4b10fb65 | Adeodato Simo | |
578 | 4b10fb65 | Adeodato Simo | # Modify alloc_policy
|
579 | 4b10fb65 | Adeodato Simo | body = { |
580 | 4b10fb65 | Adeodato Simo | "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
|
581 | 4b10fb65 | Adeodato Simo | } |
582 | 4b10fb65 | Adeodato Simo | |
583 | 4b10fb65 | Adeodato Simo | (job_id, ) = _DoTests([ |
584 | 4b10fb65 | Adeodato Simo | ("/2/groups/%s/modify" % group1, _VerifyReturnsJob, "PUT", body), |
585 | 4b10fb65 | Adeodato Simo | ]) |
586 | 4b10fb65 | Adeodato Simo | |
587 | 4b10fb65 | Adeodato Simo | _WaitForRapiJob(job_id) |
588 | 4b10fb65 | Adeodato Simo | |
589 | 4b10fb65 | Adeodato Simo | # Rename a group
|
590 | 4b10fb65 | Adeodato Simo | body = { |
591 | 4b10fb65 | Adeodato Simo | "new_name": group3,
|
592 | 4b10fb65 | Adeodato Simo | } |
593 | 4b10fb65 | Adeodato Simo | |
594 | 4b10fb65 | Adeodato Simo | (job_id, ) = _DoTests([ |
595 | 4b10fb65 | Adeodato Simo | ("/2/groups/%s/rename" % group2, _VerifyReturnsJob, "PUT", body), |
596 | 4b10fb65 | Adeodato Simo | ]) |
597 | 4b10fb65 | Adeodato Simo | |
598 | 4b10fb65 | Adeodato Simo | _WaitForRapiJob(job_id) |
599 | 4b10fb65 | Adeodato Simo | |
600 | 4b10fb65 | Adeodato Simo | # Delete groups
|
601 | 4b10fb65 | Adeodato Simo | for group in [group1, group3]: |
602 | 4b10fb65 | Adeodato Simo | (job_id, ) = _DoTests([ |
603 | 4b10fb65 | Adeodato Simo | ("/2/groups/%s" % group, _VerifyReturnsJob, "DELETE", None), |
604 | 4b10fb65 | Adeodato Simo | ]) |
605 | 4b10fb65 | Adeodato Simo | |
606 | 4b10fb65 | Adeodato Simo | _WaitForRapiJob(job_id) |
607 | 4b10fb65 | Adeodato Simo | |
608 | 4b10fb65 | Adeodato Simo | |
609 | 924e95f9 | Michael Hanselmann | def TestRapiInstanceAdd(node, use_client): |
610 | 8cb70e56 | Michael Hanselmann | """Test adding a new instance via RAPI"""
|
611 | bab4f56a | Helga Velroyen | if not qa_config.IsTemplateSupported(constants.DT_PLAIN): |
612 | bab4f56a | Helga Velroyen | return
|
613 | 8cb70e56 | Michael Hanselmann | instance = qa_config.AcquireInstance() |
614 | 02a5fe0e | Michael Hanselmann | instance.SetDiskTemplate(constants.DT_PLAIN) |
615 | 8cb70e56 | Michael Hanselmann | try:
|
616 | 090128b6 | Christos Stavrakakis | disks = [{"size": utils.ParseUnit(d.get("size")), |
617 | 090128b6 | Christos Stavrakakis | "name": str(d.get("name"))} |
618 | 090128b6 | Christos Stavrakakis | for d in qa_config.GetDiskOptions()] |
619 | 0afce24e | Michael Hanselmann | nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
|
620 | f346a7d9 | Michael Hanselmann | nics = [{ |
621 | f346a7d9 | Michael Hanselmann | constants.INIC_MAC: nic0_mac, |
622 | f346a7d9 | Michael Hanselmann | }] |
623 | 924e95f9 | Michael Hanselmann | |
624 | 713a79e7 | Michael Hanselmann | beparams = { |
625 | 8ccbbe4b | Guido Trotter | constants.BE_MAXMEM: utils.ParseUnit(qa_config.get(constants.BE_MAXMEM)), |
626 | 8ccbbe4b | Guido Trotter | constants.BE_MINMEM: utils.ParseUnit(qa_config.get(constants.BE_MINMEM)), |
627 | 713a79e7 | Michael Hanselmann | } |
628 | 924e95f9 | Michael Hanselmann | |
629 | 713a79e7 | Michael Hanselmann | if use_client:
|
630 | 924e95f9 | Michael Hanselmann | job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE, |
631 | b5f33afa | Michael Hanselmann | instance.name, |
632 | 924e95f9 | Michael Hanselmann | constants.DT_PLAIN, |
633 | 924e95f9 | Michael Hanselmann | disks, nics, |
634 | 924e95f9 | Michael Hanselmann | os=qa_config.get("os"),
|
635 | aecba21e | Michael Hanselmann | pnode=node.primary, |
636 | 924e95f9 | Michael Hanselmann | beparams=beparams) |
637 | 924e95f9 | Michael Hanselmann | else:
|
638 | 924e95f9 | Michael Hanselmann | body = { |
639 | 713a79e7 | Michael Hanselmann | "__version__": 1, |
640 | 713a79e7 | Michael Hanselmann | "mode": constants.INSTANCE_CREATE,
|
641 | b5f33afa | Michael Hanselmann | "name": instance.name,
|
642 | 713a79e7 | Michael Hanselmann | "os_type": qa_config.get("os"), |
643 | 924e95f9 | Michael Hanselmann | "disk_template": constants.DT_PLAIN,
|
644 | aecba21e | Michael Hanselmann | "pnode": node.primary,
|
645 | 713a79e7 | Michael Hanselmann | "beparams": beparams,
|
646 | 713a79e7 | Michael Hanselmann | "disks": disks,
|
647 | 713a79e7 | Michael Hanselmann | "nics": nics,
|
648 | 924e95f9 | Michael Hanselmann | } |
649 | 924e95f9 | Michael Hanselmann | |
650 | 924e95f9 | Michael Hanselmann | (job_id, ) = _DoTests([ |
651 | 924e95f9 | Michael Hanselmann | ("/2/instances", _VerifyReturnsJob, "POST", body), |
652 | 924e95f9 | Michael Hanselmann | ]) |
653 | 8cb70e56 | Michael Hanselmann | |
654 | 8cb70e56 | Michael Hanselmann | _WaitForRapiJob(job_id) |
655 | 8cb70e56 | Michael Hanselmann | |
656 | 8cb70e56 | Michael Hanselmann | return instance
|
657 | 8cb70e56 | Michael Hanselmann | except:
|
658 | 6f88e076 | Michael Hanselmann | instance.Release() |
659 | 8cb70e56 | Michael Hanselmann | raise
|
660 | 8cb70e56 | Michael Hanselmann | |
661 | 8cb70e56 | Michael Hanselmann | |
662 | 2ee9171a | Hrvoje Ribicic | def _GenInstanceAllocationDict(node, instance): |
663 | 2ee9171a | Hrvoje Ribicic | """Creates an instance allocation dict to be used with the RAPI"""
|
664 | 2ee9171a | Hrvoje Ribicic | instance.SetDiskTemplate(constants.DT_PLAIN) |
665 | 2ee9171a | Hrvoje Ribicic | |
666 | 2ee9171a | Hrvoje Ribicic | disks = [{"size": utils.ParseUnit(d.get("size")), |
667 | 2ee9171a | Hrvoje Ribicic | "name": str(d.get("name"))} |
668 | 2ee9171a | Hrvoje Ribicic | for d in qa_config.GetDiskOptions()] |
669 | 2ee9171a | Hrvoje Ribicic | |
670 | 2ee9171a | Hrvoje Ribicic | nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
|
671 | 2ee9171a | Hrvoje Ribicic | nics = [{ |
672 | 2ee9171a | Hrvoje Ribicic | constants.INIC_MAC: nic0_mac, |
673 | 2ee9171a | Hrvoje Ribicic | }] |
674 | 2ee9171a | Hrvoje Ribicic | |
675 | 2ee9171a | Hrvoje Ribicic | beparams = { |
676 | 2ee9171a | Hrvoje Ribicic | constants.BE_MAXMEM: utils.ParseUnit(qa_config.get(constants.BE_MAXMEM)), |
677 | 2ee9171a | Hrvoje Ribicic | constants.BE_MINMEM: utils.ParseUnit(qa_config.get(constants.BE_MINMEM)), |
678 | 2ee9171a | Hrvoje Ribicic | } |
679 | 2ee9171a | Hrvoje Ribicic | |
680 | 2ee9171a | Hrvoje Ribicic | return _rapi_client.InstanceAllocation(constants.INSTANCE_CREATE,
|
681 | 2ee9171a | Hrvoje Ribicic | instance.name, |
682 | 2ee9171a | Hrvoje Ribicic | constants.DT_PLAIN, |
683 | 2ee9171a | Hrvoje Ribicic | disks, nics, |
684 | 2ee9171a | Hrvoje Ribicic | os=qa_config.get("os"),
|
685 | 2ee9171a | Hrvoje Ribicic | pnode=node.primary, |
686 | 2ee9171a | Hrvoje Ribicic | beparams=beparams) |
687 | 2ee9171a | Hrvoje Ribicic | |
688 | 2ee9171a | Hrvoje Ribicic | |
689 | 2ee9171a | Hrvoje Ribicic | def TestRapiInstanceMultiAlloc(node): |
690 | 2ee9171a | Hrvoje Ribicic | """Test adding two new instances via the RAPI instance-multi-alloc method"""
|
691 | 2ee9171a | Hrvoje Ribicic | if not qa_config.IsTemplateSupported(constants.DT_PLAIN): |
692 | 2ee9171a | Hrvoje Ribicic | return
|
693 | 2ee9171a | Hrvoje Ribicic | |
694 | 2ee9171a | Hrvoje Ribicic | JOBS_KEY = "jobs"
|
695 | 2ee9171a | Hrvoje Ribicic | |
696 | 2ee9171a | Hrvoje Ribicic | instance_one = qa_config.AcquireInstance() |
697 | 2ee9171a | Hrvoje Ribicic | instance_two = qa_config.AcquireInstance() |
698 | 2ee9171a | Hrvoje Ribicic | instance_list = [instance_one, instance_two] |
699 | 2ee9171a | Hrvoje Ribicic | try:
|
700 | 2ee9171a | Hrvoje Ribicic | rapi_dicts = map(functools.partial(_GenInstanceAllocationDict, node),
|
701 | 2ee9171a | Hrvoje Ribicic | instance_list) |
702 | 2ee9171a | Hrvoje Ribicic | |
703 | 2ee9171a | Hrvoje Ribicic | job_id = _rapi_client.InstancesMultiAlloc(rapi_dicts) |
704 | 2ee9171a | Hrvoje Ribicic | |
705 | 2ee9171a | Hrvoje Ribicic | results, = _WaitForRapiJob(job_id) |
706 | 2ee9171a | Hrvoje Ribicic | |
707 | 2ee9171a | Hrvoje Ribicic | if JOBS_KEY not in results: |
708 | 2ee9171a | Hrvoje Ribicic | raise qa_error.Error("RAPI instance-multi-alloc did not deliver " |
709 | 2ee9171a | Hrvoje Ribicic | "information about created jobs")
|
710 | 2ee9171a | Hrvoje Ribicic | |
711 | 2ee9171a | Hrvoje Ribicic | if len(results[JOBS_KEY]) != len(instance_list): |
712 | 2ee9171a | Hrvoje Ribicic | raise qa_error.Error("RAPI instance-multi-alloc failed to return the " |
713 | 2ee9171a | Hrvoje Ribicic | "desired number of jobs!")
|
714 | 2ee9171a | Hrvoje Ribicic | |
715 | 2ee9171a | Hrvoje Ribicic | for success, job in results[JOBS_KEY]: |
716 | 2ee9171a | Hrvoje Ribicic | if success:
|
717 | 2ee9171a | Hrvoje Ribicic | _WaitForRapiJob(job) |
718 | 2ee9171a | Hrvoje Ribicic | else:
|
719 | 2ee9171a | Hrvoje Ribicic | raise qa_error.Error("Failed to create instance in " |
720 | 2ee9171a | Hrvoje Ribicic | "instance-multi-alloc call")
|
721 | 2ee9171a | Hrvoje Ribicic | except:
|
722 | 2ee9171a | Hrvoje Ribicic | # Note that although released, it may be that some of the instance creations
|
723 | 2ee9171a | Hrvoje Ribicic | # have in fact succeeded. Handling this in a better way may be possible, but
|
724 | 2ee9171a | Hrvoje Ribicic | # is not necessary as the QA has already failed at this point.
|
725 | 2ee9171a | Hrvoje Ribicic | for instance in instance_list: |
726 | 2ee9171a | Hrvoje Ribicic | instance.Release() |
727 | 2ee9171a | Hrvoje Ribicic | raise
|
728 | 2ee9171a | Hrvoje Ribicic | |
729 | 2ee9171a | Hrvoje Ribicic | return (instance_one, instance_two)
|
730 | 2ee9171a | Hrvoje Ribicic | |
731 | 2ee9171a | Hrvoje Ribicic | |
732 | 5fa0375e | Michael Hanselmann | @InstanceCheck(None, INST_DOWN, FIRST_ARG) |
733 | 924e95f9 | Michael Hanselmann | def TestRapiInstanceRemove(instance, use_client): |
734 | 8cb70e56 | Michael Hanselmann | """Test removing instance via RAPI"""
|
735 | bab4f56a | Helga Velroyen | # FIXME: this does not work if LVM is not enabled. Find out if this is a bug
|
736 | bab4f56a | Helga Velroyen | # in RAPI or in the test
|
737 | bab4f56a | Helga Velroyen | if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG): |
738 | bab4f56a | Helga Velroyen | return
|
739 | bab4f56a | Helga Velroyen | |
740 | 924e95f9 | Michael Hanselmann | if use_client:
|
741 | b5f33afa | Michael Hanselmann | job_id = _rapi_client.DeleteInstance(instance.name) |
742 | 924e95f9 | Michael Hanselmann | else:
|
743 | 924e95f9 | Michael Hanselmann | (job_id, ) = _DoTests([ |
744 | b5f33afa | Michael Hanselmann | ("/2/instances/%s" % instance.name, _VerifyReturnsJob, "DELETE", None), |
745 | 924e95f9 | Michael Hanselmann | ]) |
746 | 8cb70e56 | Michael Hanselmann | |
747 | 8cb70e56 | Michael Hanselmann | _WaitForRapiJob(job_id) |
748 | 8cb70e56 | Michael Hanselmann | |
749 | 5d831182 | Michael Hanselmann | |
750 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
751 | 938bde86 | Michael Hanselmann | def TestRapiInstanceMigrate(instance): |
752 | 938bde86 | Michael Hanselmann | """Test migrating instance via RAPI"""
|
753 | 5de31440 | Bernardo Dal Seno | if not IsMigrationSupported(instance): |
754 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support migration, skipping" |
755 | 5de31440 | Bernardo Dal Seno | " test")
|
756 | 5de31440 | Bernardo Dal Seno | return
|
757 | 938bde86 | Michael Hanselmann | # Move to secondary node
|
758 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name)) |
759 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
760 | 938bde86 | Michael Hanselmann | # And back to previous primary
|
761 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name)) |
762 | c0a146a1 | Michael Hanselmann | |
763 | c0a146a1 | Michael Hanselmann | |
764 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
765 | c0a146a1 | Michael Hanselmann | def TestRapiInstanceFailover(instance): |
766 | c0a146a1 | Michael Hanselmann | """Test failing over instance via RAPI"""
|
767 | 5de31440 | Bernardo Dal Seno | if not IsFailoverSupported(instance): |
768 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support failover, skipping" |
769 | 5de31440 | Bernardo Dal Seno | " test")
|
770 | 5de31440 | Bernardo Dal Seno | return
|
771 | c0a146a1 | Michael Hanselmann | # Move to secondary node
|
772 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name)) |
773 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
774 | c0a146a1 | Michael Hanselmann | # And back to previous primary
|
775 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name)) |
776 | a7418448 | Michael Hanselmann | |
777 | a7418448 | Michael Hanselmann | |
778 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG)
|
779 | a7418448 | Michael Hanselmann | def TestRapiInstanceShutdown(instance): |
780 | a7418448 | Michael Hanselmann | """Test stopping an instance via RAPI"""
|
781 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.ShutdownInstance(instance.name)) |
782 | a7418448 | Michael Hanselmann | |
783 | a7418448 | Michael Hanselmann | |
784 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
|
785 | a7418448 | Michael Hanselmann | def TestRapiInstanceStartup(instance): |
786 | a7418448 | Michael Hanselmann | """Test starting an instance via RAPI"""
|
787 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.StartupInstance(instance.name)) |
788 | 938bde86 | Michael Hanselmann | |
789 | 938bde86 | Michael Hanselmann | |
790 | 51131cad | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
791 | 4c1a464b | Iustin Pop | def TestRapiInstanceRenameAndBack(rename_source, rename_target): |
792 | 4c1a464b | Iustin Pop | """Test renaming instance via RAPI
|
793 | 4c1a464b | Iustin Pop |
|
794 | 4c1a464b | Iustin Pop | This must leave the instance with the original name (in the
|
795 | 4c1a464b | Iustin Pop | non-failure case).
|
796 | 4c1a464b | Iustin Pop |
|
797 | 4c1a464b | Iustin Pop | """
|
798 | e5c2accd | Guido Trotter | _WaitForRapiJob(_rapi_client.RenameInstance(rename_source, rename_target)) |
799 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_source, False)
|
800 | 51131cad | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_target, False)
|
801 | 4c1a464b | Iustin Pop | _WaitForRapiJob(_rapi_client.RenameInstance(rename_target, rename_source)) |
802 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_target, False)
|
803 | 7fb50870 | Michael Hanselmann | |
804 | 7fb50870 | Michael Hanselmann | |
805 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
806 | 0220d2cf | Guido Trotter | def TestRapiInstanceReinstall(instance): |
807 | 0220d2cf | Guido Trotter | """Test reinstalling an instance via RAPI"""
|
808 | ad658827 | Bernardo Dal Seno | if instance.disk_template == constants.DT_DISKLESS:
|
809 | ad658827 | Bernardo Dal Seno | print qa_utils.FormatInfo("Test not supported for diskless instances") |
810 | ad658827 | Bernardo Dal Seno | return
|
811 | ad658827 | Bernardo Dal Seno | |
812 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name)) |
813 | 51131cad | Michael Hanselmann | # By default, the instance is started again
|
814 | 51131cad | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
815 | 51131cad | Michael Hanselmann | |
816 | 51131cad | Michael Hanselmann | # Reinstall again without starting
|
817 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name, |
818 | 51131cad | Michael Hanselmann | no_startup=True))
|
819 | 0220d2cf | Guido Trotter | |
820 | 0220d2cf | Guido Trotter | |
821 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
822 | 539d65ba | Michael Hanselmann | def TestRapiInstanceReplaceDisks(instance): |
823 | 539d65ba | Michael Hanselmann | """Test replacing instance disks via RAPI"""
|
824 | 5de31440 | Bernardo Dal Seno | if not IsDiskReplacingSupported(instance): |
825 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support disk replacing," |
826 | 5de31440 | Bernardo Dal Seno | " skipping test")
|
827 | 5de31440 | Bernardo Dal Seno | return
|
828 | 5ae4945a | Iustin Pop | fn = _rapi_client.ReplaceInstanceDisks |
829 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(fn(instance.name, |
830 | 5ae4945a | Iustin Pop | mode=constants.REPLACE_DISK_AUTO, disks=[])) |
831 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(fn(instance.name, |
832 | 5ae4945a | Iustin Pop | mode=constants.REPLACE_DISK_SEC, disks="0"))
|
833 | 539d65ba | Michael Hanselmann | |
834 | 539d65ba | Michael Hanselmann | |
835 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
836 | 3b7158ef | Michael Hanselmann | def TestRapiInstanceModify(instance): |
837 | 3b7158ef | Michael Hanselmann | """Test modifying instance via RAPI"""
|
838 | a8dbf746 | Michael Hanselmann | default_hv = qa_config.GetDefaultHypervisor() |
839 | a8dbf746 | Michael Hanselmann | |
840 | 3b7158ef | Michael Hanselmann | def _ModifyInstance(**kwargs): |
841 | b5f33afa | Michael Hanselmann | _WaitForRapiJob(_rapi_client.ModifyInstance(instance.name, **kwargs)) |
842 | 3b7158ef | Michael Hanselmann | |
843 | 3b7158ef | Michael Hanselmann | _ModifyInstance(beparams={ |
844 | 3b7158ef | Michael Hanselmann | constants.BE_VCPUS: 3,
|
845 | 3b7158ef | Michael Hanselmann | }) |
846 | 3b7158ef | Michael Hanselmann | |
847 | 3b7158ef | Michael Hanselmann | _ModifyInstance(beparams={ |
848 | 3b7158ef | Michael Hanselmann | constants.BE_VCPUS: constants.VALUE_DEFAULT, |
849 | 3b7158ef | Michael Hanselmann | }) |
850 | 3b7158ef | Michael Hanselmann | |
851 | a8dbf746 | Michael Hanselmann | if default_hv == constants.HT_XEN_PVM:
|
852 | a8dbf746 | Michael Hanselmann | _ModifyInstance(hvparams={ |
853 | a8dbf746 | Michael Hanselmann | constants.HV_KERNEL_ARGS: "single",
|
854 | a8dbf746 | Michael Hanselmann | }) |
855 | a8dbf746 | Michael Hanselmann | _ModifyInstance(hvparams={ |
856 | a8dbf746 | Michael Hanselmann | constants.HV_KERNEL_ARGS: constants.VALUE_DEFAULT, |
857 | a8dbf746 | Michael Hanselmann | }) |
858 | a8dbf746 | Michael Hanselmann | elif default_hv == constants.HT_XEN_HVM:
|
859 | a8dbf746 | Michael Hanselmann | _ModifyInstance(hvparams={ |
860 | a8dbf746 | Michael Hanselmann | constants.HV_BOOT_ORDER: "acn",
|
861 | a8dbf746 | Michael Hanselmann | }) |
862 | a8dbf746 | Michael Hanselmann | _ModifyInstance(hvparams={ |
863 | a8dbf746 | Michael Hanselmann | constants.HV_BOOT_ORDER: constants.VALUE_DEFAULT, |
864 | a8dbf746 | Michael Hanselmann | }) |
865 | 3b7158ef | Michael Hanselmann | |
866 | 3b7158ef | Michael Hanselmann | |
867 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
868 | b82d4c5e | Michael Hanselmann | def TestRapiInstanceConsole(instance): |
869 | b82d4c5e | Michael Hanselmann | """Test getting instance console information via RAPI"""
|
870 | b5f33afa | Michael Hanselmann | result = _rapi_client.GetInstanceConsole(instance.name) |
871 | b82d4c5e | Michael Hanselmann | console = objects.InstanceConsole.FromDict(result) |
872 | b3724640 | Jose A. Lopes | AssertEqual(console.Validate(), None)
|
873 | b5f33afa | Michael Hanselmann | AssertEqual(console.instance, qa_utils.ResolveInstanceName(instance.name)) |
874 | b82d4c5e | Michael Hanselmann | |
875 | b82d4c5e | Michael Hanselmann | |
876 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
877 | b82d4c5e | Michael Hanselmann | def TestRapiStoppedInstanceConsole(instance): |
878 | b82d4c5e | Michael Hanselmann | """Test getting stopped instance's console information via RAPI"""
|
879 | b82d4c5e | Michael Hanselmann | try:
|
880 | b5f33afa | Michael Hanselmann | _rapi_client.GetInstanceConsole(instance.name) |
881 | b82d4c5e | Michael Hanselmann | except rapi.client.GanetiApiError, err:
|
882 | b82d4c5e | Michael Hanselmann | AssertEqual(err.code, 503)
|
883 | b82d4c5e | Michael Hanselmann | else:
|
884 | b82d4c5e | Michael Hanselmann | raise qa_error.Error("Getting console for stopped instance didn't" |
885 | b82d4c5e | Michael Hanselmann | " return HTTP 503")
|
886 | b82d4c5e | Michael Hanselmann | |
887 | b82d4c5e | Michael Hanselmann | |
888 | 2932dc44 | Michael Hanselmann | def GetOperatingSystems(): |
889 | 2932dc44 | Michael Hanselmann | """Retrieves a list of all available operating systems.
|
890 | 2932dc44 | Michael Hanselmann |
|
891 | 2932dc44 | Michael Hanselmann | """
|
892 | 2932dc44 | Michael Hanselmann | return _rapi_client.GetOperatingSystems()
|
893 | 2932dc44 | Michael Hanselmann | |
894 | 2932dc44 | Michael Hanselmann | |
895 | 5fb7679c | Hrvoje Ribicic | def _InvokeMoveInstance(current_dest_inst, current_src_inst, rapi_pw_filename, |
896 | 5fb7679c | Hrvoje Ribicic | joint_master, perform_checks, target_nodes=None):
|
897 | 5fb7679c | Hrvoje Ribicic | """ Invokes the move-instance tool for testing purposes.
|
898 | 5fb7679c | Hrvoje Ribicic |
|
899 | 5fb7679c | Hrvoje Ribicic | """
|
900 | 5fb7679c | Hrvoje Ribicic | # Some uses of this test might require that RAPI-only commands are used,
|
901 | 5fb7679c | Hrvoje Ribicic | # and the checks are command-line based.
|
902 | 5fb7679c | Hrvoje Ribicic | if perform_checks:
|
903 | 5fb7679c | Hrvoje Ribicic | qa_utils.RunInstanceCheck(current_dest_inst, False)
|
904 | 5fb7679c | Hrvoje Ribicic | |
905 | 5fb7679c | Hrvoje Ribicic | cmd = [ |
906 | 5fb7679c | Hrvoje Ribicic | "../tools/move-instance",
|
907 | 5fb7679c | Hrvoje Ribicic | "--verbose",
|
908 | 5fb7679c | Hrvoje Ribicic | "--src-ca-file=%s" % _rapi_ca.name,
|
909 | 5fb7679c | Hrvoje Ribicic | "--src-username=%s" % _rapi_username,
|
910 | 5fb7679c | Hrvoje Ribicic | "--src-password-file=%s" % rapi_pw_filename,
|
911 | 5fb7679c | Hrvoje Ribicic | "--dest-instance-name=%s" % current_dest_inst,
|
912 | 5fb7679c | Hrvoje Ribicic | ] |
913 | 5fb7679c | Hrvoje Ribicic | |
914 | 5fb7679c | Hrvoje Ribicic | if target_nodes:
|
915 | 5fb7679c | Hrvoje Ribicic | pnode, snode = target_nodes |
916 | 5fb7679c | Hrvoje Ribicic | cmd.extend([ |
917 | 5fb7679c | Hrvoje Ribicic | "--dest-primary-node=%s" % pnode,
|
918 | 5fb7679c | Hrvoje Ribicic | "--dest-secondary-node=%s" % snode,
|
919 | 5fb7679c | Hrvoje Ribicic | ]) |
920 | 5fb7679c | Hrvoje Ribicic | else:
|
921 | 343c9ed2 | Hrvoje Ribicic | cmd.extend([ |
922 | 343c9ed2 | Hrvoje Ribicic | "--iallocator=%s" % constants.IALLOC_HAIL,
|
923 | 343c9ed2 | Hrvoje Ribicic | "--opportunistic-tries=1",
|
924 | 343c9ed2 | Hrvoje Ribicic | ]) |
925 | 5fb7679c | Hrvoje Ribicic | |
926 | 5fb7679c | Hrvoje Ribicic | cmd.extend([ |
927 | 5fb7679c | Hrvoje Ribicic | "--net=0:mac=%s" % constants.VALUE_GENERATE,
|
928 | 5fb7679c | Hrvoje Ribicic | joint_master, |
929 | 5fb7679c | Hrvoje Ribicic | joint_master, |
930 | 5fb7679c | Hrvoje Ribicic | current_src_inst, |
931 | 5fb7679c | Hrvoje Ribicic | ]) |
932 | 5fb7679c | Hrvoje Ribicic | |
933 | 5fb7679c | Hrvoje Ribicic | AssertEqual(StartLocalCommand(cmd).wait(), 0)
|
934 | 5fb7679c | Hrvoje Ribicic | |
935 | 5fb7679c | Hrvoje Ribicic | if perform_checks:
|
936 | 5fb7679c | Hrvoje Ribicic | qa_utils.RunInstanceCheck(current_src_inst, False)
|
937 | 5fb7679c | Hrvoje Ribicic | qa_utils.RunInstanceCheck(current_dest_inst, True)
|
938 | 5fb7679c | Hrvoje Ribicic | |
939 | 5fb7679c | Hrvoje Ribicic | |
940 | 638a7266 | Iustin Pop | def TestInterClusterInstanceMove(src_instance, dest_instance, |
941 | 66743fe3 | Hrvoje Ribicic | inodes, tnode, perform_checks=True):
|
942 | 5d831182 | Michael Hanselmann | """Test tools/move-instance"""
|
943 | 5d831182 | Michael Hanselmann | master = qa_config.GetMasterNode() |
944 | 5d831182 | Michael Hanselmann | |
945 | 5d831182 | Michael Hanselmann | rapi_pw_file = tempfile.NamedTemporaryFile() |
946 | 5d831182 | Michael Hanselmann | rapi_pw_file.write(_rapi_password) |
947 | 5d831182 | Michael Hanselmann | rapi_pw_file.flush() |
948 | 5d831182 | Michael Hanselmann | |
949 | 66743fe3 | Hrvoje Ribicic | # Needed only if checks are to be performed
|
950 | 66743fe3 | Hrvoje Ribicic | if perform_checks:
|
951 | 66743fe3 | Hrvoje Ribicic | dest_instance.SetDiskTemplate(src_instance.disk_template) |
952 | 906a0346 | Bernardo Dal Seno | |
953 | 5d831182 | Michael Hanselmann | # TODO: Run some instance tests before moving back
|
954 | 677e16eb | Iustin Pop | |
955 | c99200a3 | Bernardo Dal Seno | if len(inodes) > 1: |
956 | c99200a3 | Bernardo Dal Seno | # No disk template currently requires more than 1 secondary node. If this
|
957 | c99200a3 | Bernardo Dal Seno | # changes, either this test must be skipped or the script must be updated.
|
958 | c99200a3 | Bernardo Dal Seno | assert len(inodes) == 2 |
959 | c99200a3 | Bernardo Dal Seno | snode = inodes[1]
|
960 | c99200a3 | Bernardo Dal Seno | else:
|
961 | 5fb7679c | Hrvoje Ribicic | # Instance is not redundant, but we still need to pass a node
|
962 | 638a7266 | Iustin Pop | # (which will be ignored)
|
963 | c99200a3 | Bernardo Dal Seno | snode = tnode |
964 | c99200a3 | Bernardo Dal Seno | pnode = inodes[0]
|
965 | 66743fe3 | Hrvoje Ribicic | |
966 | 343c9ed2 | Hrvoje Ribicic | # pnode:snode are the *current* nodes, and the first move is an
|
967 | 343c9ed2 | Hrvoje Ribicic | # iallocator-guided move outside of pnode. The node lock for the pnode
|
968 | 343c9ed2 | Hrvoje Ribicic | # assures that this happens, and while we cannot be sure where the instance
|
969 | 343c9ed2 | Hrvoje Ribicic | # will land, it is a real move.
|
970 | 343c9ed2 | Hrvoje Ribicic | locks = {locking.LEVEL_NODE: [pnode.primary]} |
971 | 57efdaf5 | Hrvoje Ribicic | RunWithLocks(_InvokeMoveInstance, locks, 600.0, False, |
972 | 343c9ed2 | Hrvoje Ribicic | dest_instance.name, src_instance.name, rapi_pw_file.name, |
973 | 343c9ed2 | Hrvoje Ribicic | master.primary, perform_checks) |
974 | 66743fe3 | Hrvoje Ribicic | |
975 | 5fb7679c | Hrvoje Ribicic | # And then back to pnode:snode
|
976 | 5fb7679c | Hrvoje Ribicic | _InvokeMoveInstance(src_instance.name, dest_instance.name, rapi_pw_file.name, |
977 | 5fb7679c | Hrvoje Ribicic | master.primary, perform_checks, |
978 | 5fb7679c | Hrvoje Ribicic | target_nodes=(pnode.primary, snode.primary)) |