gdp / apps / rest-test / gdp-rest-testcases.py @ master
History | View | Annotate | Download (31.3 KB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
#
|
3 |
# RESTful interface to GDP - Test Suite
|
4 |
#
|
5 |
# ----- BEGIN LICENSE BLOCK -----
|
6 |
# Applications for the Global Data Plane
|
7 |
# From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
|
8 |
#
|
9 |
# Copyright (c) 2017, Regents of the University of California.
|
10 |
# All rights reserved.
|
11 |
#
|
12 |
# Permission is hereby granted, without written agreement and without
|
13 |
# license or royalty fees, to use, copy, modify, and distribute this
|
14 |
# software and its documentation for any purpose, provided that the above
|
15 |
# copyright notice and the following two paragraphs appear in all copies
|
16 |
# of this software.
|
17 |
#
|
18 |
# IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
|
19 |
# SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
|
20 |
# PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
|
21 |
# EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22 |
#
|
23 |
# REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
24 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25 |
# FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
|
26 |
# IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
|
27 |
# OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
28 |
# OR MODIFICATIONS.
|
29 |
# ----- END LICENSE BLOCK -----
|
30 |
|
31 |
import os |
32 |
import sys |
33 |
import requests |
34 |
import json |
35 |
import fcntl |
36 |
import re |
37 |
import socket |
38 |
import subprocess |
39 |
|
40 |
#
|
41 |
# sanity check invocations
|
42 |
#
|
43 |
testbed = socket.gethostname() |
44 |
if testbed != "gdp-rest-01": |
45 |
print "host is {}".format(testbed) |
46 |
print "Error: this script is only safe to run on the RESTful server" |
47 |
sys.exit(1)
|
48 |
|
49 |
#
|
50 |
# Monitor the gdp-rest-v2.log for diagnostic detail
|
51 |
#
|
52 |
log_path = "/var/log/gdp/gdp-rest-v2.log"
|
53 |
log = open(log_path)
|
54 |
log.seek(0, os.SEEK_END)
|
55 |
log_fd = log.fileno() |
56 |
flags = fcntl.fcntl(log_fd, fcntl.F_GETFL) |
57 |
fcntl.fcntl(log_fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) |
58 |
|
59 |
# dev null to silence subprocess output
|
60 |
dn = open("/dev/null", "w") |
61 |
|
62 |
test_auth = None
|
63 |
#
|
64 |
# Create a temporary test account on gdp-rest-01 (do not use sample strings):
|
65 |
#
|
66 |
# $cat /etc/lighttpd/.plainauth
|
67 |
# your_unique_testuser:your_unique_testpassword
|
68 |
# [other_permanent_user_accounts_left_untouched]
|
69 |
# $
|
70 |
#
|
71 |
# ...fill in test_auth to match the above, and uncomment it
|
72 |
#
|
73 |
# test_auth = ("your_unique_testuser", "your_unique_testpassword")
|
74 |
|
75 |
if test_auth == None: |
76 |
print "Error: modify gdp-rest-testcases.py to use a temporary test account" |
77 |
sys.exit(1)
|
78 |
|
79 |
json_header = { 'Content-type': 'application/json' } |
80 |
|
81 |
# clean up test logs (defined to be gdp-rest-01 local logs), while
|
82 |
# being careful to only remove keys which go with test logs, as all
|
83 |
# other keys are for real logs located in the real GDP.
|
84 |
def clean_glogs_and_keys(): |
85 |
output = subprocess.check_output([ "sudo", "-g", "gdp", "-u", "gdp", |
86 |
"/usr/bin/find",
|
87 |
"/var/swarm/gdp/glogs/",
|
88 |
"-type", "f", "-name", "*.glog" ]) |
89 |
|
90 |
lines = output.splitlines() |
91 |
for line in lines: |
92 |
# find <glog_id> in /var/swarm/gdp/glogs/<glog_id>.glog
|
93 |
glog_id = line[25:-5] |
94 |
# check expectations, where file removal is involved
|
95 |
if len(glog_id) == 43: |
96 |
print "Info: remove local GCL {}...".format(glog_id), |
97 |
subprocess.call([ "sudo", "-g", "gdp", "-u", "gdp", |
98 |
"/usr/bin/find", "/var/swarm/gdp/glogs/", |
99 |
"-type", "f", "-name", glog_id + "*", |
100 |
"-exec", "/bin/rm", "-f", "{}", ";"]) |
101 |
print "done" |
102 |
print "Info: remove local key {}...".format(glog_id), |
103 |
subprocess.call([ "sudo", "-g", "gdp", "-u", "gdp", |
104 |
"/usr/bin/find", "/etc/gdp/keys/", |
105 |
"-type", "f", "-name", glog_id + ".pem", |
106 |
"-exec", "/bin/rm", "-f", "{}", ";"]) |
107 |
print "done" |
108 |
else:
|
109 |
print "Error: cleanup has unexpected glog_id: {}".format(glog_id) |
110 |
|
111 |
def page_display(p): |
112 |
if p != None: |
113 |
print "STATUS:" |
114 |
print p.status_code
|
115 |
print "HEADERS:" |
116 |
print p.headers
|
117 |
print "CONTENT:" |
118 |
print p.content
|
119 |
else:
|
120 |
print "Error: no page" |
121 |
#
|
122 |
|
123 |
def failed_page_display(p): |
124 |
print "FAILED" |
125 |
print "DIAGNOSTICS:" |
126 |
page_display(p) |
127 |
print "END DIAGNOSTICS" |
128 |
#
|
129 |
|
130 |
def failed_log_and_page_display(p, l): |
131 |
print "FAILURE DIAGNOSTICS:" |
132 |
print "==== gdp-rest-v2.log:" |
133 |
print l.read(-1) |
134 |
print "==== end" |
135 |
|
136 |
print "==== response page:" |
137 |
page_display(p) |
138 |
print "==== end" |
139 |
print "END DIAGNOSTICS" |
140 |
#
|
141 |
|
142 |
def test_write(tc, tid, gid, rn): |
143 |
json_body = { |
144 |
tid : rn, |
145 |
"gcl_id" : gid
|
146 |
} |
147 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl/" +
|
148 |
gid, |
149 |
auth = test_auth, |
150 |
timeout = 60,
|
151 |
headers = json_header, |
152 |
data = json.dumps(json_body)) |
153 |
print "{} WRITE {}".format(tc, rn), |
154 |
if page.status_code == 200: |
155 |
print "" |
156 |
return True |
157 |
else:
|
158 |
failed_page_display(page) |
159 |
return False |
160 |
#
|
161 |
|
162 |
def test_read(tc, tid, gid, rn): |
163 |
page = requests.get("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl/" +
|
164 |
gid + "?recno=" + rn,
|
165 |
auth = test_auth, |
166 |
timeout = 60)
|
167 |
pj = page.json() |
168 |
print "{} READ {}".format(tc, rn), |
169 |
passed = False
|
170 |
if page.status_code == 200 and pj[tid] == rn: |
171 |
print "" |
172 |
return True |
173 |
else:
|
174 |
failed_page_display(page) |
175 |
return False |
176 |
#
|
177 |
|
178 |
def test_log(tc, tid, gcl_id): |
179 |
print "{} GCL {} write and read".format(tc, gcl_id) |
180 |
|
181 |
if (test_write(tc, tid, gcl_id, "1") and |
182 |
test_write(tc, tid, gcl_id, "2") and |
183 |
test_write(tc, tid, gcl_id, "3") and |
184 |
test_read(tc, tid, gcl_id, "3") and |
185 |
test_read(tc, tid, gcl_id, "2") and |
186 |
test_read(tc, tid, gcl_id, "1")):
|
187 |
print "{} PASSED".format(tc) |
188 |
else:
|
189 |
print "{} FAILED GCL write and read".format(tc) |
190 |
#
|
191 |
|
192 |
#
|
193 |
# HTTP PUT TESTS
|
194 |
#
|
195 |
|
196 |
def test_put_01(): |
197 |
log.seek(0, os.SEEK_END)
|
198 |
test_case = "TEST PUT 01:"
|
199 |
test_id = "test_put_01_log"
|
200 |
print "{} HTTP PUT new log".format(test_case) |
201 |
|
202 |
|
203 |
json_body = { |
204 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_01" |
205 |
} |
206 |
|
207 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
208 |
auth = test_auth, |
209 |
timeout = 60,
|
210 |
headers = json_header, |
211 |
data = json.dumps(json_body)) |
212 |
if page.status_code == 201: |
213 |
pj = page.json() |
214 |
gcl_name = pj["gcl_name"]
|
215 |
# DEPRECATED gdplogd_name retrieval code block
|
216 |
# gdplogd_name = pj["gdplogd_name"]
|
217 |
# if gcl_name != None and gdplogd_name != None:
|
218 |
# print "{} PASSED \"{}\" \"{}\"".format(test_case,
|
219 |
# gcl_name, gdplogd_name)
|
220 |
# test_log(test_case, test_id, gcl_name)
|
221 |
# else:
|
222 |
# print "{} FAILED page: \"{}\" \"{}\"".format(test_case,
|
223 |
# gcl_name, gdplogd_name)
|
224 |
# failed_log_and_page_display(page, log)
|
225 |
# END DEPRECATED gdplogd_name retrieval code block
|
226 |
if gcl_name != None: |
227 |
print "{} PASSED \"{}\"".format(test_case, gcl_name) |
228 |
test_log(test_case, test_id, gcl_name) |
229 |
else:
|
230 |
print "{} FAILED page: \"{}\"".format(test_case, gcl_name) |
231 |
failed_log_and_page_display(page, log) |
232 |
else:
|
233 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
234 |
failed_log_and_page_display(page, log) |
235 |
#
|
236 |
|
237 |
def test_put_02(): |
238 |
log.seek(0, os.SEEK_END)
|
239 |
test_case = "TEST PUT 02:"
|
240 |
print "{} HTTP PUT existing log (from TEST PUT 01)".format(test_case) |
241 |
|
242 |
json_body = { |
243 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_01" |
244 |
} |
245 |
|
246 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
247 |
auth = test_auth, |
248 |
timeout = 60,
|
249 |
headers = json_header, |
250 |
data = json.dumps(json_body)) |
251 |
if page.status_code == 409: |
252 |
pj = page.json() |
253 |
detail = pj["detail"]
|
254 |
if detail == "external-name already exists on gdplogd server": |
255 |
print "{} PASSED \"{}\"".format(test_case, detail) |
256 |
else:
|
257 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
258 |
failed_log_and_page_display(page, log) |
259 |
|
260 |
else:
|
261 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
262 |
failed_log_and_page_display(page, log) |
263 |
#
|
264 |
|
265 |
def test_put_03(): |
266 |
log.seek(0, os.SEEK_END)
|
267 |
test_case = "TEST PUT 03:"
|
268 |
print "{} HTTP PUT with no external-name".format(test_case) |
269 |
|
270 |
json_body = { |
271 |
"NO-external-name" : "edu.berkeley.eecs.gdp-rest.test_put_03" |
272 |
} |
273 |
|
274 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
275 |
auth = test_auth, |
276 |
timeout = 60,
|
277 |
headers = json_header, |
278 |
data = json.dumps(json_body)) |
279 |
if page.status_code == 400: |
280 |
pj = page.json() |
281 |
detail = pj["detail"]
|
282 |
if detail == "mandatory external-name not found": |
283 |
print "{} PASSED \"{}\"".format(test_case, detail) |
284 |
else:
|
285 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
286 |
failed_log_and_page_display(page, log) |
287 |
|
288 |
else:
|
289 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
290 |
failed_log_and_page_display(page, log) |
291 |
#
|
292 |
|
293 |
def test_put_04(): |
294 |
log.seek(0, os.SEEK_END)
|
295 |
test_case = "TEST PUT 04:"
|
296 |
print "{} HTTP PUT with no request body".format(test_case) |
297 |
|
298 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
299 |
auth = test_auth, |
300 |
timeout = 60,
|
301 |
headers = json_header) |
302 |
if page.status_code == 400: |
303 |
pj = page.json() |
304 |
detail = pj["detail"]
|
305 |
if detail == "request body not recognized json format": |
306 |
print "{} PASSED \"{}\"".format(test_case, detail) |
307 |
else:
|
308 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
309 |
failed_log_and_page_display(page, log) |
310 |
|
311 |
else:
|
312 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
313 |
failed_log_and_page_display(page, log) |
314 |
#
|
315 |
|
316 |
def test_put_05(): |
317 |
log.seek(0, os.SEEK_END)
|
318 |
test_case = "TEST PUT 05:"
|
319 |
print "{} HTTP PUT with no request header or body".format(test_case) |
320 |
|
321 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
322 |
auth = test_auth, |
323 |
timeout = 60)
|
324 |
if page.status_code == 400: |
325 |
pj = page.json() |
326 |
detail = pj["detail"]
|
327 |
if detail == "request body not recognized json format": |
328 |
print "{} PASSED \"{}\"".format(test_case, detail) |
329 |
else:
|
330 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
331 |
failed_log_and_page_display(page, log) |
332 |
|
333 |
else:
|
334 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
335 |
failed_log_and_page_display(page, log) |
336 |
#
|
337 |
|
338 |
def test_put_06(): |
339 |
log.seek(0, os.SEEK_END)
|
340 |
test_case = "TEST PUT 06:"
|
341 |
test_id = "test_put_06_log"
|
342 |
print "{} HTTP PUT new log, verify all valid options".format(test_case) |
343 |
|
344 |
json_body = { |
345 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_06", |
346 |
"-C" : "swarmlab@berkeley.edu", |
347 |
"-h" : "sha224", |
348 |
"-k" : "dsa", |
349 |
"-b" : "1024", |
350 |
"-c" : "ignored_for_dsa", |
351 |
"META" : [ "meta1=foo", "meta2=bar" ], |
352 |
} |
353 |
|
354 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
355 |
auth = test_auth, |
356 |
timeout = 60,
|
357 |
headers = json_header, |
358 |
data = json.dumps(json_body)) |
359 |
if page.status_code == 201: |
360 |
pj = page.json() |
361 |
gcl_name = pj["gcl_name"]
|
362 |
# DEPRECATED gdplogd_name retrieval code block
|
363 |
# gdplogd_name = pj["gdplogd_name"]
|
364 |
# if gcl_name != None and gdplogd_name != None:
|
365 |
# print "{} PASSED \"{}\" \"{}\"".format(test_case,
|
366 |
# gcl_name, gdplogd_name)
|
367 |
# test_log(test_case, test_id, gcl_name)
|
368 |
# else:
|
369 |
# print "{} FAILED page: \"{}\" \"{}\"".format(test_case,
|
370 |
# gcl_name, gdplogd_name)
|
371 |
# failed_log_and_page_display(page, log)
|
372 |
# END DEPRECATED gdplogd_name retrieval code block
|
373 |
if gcl_name != None: |
374 |
print "{} PASSED \"{}\"".format(test_case, gcl_name) |
375 |
test_log(test_case, test_id, gcl_name) |
376 |
else:
|
377 |
print "{} FAILED page: \"{}\"".format(test_case, gcl_name) |
378 |
failed_log_and_page_display(page, log) |
379 |
else:
|
380 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
381 |
failed_log_and_page_display(page, log) |
382 |
#
|
383 |
|
384 |
#
|
385 |
# server controlled options -e, -S, -K should not be accessible to clients
|
386 |
#
|
387 |
|
388 |
def test_put_07(): |
389 |
log.seek(0, os.SEEK_END)
|
390 |
test_case = "TEST PUT 07:"
|
391 |
print "{} HTTP PUT create log, -e option is not permitted".format(test_case) |
392 |
|
393 |
json_body = { |
394 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_07", |
395 |
"-e" : "none" |
396 |
} |
397 |
|
398 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
399 |
auth = test_auth, |
400 |
timeout = 60,
|
401 |
headers = json_header, |
402 |
data = json.dumps(json_body)) |
403 |
if page.status_code == 400: |
404 |
pj = page.json() |
405 |
detail = pj["detail"]
|
406 |
if detail == "request contains unrecognized json objects": |
407 |
print "{} PASSED \"{}\"".format(test_case, detail) |
408 |
else:
|
409 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
410 |
failed_log_and_page_display(page, log) |
411 |
|
412 |
else:
|
413 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
414 |
failed_log_and_page_display(page, log) |
415 |
#
|
416 |
|
417 |
def test_put_08(): |
418 |
log.seek(0, os.SEEK_END)
|
419 |
test_case = "TEST PUT 09:"
|
420 |
print "{} HTTP PUT create log, -S option is not permitted".format(test_case) |
421 |
|
422 |
json_body = { |
423 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_08", |
424 |
"-S" : None |
425 |
} |
426 |
|
427 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
428 |
auth = test_auth, |
429 |
timeout = 60,
|
430 |
headers = json_header, |
431 |
data = json.dumps(json_body)) |
432 |
if page.status_code == 400: |
433 |
pj = page.json() |
434 |
detail = pj["detail"]
|
435 |
if detail == "request contains unrecognized json objects": |
436 |
print "{} PASSED \"{}\"".format(test_case, detail) |
437 |
else:
|
438 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
439 |
failed_log_and_page_display(page, log) |
440 |
|
441 |
else:
|
442 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
443 |
failed_log_and_page_display(page, log) |
444 |
#
|
445 |
|
446 |
def test_put_09(): |
447 |
log.seek(0, os.SEEK_END)
|
448 |
test_case = "TEST PUT 09:"
|
449 |
print "{} HTTP PUT create log, -K option is not permitted".format(test_case) |
450 |
|
451 |
json_body = { |
452 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_09", |
453 |
"-K" : "/etc/gdp/keys" |
454 |
} |
455 |
|
456 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
457 |
auth = test_auth, |
458 |
timeout = 60,
|
459 |
headers = json_header, |
460 |
data = json.dumps(json_body)) |
461 |
if page.status_code == 400: |
462 |
pj = page.json() |
463 |
detail = pj["detail"]
|
464 |
if detail == "request contains unrecognized json objects": |
465 |
print "{} PASSED \"{}\"".format(test_case, detail) |
466 |
else:
|
467 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
468 |
failed_log_and_page_display(page, log) |
469 |
|
470 |
else:
|
471 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
472 |
failed_log_and_page_display(page, log) |
473 |
#
|
474 |
|
475 |
#
|
476 |
# unsupported options -G, -q, -s, -w, -W should not be accessible to clients
|
477 |
#
|
478 |
|
479 |
def test_put_10(): |
480 |
log.seek(0, os.SEEK_END)
|
481 |
test_case = "TEST PUT 10:"
|
482 |
print "{} HTTP PUT create log, -G option is not permitted".format(test_case) |
483 |
|
484 |
json_body = { |
485 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_10", |
486 |
"-G" : "127.0.0.1" |
487 |
} |
488 |
|
489 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
490 |
auth = test_auth, |
491 |
timeout = 60,
|
492 |
headers = json_header, |
493 |
data = json.dumps(json_body)) |
494 |
if page.status_code == 400: |
495 |
pj = page.json() |
496 |
detail = pj["detail"]
|
497 |
if detail == "request contains unrecognized json objects": |
498 |
print "{} PASSED \"{}\"".format(test_case, detail) |
499 |
else:
|
500 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
501 |
failed_log_and_page_display(page, log) |
502 |
|
503 |
else:
|
504 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
505 |
failed_log_and_page_display(page, log) |
506 |
#
|
507 |
|
508 |
def test_put_11(): |
509 |
log.seek(0, os.SEEK_END)
|
510 |
test_case = "TEST PUT 11:"
|
511 |
print "{} HTTP PUT create log, -q option is not permitted".format(test_case) |
512 |
|
513 |
json_body = { |
514 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_11", |
515 |
"-q" : None |
516 |
} |
517 |
|
518 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
519 |
auth = test_auth, |
520 |
timeout = 60,
|
521 |
headers = json_header, |
522 |
data = json.dumps(json_body)) |
523 |
if page.status_code == 400: |
524 |
pj = page.json() |
525 |
detail = pj["detail"]
|
526 |
if detail == "request contains unrecognized json objects": |
527 |
print "{} PASSED \"{}\"".format(test_case, detail) |
528 |
else:
|
529 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
530 |
failed_log_and_page_display(page, log) |
531 |
|
532 |
else:
|
533 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
534 |
failed_log_and_page_display(page, log) |
535 |
#
|
536 |
|
537 |
def test_put_12(): |
538 |
log.seek(0, os.SEEK_END)
|
539 |
test_case = "TEST PUT 12:"
|
540 |
print "{} HTTP PUT create log, -s option is not permitted".format(test_case) |
541 |
|
542 |
json_body = { |
543 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_12", |
544 |
"-s" : "edu.berkeley.eecs.service.creation" |
545 |
} |
546 |
|
547 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
548 |
auth = test_auth, |
549 |
timeout = 60,
|
550 |
headers = json_header, |
551 |
data = json.dumps(json_body)) |
552 |
if page.status_code == 400: |
553 |
pj = page.json() |
554 |
detail = pj["detail"]
|
555 |
if detail == "request contains unrecognized json objects": |
556 |
print "{} PASSED \"{}\"".format(test_case, detail) |
557 |
else:
|
558 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
559 |
failed_log_and_page_display(page, log) |
560 |
|
561 |
else:
|
562 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
563 |
failed_log_and_page_display(page, log) |
564 |
#
|
565 |
|
566 |
def test_put_13(): |
567 |
log.seek(0, os.SEEK_END)
|
568 |
test_case = "TEST PUT 13:"
|
569 |
print "{} HTTP PUT create log, -w option is not permitted".format(test_case) |
570 |
|
571 |
json_body = { |
572 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_13", |
573 |
"-w" : None |
574 |
} |
575 |
|
576 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
577 |
auth = test_auth, |
578 |
timeout = 60,
|
579 |
headers = json_header, |
580 |
data = json.dumps(json_body)) |
581 |
if page.status_code == 400: |
582 |
pj = page.json() |
583 |
detail = pj["detail"]
|
584 |
if detail == "request contains unrecognized json objects": |
585 |
print "{} PASSED \"{}\"".format(test_case, detail) |
586 |
else:
|
587 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
588 |
failed_log_and_page_display(page, log) |
589 |
|
590 |
else:
|
591 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
592 |
failed_log_and_page_display(page, log) |
593 |
#
|
594 |
|
595 |
def test_put_14(): |
596 |
log.seek(0, os.SEEK_END)
|
597 |
test_case = "TEST PUT 14:"
|
598 |
print "{} HTTP PUT create log, -W option is not permitted".format(test_case) |
599 |
|
600 |
json_body = { |
601 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_14", |
602 |
"-W" : "/etc/gdp/keys" |
603 |
} |
604 |
|
605 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
606 |
auth = test_auth, |
607 |
timeout = 60,
|
608 |
headers = json_header, |
609 |
data = json.dumps(json_body)) |
610 |
if page.status_code == 400: |
611 |
pj = page.json() |
612 |
detail = pj["detail"]
|
613 |
if detail == "request contains unrecognized json objects": |
614 |
print "{} PASSED \"{}\"".format(test_case, detail) |
615 |
else:
|
616 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
617 |
failed_log_and_page_display(page, log) |
618 |
|
619 |
else:
|
620 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
621 |
failed_log_and_page_display(page, log) |
622 |
#
|
623 |
|
624 |
def test_put_15(): |
625 |
log.seek(0, os.SEEK_END)
|
626 |
test_case = "TEST PUT 15:"
|
627 |
print "{} HTTP PUT create log, META list is None(s)".format(test_case) |
628 |
|
629 |
json_body = { |
630 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_15", |
631 |
"META" : None |
632 |
} |
633 |
|
634 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
635 |
auth = test_auth, |
636 |
timeout = 60,
|
637 |
headers = json_header, |
638 |
data = json.dumps(json_body)) |
639 |
if page.status_code == 400: |
640 |
pj = page.json() |
641 |
detail = pj["detail"]
|
642 |
if detail == "request contains unrecognized json objects": |
643 |
print "{} PASSED \"{}\"".format(test_case, detail) |
644 |
else:
|
645 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
646 |
failed_log_and_page_display(page, log) |
647 |
|
648 |
else:
|
649 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
650 |
failed_log_and_page_display(page, log) |
651 |
#
|
652 |
|
653 |
def test_put_16(): |
654 |
log.seek(0, os.SEEK_END)
|
655 |
test_case = "TEST PUT 16:"
|
656 |
print "{} HTTP PUT create log, META list element bad(s)".format(test_case) |
657 |
|
658 |
json_body = { |
659 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_put_16", |
660 |
"META" : [ "foo=1", "missing_equal", "bar=2" ], |
661 |
} |
662 |
|
663 |
page = requests.put("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
664 |
auth = test_auth, |
665 |
timeout = 60,
|
666 |
headers = json_header, |
667 |
data = json.dumps(json_body)) |
668 |
if page.status_code == 400: |
669 |
pj = page.json() |
670 |
detail = pj["detail"]
|
671 |
if detail == "request contains unrecognized json objects": |
672 |
print "{} PASSED \"{}\"".format(test_case, detail) |
673 |
else:
|
674 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
675 |
failed_log_and_page_display(page, log) |
676 |
|
677 |
else:
|
678 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
679 |
failed_log_and_page_display(page, log) |
680 |
#
|
681 |
|
682 |
#
|
683 |
# HTTP POST TESTS
|
684 |
#
|
685 |
|
686 |
def test_post_01(): |
687 |
log.seek(0, os.SEEK_END)
|
688 |
test_case = "TEST POST 01:"
|
689 |
test_id = "test_post_01_log"
|
690 |
print "{} HTTP POST new log".format(test_case) |
691 |
|
692 |
|
693 |
json_body = { |
694 |
"external-name" : None |
695 |
} |
696 |
|
697 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
698 |
auth = test_auth, |
699 |
timeout = 60,
|
700 |
headers = json_header, |
701 |
data = json.dumps(json_body)) |
702 |
if page.status_code == 201: |
703 |
pj = page.json() |
704 |
gcl_name = pj["gcl_name"]
|
705 |
# DEPRECATED gdplogd_name retrieval code block
|
706 |
# gdplogd_name = pj["gdplogd_name"]
|
707 |
# if gcl_name != None and gdplogd_name != None:
|
708 |
# print "{} PASSED \"{}\" \"{}\"".format(test_case,
|
709 |
# gcl_name, gdplogd_name)
|
710 |
# test_log(test_case, test_id, gcl_name)
|
711 |
# else:
|
712 |
# print "{} FAILED page: \"{}\" \"{}\"".format(test_case,
|
713 |
# gcl_name, gdplogd_name)
|
714 |
# failed_log_and_page_display(page, log)
|
715 |
# END DEPRECATED gdplogd_name retrieval code block
|
716 |
if gcl_name != None: |
717 |
print "{} PASSED \"{}\"".format(test_case, gcl_name) |
718 |
test_log(test_case, test_id, gcl_name) |
719 |
else:
|
720 |
print "{} FAILED page: \"{}\"".format(test_case, gcl_name) |
721 |
failed_log_and_page_display(page, log) |
722 |
else:
|
723 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
724 |
failed_log_and_page_display(page, log) |
725 |
#
|
726 |
|
727 |
def test_post_02(): |
728 |
log.seek(0, os.SEEK_END)
|
729 |
test_case = "TEST POST 02:"
|
730 |
print "{} HTTP POST with an external-name".format(test_case) |
731 |
|
732 |
json_body = { |
733 |
"external-name" : "edu.berkeley.eecs.gdp-rest.test_post_02" |
734 |
} |
735 |
|
736 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
737 |
auth = test_auth, |
738 |
timeout = 60,
|
739 |
headers = json_header, |
740 |
data = json.dumps(json_body)) |
741 |
if page.status_code == 400: |
742 |
pj = page.json() |
743 |
detail = pj["detail"]
|
744 |
if detail == "POST external-name must have null value": |
745 |
print "{} PASSED \"{}\"".format(test_case, detail) |
746 |
else:
|
747 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
748 |
failed_log_and_page_display(page, log) |
749 |
|
750 |
else:
|
751 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
752 |
failed_log_and_page_display(page, log) |
753 |
#
|
754 |
|
755 |
def test_post_03(): |
756 |
log.seek(0, os.SEEK_END)
|
757 |
test_case = "TEST POST 03:"
|
758 |
print "{} HTTP POST with no request body".format(test_case) |
759 |
|
760 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
761 |
auth = test_auth, |
762 |
timeout = 60,
|
763 |
headers = json_header) |
764 |
if page.status_code == 400: |
765 |
pj = page.json() |
766 |
detail = pj["detail"]
|
767 |
if detail == "request body not recognized json format": |
768 |
print "{} PASSED \"{}\"".format(test_case, detail) |
769 |
else:
|
770 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
771 |
failed_log_and_page_display(page, log) |
772 |
|
773 |
else:
|
774 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
775 |
failed_log_and_page_display(page, log) |
776 |
#
|
777 |
|
778 |
def test_post_04(): |
779 |
log.seek(0, os.SEEK_END)
|
780 |
test_case = "TEST POST 04:"
|
781 |
print "{} HTTP POST with no request header or body".format(test_case) |
782 |
|
783 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
784 |
auth = test_auth, |
785 |
timeout = 60)
|
786 |
|
787 |
if page.status_code == 400: |
788 |
pj = page.json() |
789 |
detail = pj["detail"]
|
790 |
if detail == "request body not recognized json format": |
791 |
print "{} PASSED \"{}\"".format(test_case, detail) |
792 |
else:
|
793 |
print "{} FAILED page: \"{}\"".format(test_case, detail) |
794 |
failed_log_and_page_display(page, log) |
795 |
|
796 |
else:
|
797 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
798 |
failed_log_and_page_display(page, log) |
799 |
#
|
800 |
|
801 |
def test_post_05(): |
802 |
log.seek(0, os.SEEK_END)
|
803 |
test_case = "TEST POST 05:"
|
804 |
test_id = "test_post_05_log"
|
805 |
print "{} HTTP POST new log, verify all valid options".format(test_case) |
806 |
|
807 |
json_body = { |
808 |
"external-name" : None, |
809 |
"-C" : "swarmlab@berkeley.edu", |
810 |
"-h" : "sha224", |
811 |
"-k" : "dsa", |
812 |
"-b" : "1024", |
813 |
"-c" : "ignored_for_dsa", |
814 |
"META" : [ "meta1=foo", "meta2=bar" ], |
815 |
} |
816 |
|
817 |
page = requests.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v2/gcl",
|
818 |
auth = test_auth, |
819 |
timeout = 60,
|
820 |
headers = json_header, |
821 |
data = json.dumps(json_body)) |
822 |
if page.status_code == 201: |
823 |
pj = page.json() |
824 |
gcl_name = pj["gcl_name"]
|
825 |
# DEPRECATED gdplogd_name retrieval code block
|
826 |
# gdplogd_name = pj["gdplogd_name"]
|
827 |
# if gcl_name != None and gdplogd_name != None:
|
828 |
# print "{} PASSED \"{}\" \"{}\"".format(test_case,
|
829 |
# gcl_name, gdplogd_name)
|
830 |
# test_log(test_case, test_id, gcl_name)
|
831 |
# else:
|
832 |
# print "{} FAILED page: \"{}\" \"{}\"".format(test_case,
|
833 |
# gcl_name, gdplogd_name)
|
834 |
# failed_log_and_page_display(page, log)
|
835 |
# END DEPRECATED gdplogd_name retrieval code block
|
836 |
if gcl_name != None: |
837 |
print "{} PASSED \"{}\"".format(test_case, gcl_name) |
838 |
test_log(test_case, test_id, gcl_name) |
839 |
else:
|
840 |
print "{} FAILED page: \"{}\"".format(test_case, gcl_name) |
841 |
failed_log_and_page_display(page, log) |
842 |
else:
|
843 |
print "{} FAILED status code: {}".format(test_case, page.status_code) |
844 |
failed_log_and_page_display(page, log) |
845 |
#
|
846 |
|
847 |
|
848 |
#
|
849 |
# RUN TESTS
|
850 |
#
|
851 |
|
852 |
# #
|
853 |
# # preclean gdp-rest-01 v2 testbed (aborted test runs)
|
854 |
# #
|
855 |
# print "Info: stopping gdplogd2.service (purge GCL cache from prior test runs)"
|
856 |
# subprocess.call("sudo systemctl stop gdplogd2.service", shell=True)
|
857 |
# print "Info: stop gdp-rest-v2.service (purge GCL cache from prior test runs)"
|
858 |
# subprocess.call("sudo systemctl stop gdp-rest-v2.service", shell=True)
|
859 |
# print "Info: clean local logs (and their keys, but not production keys)"
|
860 |
# clean_glogs_and_keys()
|
861 |
|
862 |
# #
|
863 |
# # start v2 testbed
|
864 |
# #
|
865 |
# print "Info: start gdplogd2.service (sudo systemctl)"
|
866 |
# if subprocess.call("sudo systemctl start gdplogd2.service", shell=True) != 0:
|
867 |
# print "Error: sudo systemctl start gdplogd2.service failed"
|
868 |
# sys.exit(1)
|
869 |
# #
|
870 |
# log.seek(0, os.SEEK_END)
|
871 |
# print "Info: start gdp-rest-v2.service (sudo systemctl)"
|
872 |
# if subprocess.call("sudo systemctl start gdp-rest-v2.service", shell=True) != 0:
|
873 |
# print "Error: sudo systemctl start gdp-rest-v2.service failed"
|
874 |
# sys.exit(1)
|
875 |
# #
|
876 |
# m = re.search(".*could not initialize SCGI port.*", log.read(-1))
|
877 |
# if m != None:
|
878 |
# print "Warning: gdp-rest has not released the SCGI port yet, wait and retry"
|
879 |
# sys.exit(1)
|
880 |
# #
|
881 |
|
882 |
#
|
883 |
# TEST run
|
884 |
#
|
885 |
|
886 |
# HTTP PUT test suite
|
887 |
test_put_01() |
888 |
test_put_02() |
889 |
test_put_03() |
890 |
test_put_04() |
891 |
test_put_05() |
892 |
test_put_06() |
893 |
test_put_07() |
894 |
test_put_08() |
895 |
test_put_09() |
896 |
test_put_10() |
897 |
test_put_11() |
898 |
test_put_12() |
899 |
test_put_13() |
900 |
test_put_14() |
901 |
test_put_15() |
902 |
test_put_16() |
903 |
|
904 |
# HTTP POST test suite
|
905 |
test_post_01() |
906 |
test_post_02() |
907 |
test_post_03() |
908 |
test_post_04() |
909 |
test_post_05() |
910 |
|
911 |
# print "Info: stopping gdplogd2.service (sudo systemctl) ...",
|
912 |
# if subprocess.call("sudo systemctl stop gdplogd2.service", shell=True) != 0:
|
913 |
# print "\nError: systemctl stop gdplogd2.service failed"
|
914 |
# else:
|
915 |
# print "stopped"
|
916 |
|
917 |
# print "Info: stopping gdp-rest-v2.service (sudo systemctl) ...",
|
918 |
# if subprocess.call("sudo systemctl stop gdp-rest-v2.service", shell=True) != 0:
|
919 |
# print "\nError: systemctl stop gdp-rest-v2.service failed"
|
920 |
# else:
|
921 |
# print "stopped"
|
922 |
|
923 |
# clean_glogs_and_keys()
|
924 |
|
925 |
dn.close() |
926 |
log.close() |
927 |
|
928 |
sys.exit(0)
|
929 |
#
|