Revision 94e63ca1
b/qa/qa_rapi.py | ||
---|---|---|
83 | 83 |
|
84 | 84 |
""" |
85 | 85 |
|
86 |
def __init__(self, url, data=None, headers={}, origin_req_host=None, |
|
87 |
unverifiable=False, method="GET"): |
|
88 |
urllib2.Request.__init__(self, url, data, headers, origin_req_host, |
|
89 |
unverifiable) |
|
86 |
def __init__(self, method, url, headers, data): |
|
87 |
urllib2.Request.__init__(self, url, data=data, headers=headers) |
|
90 | 88 |
self._method = method |
91 | 89 |
|
92 | 90 |
def get_method(self): |
... | ... | |
104 | 102 |
"mtotal", "mnode", "mfree", |
105 | 103 |
"pinst_cnt", "sinst_cnt", "tags") |
106 | 104 |
|
105 |
JOB_FIELDS = frozenset([ |
|
106 |
"id", "ops", "status", "summary", |
|
107 |
"opstatus", "opresult", "oplog", |
|
108 |
"received_ts", "start_ts", "end_ts", |
|
109 |
]) |
|
110 |
|
|
107 | 111 |
LIST_FIELDS = ("id", "uri") |
108 | 112 |
|
109 | 113 |
|
... | ... | |
118 | 122 |
master = qa_config.GetMasterNode() |
119 | 123 |
host = master["primary"] |
120 | 124 |
port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT) |
125 |
results = [] |
|
121 | 126 |
|
122 |
for uri, verify, method in uris: |
|
127 |
for uri, verify, method, body in uris:
|
|
123 | 128 |
assert uri.startswith("/") |
124 | 129 |
|
125 | 130 |
url = "https://%s:%s%s" % (host, port, uri) |
126 | 131 |
|
127 |
print "Testing %s ..." % url |
|
132 |
headers = {} |
|
133 |
|
|
134 |
if body: |
|
135 |
data = serializer.DumpJson(body, indent=False) |
|
136 |
headers["Content-Type"] = "application/json" |
|
137 |
else: |
|
138 |
data = None |
|
139 |
|
|
140 |
if headers or data: |
|
141 |
details = [] |
|
142 |
if headers: |
|
143 |
details.append("headers=%s" % |
|
144 |
serializer.DumpJson(headers, indent=False).rstrip()) |
|
145 |
if data: |
|
146 |
details.append("data=%s" % data.rstrip()) |
|
147 |
info = "(%s)" % (", ".join(details), ) |
|
148 |
else: |
|
149 |
info = "" |
|
128 | 150 |
|
129 |
req = RapiRequest(url, method=method) |
|
151 |
print "Testing %s %s %s..." % (method, url, info) |
|
152 |
|
|
153 |
req = RapiRequest(method, url, headers, data) |
|
130 | 154 |
response = OpenerFactory.Opener().open(req) |
131 | 155 |
|
132 | 156 |
AssertEqual(response.info()["Content-type"], "application/json") |
... | ... | |
139 | 163 |
else: |
140 | 164 |
AssertEqual(data, verify) |
141 | 165 |
|
166 |
results.append(data) |
|
167 |
|
|
168 |
return results |
|
169 |
|
|
170 |
|
|
171 |
def _VerifyReturnsJob(data): |
|
172 |
AssertMatch(data, r'^\d+$') |
|
173 |
|
|
142 | 174 |
|
143 | 175 |
def TestVersion(): |
144 | 176 |
"""Testing remote API version. |
145 | 177 |
|
146 | 178 |
""" |
147 | 179 |
_DoTests([ |
148 |
("/version", constants.RAPI_VERSION, 'GET'), |
|
180 |
("/version", constants.RAPI_VERSION, 'GET', None),
|
|
149 | 181 |
]) |
150 | 182 |
|
151 | 183 |
|
... | ... | |
153 | 185 |
"""Testing remote API on an empty cluster. |
154 | 186 |
|
155 | 187 |
""" |
156 |
master_name = qa_config.GetMasterNode()["primary"] |
|
188 |
master = qa_config.GetMasterNode() |
|
189 |
master_full = qa_utils.ResolveNodeName(master) |
|
157 | 190 |
|
158 | 191 |
def _VerifyInfo(data): |
159 | 192 |
AssertIn("name", data) |
160 | 193 |
AssertIn("master", data) |
161 |
AssertEqual(data["master"], master_name)
|
|
194 |
AssertEqual(data["master"], master_full)
|
|
162 | 195 |
|
163 | 196 |
def _VerifyNodes(data): |
164 | 197 |
master_entry = { |
165 |
"id": master_name,
|
|
166 |
"uri": "/2/nodes/%s" % master_name,
|
|
198 |
"id": master_full,
|
|
199 |
"uri": "/2/nodes/%s" % master_full,
|
|
167 | 200 |
} |
168 | 201 |
AssertIn(master_entry, data) |
169 | 202 |
|
... | ... | |
173 | 206 |
AssertIn(entry, node) |
174 | 207 |
|
175 | 208 |
_DoTests([ |
176 |
("/", None, 'GET'), |
|
177 |
("/2/info", _VerifyInfo, 'GET'), |
|
178 |
("/2/tags", None, 'GET'), |
|
179 |
("/2/nodes", _VerifyNodes, 'GET'), |
|
180 |
("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET'), |
|
181 |
("/2/instances", [], 'GET'), |
|
182 |
("/2/instances?bulk=1", [], 'GET'), |
|
183 |
("/2/os", None, 'GET'), |
|
209 |
("/", None, 'GET', None),
|
|
210 |
("/2/info", _VerifyInfo, 'GET', None),
|
|
211 |
("/2/tags", None, 'GET', None),
|
|
212 |
("/2/nodes", _VerifyNodes, 'GET', None),
|
|
213 |
("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET', None),
|
|
214 |
("/2/instances", [], 'GET', None),
|
|
215 |
("/2/instances?bulk=1", [], 'GET', None),
|
|
216 |
("/2/os", None, 'GET', None),
|
|
184 | 217 |
]) |
185 | 218 |
|
186 | 219 |
|
... | ... | |
201 | 234 |
for instance_data in data: |
202 | 235 |
_VerifyInstance(instance_data) |
203 | 236 |
|
204 |
def _VerifyReturnsJob(data): |
|
205 |
AssertMatch(data, r'^\d+$') |
|
206 |
|
|
207 | 237 |
_DoTests([ |
208 |
("/2/instances/%s" % instance["name"], _VerifyInstance, 'GET'), |
|
209 |
("/2/instances", _VerifyInstancesList, 'GET'), |
|
210 |
("/2/instances?bulk=1", _VerifyInstancesBulk, 'GET'), |
|
211 |
("/2/instances/%s/activate-disks" % instance["name"], _VerifyReturnsJob, 'PUT'), |
|
212 |
("/2/instances/%s/deactivate-disks" % instance["name"], _VerifyReturnsJob, 'PUT'), |
|
238 |
("/2/instances/%s" % instance["name"], _VerifyInstance, 'GET', None), |
|
239 |
("/2/instances", _VerifyInstancesList, 'GET', None), |
|
240 |
("/2/instances?bulk=1", _VerifyInstancesBulk, 'GET', None), |
|
241 |
("/2/instances/%s/activate-disks" % instance["name"], |
|
242 |
_VerifyReturnsJob, 'PUT', None), |
|
243 |
("/2/instances/%s/deactivate-disks" % instance["name"], |
|
244 |
_VerifyReturnsJob, 'PUT', None), |
|
213 | 245 |
]) |
214 | 246 |
|
215 | 247 |
|
... | ... | |
231 | 263 |
_VerifyNode(node_data) |
232 | 264 |
|
233 | 265 |
_DoTests([ |
234 |
("/2/nodes/%s" % node["primary"], _VerifyNode, 'GET'), |
|
235 |
("/2/nodes", _VerifyNodesList, 'GET'), |
|
236 |
("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET'), |
|
266 |
("/2/nodes/%s" % node["primary"], _VerifyNode, 'GET', None),
|
|
267 |
("/2/nodes", _VerifyNodesList, 'GET', None),
|
|
268 |
("/2/nodes?bulk=1", _VerifyNodesBulk, 'GET', None),
|
|
237 | 269 |
]) |
238 | 270 |
|
239 | 271 |
|
... | ... | |
251 | 283 |
raise errors.ProgrammerError("Unknown tag kind") |
252 | 284 |
|
253 | 285 |
def _VerifyTags(data): |
254 |
# Create copies to modify |
|
255 |
should = tags[:] |
|
256 |
should.sort() |
|
257 |
|
|
258 |
returned = data[:] |
|
259 |
returned.sort() |
|
260 |
AssertEqual(should, returned) |
|
286 |
AssertEqual(sorted(tags), sorted(data)) |
|
261 | 287 |
|
262 | 288 |
_DoTests([ |
263 |
(uri, _VerifyTags, 'GET'), |
|
289 |
(uri, _VerifyTags, 'GET', None),
|
|
264 | 290 |
]) |
Also available in: Unified diff