root / qa / qa_rapi.py @ 2a7c3583
History | View | Annotate | Download (9.6 kB)
1 | a47f574c | Oleksiy Mishchenko | #
|
---|---|---|---|
2 | a47f574c | Oleksiy Mishchenko | |
3 | a47f574c | Oleksiy Mishchenko | # Copyright (C) 2007, 2008 Google Inc.
|
4 | a47f574c | Oleksiy Mishchenko | #
|
5 | a47f574c | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify
|
6 | a47f574c | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by
|
7 | a47f574c | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or
|
8 | a47f574c | Oleksiy Mishchenko | # (at your option) any later version.
|
9 | a47f574c | Oleksiy Mishchenko | #
|
10 | a47f574c | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but
|
11 | a47f574c | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | a47f574c | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | a47f574c | Oleksiy Mishchenko | # General Public License for more details.
|
14 | a47f574c | Oleksiy Mishchenko | #
|
15 | a47f574c | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License
|
16 | a47f574c | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software
|
17 | a47f574c | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
18 | a47f574c | Oleksiy Mishchenko | # 02110-1301, USA.
|
19 | a47f574c | Oleksiy Mishchenko | |
20 | a47f574c | Oleksiy Mishchenko | |
21 | a47f574c | Oleksiy Mishchenko | """Remote API QA tests.
|
22 | a47f574c | Oleksiy Mishchenko |
|
23 | a47f574c | Oleksiy Mishchenko | """
|
24 | a47f574c | Oleksiy Mishchenko | |
25 | 2771835c | Michael Hanselmann | import tempfile |
26 | a47f574c | Oleksiy Mishchenko | |
27 | a47f574c | Oleksiy Mishchenko | from ganeti import utils |
28 | a47f574c | Oleksiy Mishchenko | from ganeti import constants |
29 | a47f574c | Oleksiy Mishchenko | from ganeti import errors |
30 | a47f574c | Oleksiy Mishchenko | from ganeti import serializer |
31 | 2771835c | Michael Hanselmann | from ganeti import cli |
32 | 2771835c | Michael Hanselmann | from ganeti import rapi |
33 | 2771835c | Michael Hanselmann | |
34 | 2771835c | Michael Hanselmann | import ganeti.rapi.client |
35 | 2771835c | Michael Hanselmann | import ganeti.rapi.client_utils |
36 | a47f574c | Oleksiy Mishchenko | |
37 | a47f574c | Oleksiy Mishchenko | import qa_config |
38 | a47f574c | Oleksiy Mishchenko | import qa_utils |
39 | a47f574c | Oleksiy Mishchenko | import qa_error |
40 | a47f574c | Oleksiy Mishchenko | |
41 | e6ce18ac | René Nussbaumer | from qa_utils import (AssertEqual, AssertNotEqual, AssertIn, AssertMatch, |
42 | 5d831182 | Michael Hanselmann | StartLocalCommand) |
43 | a47f574c | Oleksiy Mishchenko | |
44 | a47f574c | Oleksiy Mishchenko | |
45 | 2771835c | Michael Hanselmann | _rapi_ca = None
|
46 | 2771835c | Michael Hanselmann | _rapi_client = None
|
47 | 5d831182 | Michael Hanselmann | _rapi_username = None
|
48 | 5d831182 | Michael Hanselmann | _rapi_password = None
|
49 | e6ce18ac | René Nussbaumer | |
50 | e6ce18ac | René Nussbaumer | |
51 | 2771835c | Michael Hanselmann | def Setup(username, password): |
52 | 2771835c | Michael Hanselmann | """Configures the RAPI client.
|
53 | 725ec2f1 | René Nussbaumer |
|
54 | 2771835c | Michael Hanselmann | """
|
55 | 2771835c | Michael Hanselmann | global _rapi_ca
|
56 | 2771835c | Michael Hanselmann | global _rapi_client
|
57 | 5d831182 | Michael Hanselmann | global _rapi_username
|
58 | 5d831182 | Michael Hanselmann | global _rapi_password
|
59 | 5d831182 | Michael Hanselmann | |
60 | 5d831182 | Michael Hanselmann | _rapi_username = username |
61 | 5d831182 | Michael Hanselmann | _rapi_password = password |
62 | e6ce18ac | René Nussbaumer | |
63 | 2771835c | Michael Hanselmann | master = qa_config.GetMasterNode() |
64 | e6ce18ac | René Nussbaumer | |
65 | 2771835c | Michael Hanselmann | # Load RAPI certificate from master node
|
66 | 2771835c | Michael Hanselmann | cmd = ["cat", constants.RAPI_CERT_FILE]
|
67 | e6ce18ac | René Nussbaumer | |
68 | 2771835c | Michael Hanselmann | # Write to temporary file
|
69 | 2771835c | Michael Hanselmann | _rapi_ca = tempfile.NamedTemporaryFile() |
70 | 2771835c | Michael Hanselmann | _rapi_ca.write(qa_utils.GetCommandOutput(master["primary"],
|
71 | 2771835c | Michael Hanselmann | utils.ShellQuoteArgs(cmd))) |
72 | 2771835c | Michael Hanselmann | _rapi_ca.flush() |
73 | e6ce18ac | René Nussbaumer | |
74 | 2771835c | Michael Hanselmann | port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
|
75 | 2a7c3583 | Michael Hanselmann | cfg_curl = rapi.client.GenericCurlConfig(cafile=_rapi_ca.name, |
76 | 2a7c3583 | Michael Hanselmann | proxy="")
|
77 | e6ce18ac | René Nussbaumer | |
78 | 2771835c | Michael Hanselmann | _rapi_client = rapi.client.GanetiRapiClient(master["primary"], port=port,
|
79 | 2771835c | Michael Hanselmann | username=username, |
80 | 2771835c | Michael Hanselmann | password=password, |
81 | 2a7c3583 | Michael Hanselmann | curl_config_fn=cfg_curl) |
82 | e6ce18ac | René Nussbaumer | |
83 | 2771835c | Michael Hanselmann | print "RAPI protocol version: %s" % _rapi_client.GetVersion() |
84 | a47f574c | Oleksiy Mishchenko | |
85 | a47f574c | Oleksiy Mishchenko | |
86 | a47f574c | Oleksiy Mishchenko | INSTANCE_FIELDS = ("name", "os", "pnode", "snodes", |
87 | a5b9d725 | Iustin Pop | "admin_state",
|
88 | a5b9d725 | Iustin Pop | "disk_template", "disk.sizes", |
89 | 22482387 | Iustin Pop | "nic.ips", "nic.macs", "nic.modes", "nic.links", |
90 | a5b9d725 | Iustin Pop | "beparams", "hvparams", |
91 | a5b9d725 | Iustin Pop | "oper_state", "oper_ram", "status", "tags") |
92 | a47f574c | Oleksiy Mishchenko | |
93 | a47f574c | Oleksiy Mishchenko | NODE_FIELDS = ("name", "dtotal", "dfree", |
94 | a47f574c | Oleksiy Mishchenko | "mtotal", "mnode", "mfree", |
95 | a47f574c | Oleksiy Mishchenko | "pinst_cnt", "sinst_cnt", "tags") |
96 | a47f574c | Oleksiy Mishchenko | |
97 | 94e63ca1 | Michael Hanselmann | JOB_FIELDS = frozenset([
|
98 | 94e63ca1 | Michael Hanselmann | "id", "ops", "status", "summary", |
99 | 94e63ca1 | Michael Hanselmann | "opstatus", "opresult", "oplog", |
100 | 94e63ca1 | Michael Hanselmann | "received_ts", "start_ts", "end_ts", |
101 | 94e63ca1 | Michael Hanselmann | ]) |
102 | 94e63ca1 | Michael Hanselmann | |
103 | 68289c75 | Iustin Pop | LIST_FIELDS = ("id", "uri") |
104 | a47f574c | Oleksiy Mishchenko | |
105 | a47f574c | Oleksiy Mishchenko | |
106 | a47f574c | Oleksiy Mishchenko | def Enabled(): |
107 | a47f574c | Oleksiy Mishchenko | """Return whether remote API tests should be run.
|
108 | a47f574c | Oleksiy Mishchenko |
|
109 | a47f574c | Oleksiy Mishchenko | """
|
110 | e1876432 | Guido Trotter | return qa_config.TestEnabled('rapi') |
111 | a47f574c | Oleksiy Mishchenko | |
112 | a47f574c | Oleksiy Mishchenko | |
113 | a47f574c | Oleksiy Mishchenko | def _DoTests(uris): |
114 | 94e63ca1 | Michael Hanselmann | results = [] |
115 | a47f574c | Oleksiy Mishchenko | |
116 | 94e63ca1 | Michael Hanselmann | for uri, verify, method, body in uris: |
117 | a47f574c | Oleksiy Mishchenko | assert uri.startswith("/") |
118 | a47f574c | Oleksiy Mishchenko | |
119 | 2771835c | Michael Hanselmann | data = _rapi_client._SendRequest(method, uri, None, body)
|
120 | a47f574c | Oleksiy Mishchenko | |
121 | a47f574c | Oleksiy Mishchenko | if verify is not None: |
122 | a47f574c | Oleksiy Mishchenko | if callable(verify): |
123 | a47f574c | Oleksiy Mishchenko | verify(data) |
124 | a47f574c | Oleksiy Mishchenko | else:
|
125 | a47f574c | Oleksiy Mishchenko | AssertEqual(data, verify) |
126 | a47f574c | Oleksiy Mishchenko | |
127 | 94e63ca1 | Michael Hanselmann | results.append(data) |
128 | 94e63ca1 | Michael Hanselmann | |
129 | 94e63ca1 | Michael Hanselmann | return results
|
130 | 94e63ca1 | Michael Hanselmann | |
131 | 94e63ca1 | Michael Hanselmann | |
132 | 94e63ca1 | Michael Hanselmann | def _VerifyReturnsJob(data): |
133 | 94e63ca1 | Michael Hanselmann | AssertMatch(data, r'^\d+$')
|
134 | 94e63ca1 | Michael Hanselmann | |
135 | a47f574c | Oleksiy Mishchenko | |
136 | a47f574c | Oleksiy Mishchenko | def TestVersion(): |
137 | a47f574c | Oleksiy Mishchenko | """Testing remote API version.
|
138 | a47f574c | Oleksiy Mishchenko |
|
139 | a47f574c | Oleksiy Mishchenko | """
|
140 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
141 | 94e63ca1 | Michael Hanselmann | ("/version", constants.RAPI_VERSION, 'GET', None), |
142 | a47f574c | Oleksiy Mishchenko | ]) |
143 | a47f574c | Oleksiy Mishchenko | |
144 | a47f574c | Oleksiy Mishchenko | |
145 | a47f574c | Oleksiy Mishchenko | def TestEmptyCluster(): |
146 | a47f574c | Oleksiy Mishchenko | """Testing remote API on an empty cluster.
|
147 | a47f574c | Oleksiy Mishchenko |
|
148 | a47f574c | Oleksiy Mishchenko | """
|
149 | 94e63ca1 | Michael Hanselmann | master = qa_config.GetMasterNode() |
150 | 94e63ca1 | Michael Hanselmann | master_full = qa_utils.ResolveNodeName(master) |
151 | a47f574c | Oleksiy Mishchenko | |
152 | a47f574c | Oleksiy Mishchenko | def _VerifyInfo(data): |
153 | a47f574c | Oleksiy Mishchenko | AssertIn("name", data)
|
154 | a47f574c | Oleksiy Mishchenko | AssertIn("master", data)
|
155 | 94e63ca1 | Michael Hanselmann | AssertEqual(data["master"], master_full)
|
156 | a47f574c | Oleksiy Mishchenko | |
157 | a47f574c | Oleksiy Mishchenko | def _VerifyNodes(data): |
158 | a47f574c | Oleksiy Mishchenko | master_entry = { |
159 | 94e63ca1 | Michael Hanselmann | "id": master_full,
|
160 | 94e63ca1 | Michael Hanselmann | "uri": "/2/nodes/%s" % master_full, |
161 | a47f574c | Oleksiy Mishchenko | } |
162 | a47f574c | Oleksiy Mishchenko | AssertIn(master_entry, data) |
163 | a47f574c | Oleksiy Mishchenko | |
164 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
165 | a47f574c | Oleksiy Mishchenko | for node in data: |
166 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
167 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
168 | a47f574c | Oleksiy Mishchenko | |
169 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
170 | 94e63ca1 | Michael Hanselmann | ("/", None, 'GET', None), |
171 | 94e63ca1 | Michael Hanselmann | ("/2/info", _VerifyInfo, 'GET', None), |
172 | 94e63ca1 | Michael Hanselmann | ("/2/tags", None, 'GET', None), |
173 | 94e63ca1 | Michael Hanselmann | ("/2/nodes", _VerifyNodes, 'GET', None), |
174 | 94e63ca1 | Michael Hanselmann | ("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET', None), |
175 | 94e63ca1 | Michael Hanselmann | ("/2/instances", [], 'GET', None), |
176 | 94e63ca1 | Michael Hanselmann | ("/2/instances?bulk=1", [], 'GET', None), |
177 | 94e63ca1 | Michael Hanselmann | ("/2/os", None, 'GET', None), |
178 | a47f574c | Oleksiy Mishchenko | ]) |
179 | a47f574c | Oleksiy Mishchenko | |
180 | a47f574c | Oleksiy Mishchenko | |
181 | a47f574c | Oleksiy Mishchenko | def TestInstance(instance): |
182 | a47f574c | Oleksiy Mishchenko | """Testing getting instance(s) info via remote API.
|
183 | a47f574c | Oleksiy Mishchenko |
|
184 | a47f574c | Oleksiy Mishchenko | """
|
185 | a47f574c | Oleksiy Mishchenko | def _VerifyInstance(data): |
186 | a47f574c | Oleksiy Mishchenko | for entry in INSTANCE_FIELDS: |
187 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
188 | c85d3b64 | Michael Hanselmann | |
189 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesList(data): |
190 | a47f574c | Oleksiy Mishchenko | for instance in data: |
191 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
192 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, instance) |
193 | c85d3b64 | Michael Hanselmann | |
194 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesBulk(data): |
195 | a47f574c | Oleksiy Mishchenko | for instance_data in data: |
196 | a47f574c | Oleksiy Mishchenko | _VerifyInstance(instance_data) |
197 | a47f574c | Oleksiy Mishchenko | |
198 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
199 | 94e63ca1 | Michael Hanselmann | ("/2/instances/%s" % instance["name"], _VerifyInstance, 'GET', None), |
200 | 94e63ca1 | Michael Hanselmann | ("/2/instances", _VerifyInstancesList, 'GET', None), |
201 | 94e63ca1 | Michael Hanselmann | ("/2/instances?bulk=1", _VerifyInstancesBulk, 'GET', None), |
202 | 94e63ca1 | Michael Hanselmann | ("/2/instances/%s/activate-disks" % instance["name"], |
203 | 94e63ca1 | Michael Hanselmann | _VerifyReturnsJob, 'PUT', None), |
204 | 94e63ca1 | Michael Hanselmann | ("/2/instances/%s/deactivate-disks" % instance["name"], |
205 | 94e63ca1 | Michael Hanselmann | _VerifyReturnsJob, 'PUT', None), |
206 | a47f574c | Oleksiy Mishchenko | ]) |
207 | a47f574c | Oleksiy Mishchenko | |
208 | ebeb600f | Michael Hanselmann | # Test OpPrepareExport
|
209 | ebeb600f | Michael Hanselmann | (job_id, ) = _DoTests([ |
210 | ebeb600f | Michael Hanselmann | ("/2/instances/%s/prepare-export?mode=%s" %
|
211 | ebeb600f | Michael Hanselmann | (instance["name"], constants.EXPORT_MODE_REMOTE),
|
212 | ebeb600f | Michael Hanselmann | _VerifyReturnsJob, "PUT", None), |
213 | ebeb600f | Michael Hanselmann | ]) |
214 | ebeb600f | Michael Hanselmann | |
215 | ebeb600f | Michael Hanselmann | result = _WaitForRapiJob(job_id)[0]
|
216 | ebeb600f | Michael Hanselmann | AssertEqual(len(result["handshake"]), 3) |
217 | ebeb600f | Michael Hanselmann | AssertEqual(result["handshake"][0], constants.RIE_VERSION) |
218 | ebeb600f | Michael Hanselmann | AssertEqual(len(result["x509_key_name"]), 3) |
219 | ebeb600f | Michael Hanselmann | AssertIn("-----BEGIN CERTIFICATE-----", result["x509_ca"]) |
220 | ebeb600f | Michael Hanselmann | |
221 | a47f574c | Oleksiy Mishchenko | |
222 | a47f574c | Oleksiy Mishchenko | def TestNode(node): |
223 | a47f574c | Oleksiy Mishchenko | """Testing getting node(s) info via remote API.
|
224 | a47f574c | Oleksiy Mishchenko |
|
225 | a47f574c | Oleksiy Mishchenko | """
|
226 | a47f574c | Oleksiy Mishchenko | def _VerifyNode(data): |
227 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
228 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
229 | c85d3b64 | Michael Hanselmann | |
230 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesList(data): |
231 | a47f574c | Oleksiy Mishchenko | for node in data: |
232 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
233 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
234 | c85d3b64 | Michael Hanselmann | |
235 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
236 | a47f574c | Oleksiy Mishchenko | for node_data in data: |
237 | a47f574c | Oleksiy Mishchenko | _VerifyNode(node_data) |
238 | a47f574c | Oleksiy Mishchenko | |
239 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
240 | 94e63ca1 | Michael Hanselmann | ("/2/nodes/%s" % node["primary"], _VerifyNode, 'GET', None), |
241 | 94e63ca1 | Michael Hanselmann | ("/2/nodes", _VerifyNodesList, 'GET', None), |
242 | 94e63ca1 | Michael Hanselmann | ("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET', None), |
243 | a47f574c | Oleksiy Mishchenko | ]) |
244 | a47f574c | Oleksiy Mishchenko | |
245 | a47f574c | Oleksiy Mishchenko | |
246 | a47f574c | Oleksiy Mishchenko | def TestTags(kind, name, tags): |
247 | a47f574c | Oleksiy Mishchenko | """Tests .../tags resources.
|
248 | a47f574c | Oleksiy Mishchenko |
|
249 | a47f574c | Oleksiy Mishchenko | """
|
250 | a47f574c | Oleksiy Mishchenko | if kind == constants.TAG_CLUSTER:
|
251 | a5b9d725 | Iustin Pop | uri = "/2/tags"
|
252 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_NODE:
|
253 | a5b9d725 | Iustin Pop | uri = "/2/nodes/%s/tags" % name
|
254 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_INSTANCE:
|
255 | a5b9d725 | Iustin Pop | uri = "/2/instances/%s/tags" % name
|
256 | a47f574c | Oleksiy Mishchenko | else:
|
257 | a47f574c | Oleksiy Mishchenko | raise errors.ProgrammerError("Unknown tag kind") |
258 | a47f574c | Oleksiy Mishchenko | |
259 | a47f574c | Oleksiy Mishchenko | def _VerifyTags(data): |
260 | 94e63ca1 | Michael Hanselmann | AssertEqual(sorted(tags), sorted(data)) |
261 | a47f574c | Oleksiy Mishchenko | |
262 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
263 | 94e63ca1 | Michael Hanselmann | (uri, _VerifyTags, 'GET', None), |
264 | a47f574c | Oleksiy Mishchenko | ]) |
265 | 8cb70e56 | Michael Hanselmann | |
266 | 8cb70e56 | Michael Hanselmann | |
267 | 8cb70e56 | Michael Hanselmann | def _WaitForRapiJob(job_id): |
268 | 8cb70e56 | Michael Hanselmann | """Waits for a job to finish.
|
269 | 8cb70e56 | Michael Hanselmann |
|
270 | 8cb70e56 | Michael Hanselmann | """
|
271 | 8cb70e56 | Michael Hanselmann | master = qa_config.GetMasterNode() |
272 | 8cb70e56 | Michael Hanselmann | |
273 | 8cb70e56 | Michael Hanselmann | def _VerifyJob(data): |
274 | 8cb70e56 | Michael Hanselmann | AssertEqual(data["id"], job_id)
|
275 | 8cb70e56 | Michael Hanselmann | for field in JOB_FIELDS: |
276 | 8cb70e56 | Michael Hanselmann | AssertIn(field, data) |
277 | 8cb70e56 | Michael Hanselmann | |
278 | 8cb70e56 | Michael Hanselmann | _DoTests([ |
279 | 8cb70e56 | Michael Hanselmann | ("/2/jobs/%s" % job_id, _VerifyJob, "GET", None), |
280 | 8cb70e56 | Michael Hanselmann | ]) |
281 | 8cb70e56 | Michael Hanselmann | |
282 | ebeb600f | Michael Hanselmann | return rapi.client_utils.PollJob(_rapi_client, job_id,
|
283 | ebeb600f | Michael Hanselmann | cli.StdioJobPollReportCb()) |
284 | 8cb70e56 | Michael Hanselmann | |
285 | 8cb70e56 | Michael Hanselmann | |
286 | 924e95f9 | Michael Hanselmann | def TestRapiInstanceAdd(node, use_client): |
287 | 8cb70e56 | Michael Hanselmann | """Test adding a new instance via RAPI"""
|
288 | 8cb70e56 | Michael Hanselmann | instance = qa_config.AcquireInstance() |
289 | 8cb70e56 | Michael Hanselmann | try:
|
290 | 924e95f9 | Michael Hanselmann | memory = utils.ParseUnit(qa_config.get("mem"))
|
291 | 924e95f9 | Michael Hanselmann | disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")] |
292 | 924e95f9 | Michael Hanselmann | |
293 | 924e95f9 | Michael Hanselmann | if use_client:
|
294 | 924e95f9 | Michael Hanselmann | disks = [{"size": size} for size in disk_sizes] |
295 | 924e95f9 | Michael Hanselmann | nics = [{}] |
296 | 924e95f9 | Michael Hanselmann | |
297 | 924e95f9 | Michael Hanselmann | beparams = { |
298 | 924e95f9 | Michael Hanselmann | constants.BE_MEMORY: memory, |
299 | 924e95f9 | Michael Hanselmann | } |
300 | 924e95f9 | Michael Hanselmann | |
301 | 924e95f9 | Michael Hanselmann | job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE, |
302 | 924e95f9 | Michael Hanselmann | instance["name"],
|
303 | 924e95f9 | Michael Hanselmann | constants.DT_PLAIN, |
304 | 924e95f9 | Michael Hanselmann | disks, nics, |
305 | 924e95f9 | Michael Hanselmann | os=qa_config.get("os"),
|
306 | 924e95f9 | Michael Hanselmann | pnode=node["primary"],
|
307 | 924e95f9 | Michael Hanselmann | beparams=beparams) |
308 | 924e95f9 | Michael Hanselmann | else:
|
309 | 924e95f9 | Michael Hanselmann | body = { |
310 | 924e95f9 | Michael Hanselmann | "name": instance["name"], |
311 | 924e95f9 | Michael Hanselmann | "os": qa_config.get("os"), |
312 | 924e95f9 | Michael Hanselmann | "disk_template": constants.DT_PLAIN,
|
313 | 924e95f9 | Michael Hanselmann | "pnode": node["primary"], |
314 | 924e95f9 | Michael Hanselmann | "memory": memory,
|
315 | 924e95f9 | Michael Hanselmann | "disks": disk_sizes,
|
316 | 924e95f9 | Michael Hanselmann | } |
317 | 924e95f9 | Michael Hanselmann | |
318 | 924e95f9 | Michael Hanselmann | (job_id, ) = _DoTests([ |
319 | 924e95f9 | Michael Hanselmann | ("/2/instances", _VerifyReturnsJob, "POST", body), |
320 | 924e95f9 | Michael Hanselmann | ]) |
321 | 8cb70e56 | Michael Hanselmann | |
322 | 8cb70e56 | Michael Hanselmann | _WaitForRapiJob(job_id) |
323 | 8cb70e56 | Michael Hanselmann | |
324 | 8cb70e56 | Michael Hanselmann | return instance
|
325 | 8cb70e56 | Michael Hanselmann | except:
|
326 | 8cb70e56 | Michael Hanselmann | qa_config.ReleaseInstance(instance) |
327 | 8cb70e56 | Michael Hanselmann | raise
|
328 | 8cb70e56 | Michael Hanselmann | |
329 | 8cb70e56 | Michael Hanselmann | |
330 | 924e95f9 | Michael Hanselmann | def TestRapiInstanceRemove(instance, use_client): |
331 | 8cb70e56 | Michael Hanselmann | """Test removing instance via RAPI"""
|
332 | 924e95f9 | Michael Hanselmann | if use_client:
|
333 | 924e95f9 | Michael Hanselmann | job_id = _rapi_client.DeleteInstance(instance["name"])
|
334 | 924e95f9 | Michael Hanselmann | else:
|
335 | 924e95f9 | Michael Hanselmann | (job_id, ) = _DoTests([ |
336 | 924e95f9 | Michael Hanselmann | ("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None), |
337 | 924e95f9 | Michael Hanselmann | ]) |
338 | 8cb70e56 | Michael Hanselmann | |
339 | 8cb70e56 | Michael Hanselmann | _WaitForRapiJob(job_id) |
340 | 8cb70e56 | Michael Hanselmann | |
341 | 8cb70e56 | Michael Hanselmann | qa_config.ReleaseInstance(instance) |
342 | 5d831182 | Michael Hanselmann | |
343 | 5d831182 | Michael Hanselmann | |
344 | 5d831182 | Michael Hanselmann | def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode): |
345 | 5d831182 | Michael Hanselmann | """Test tools/move-instance"""
|
346 | 5d831182 | Michael Hanselmann | master = qa_config.GetMasterNode() |
347 | 5d831182 | Michael Hanselmann | |
348 | 5d831182 | Michael Hanselmann | rapi_pw_file = tempfile.NamedTemporaryFile() |
349 | 5d831182 | Michael Hanselmann | rapi_pw_file.write(_rapi_password) |
350 | 5d831182 | Michael Hanselmann | rapi_pw_file.flush() |
351 | 5d831182 | Michael Hanselmann | |
352 | 5d831182 | Michael Hanselmann | # TODO: Run some instance tests before moving back
|
353 | 5d831182 | Michael Hanselmann | for srcname, destname in [(src_instance["name"], dest_instance["name"]), |
354 | 5d831182 | Michael Hanselmann | (dest_instance["name"], src_instance["name"])]: |
355 | 5d831182 | Michael Hanselmann | cmd = [ |
356 | 5d831182 | Michael Hanselmann | "../tools/move-instance",
|
357 | 5d831182 | Michael Hanselmann | "--verbose",
|
358 | 5d831182 | Michael Hanselmann | "--src-ca-file=%s" % _rapi_ca.name,
|
359 | 5d831182 | Michael Hanselmann | "--src-username=%s" % _rapi_username,
|
360 | 5d831182 | Michael Hanselmann | "--src-password-file=%s" % rapi_pw_file.name,
|
361 | 5d831182 | Michael Hanselmann | "--dest-instance-name=%s" % destname,
|
362 | 5d831182 | Michael Hanselmann | "--dest-primary-node=%s" % pnode["primary"], |
363 | 5d831182 | Michael Hanselmann | "--dest-secondary-node=%s" % snode["primary"], |
364 | 5d831182 | Michael Hanselmann | |
365 | 5d831182 | Michael Hanselmann | master["primary"],
|
366 | 5d831182 | Michael Hanselmann | master["primary"],
|
367 | 5d831182 | Michael Hanselmann | srcname, |
368 | 5d831182 | Michael Hanselmann | ] |
369 | 5d831182 | Michael Hanselmann | |
370 | 5d831182 | Michael Hanselmann | AssertEqual(StartLocalCommand(cmd).wait(), 0) |