]>
Commit | Line | Data |
---|---|---|
1 | #! /usr/bin/env python | |
2 | ||
3 | import requests | |
4 | import time | |
5 | import sys | |
6 | import json | |
7 | ||
8 | # Do not show the stupid message about verify=False. ignore exceptions bc | |
9 | # this doesn't work on some distros. | |
10 | try: | |
11 | from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
12 | requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) | |
13 | except: | |
14 | pass | |
15 | ||
16 | if len(sys.argv) < 3: | |
17 | print("Usage: %s <url> <admin_key>" % sys.argv[0]) | |
18 | sys.exit(1) | |
19 | ||
20 | addr = sys.argv[1] | |
21 | auth = ('admin', sys.argv[2]) | |
22 | headers = {'Content-type': 'application/json'} | |
23 | ||
24 | request = None | |
25 | ||
26 | # Create a pool and get its id | |
27 | request = requests.post( | |
28 | addr + '/pool?wait=yes', | |
29 | data=json.dumps({'name': 'supertestfriends', 'pg_num': 128}), | |
30 | headers=headers, | |
31 | verify=False, | |
32 | auth=auth) | |
33 | print(request.text) | |
34 | request = requests.get(addr + '/pool', verify=False, auth=auth) | |
35 | assert(request.json()[-1]['pool_name'] == 'supertestfriends') | |
36 | pool_id = request.json()[-1]['pool'] | |
37 | ||
38 | # get a mon name | |
39 | request = requests.get(addr + '/mon', verify=False, auth=auth) | |
40 | firstmon = request.json()[0]['name'] | |
41 | print('first mon is %s' % firstmon) | |
42 | ||
43 | # get a server name | |
44 | request = requests.get(addr + '/osd', verify=False, auth=auth) | |
45 | aserver = request.json()[0]['server'] | |
46 | print('a server is %s' % aserver) | |
47 | ||
48 | ||
49 | screenplay = [ | |
50 | ('get', '/', {}), | |
51 | ('get', '/config/cluster', {}), | |
52 | ('get', '/crush/rule', {}), | |
53 | ('get', '/doc', {}), | |
54 | ('get', '/mon', {}), | |
55 | ('get', '/mon/' + firstmon, {}), | |
56 | ('get', '/osd', {}), | |
57 | ('get', '/osd/0', {}), | |
58 | ('get', '/osd/0/command', {}), | |
59 | ('get', '/pool/1', {}), | |
60 | ('get', '/server', {}), | |
61 | ('get', '/server/' + aserver, {}), | |
62 | ('post', '/osd/0/command', {'command': 'scrub'}), | |
63 | ('post', '/pool?wait=1', {'name': 'supertestfriends', 'pg_num': 128}), | |
64 | ('patch', '/osd/0', {'in': False}), | |
65 | ('patch', '/config/osd', {'pause': True}), | |
66 | ('get', '/config/osd', {}), | |
67 | ('patch', '/pool/' + str(pool_id), {'size': 2}), | |
68 | ('patch', '/config/osd', {'pause': False}), | |
69 | ('patch', '/osd/0', {'in': True}), | |
70 | ('get', '/pool', {}), | |
71 | ('delete', '/pool/' + str(pool_id) + '?wait=1', {}), | |
72 | ('get', '/request?page=0', {}), | |
73 | ('delete', '/request', {}), | |
74 | ('get', '/request', {}), | |
75 | ] | |
76 | ||
77 | for method, endpoint, args in screenplay: | |
78 | if method == 'sleep': | |
79 | time.sleep(endpoint) | |
80 | continue | |
81 | url = addr + endpoint | |
82 | print("URL = " + url) | |
83 | request = getattr(requests, method)( | |
84 | url, | |
85 | data=json.dumps(args), | |
86 | headers=headers, | |
87 | verify=False, | |
88 | auth=auth) | |
89 | print(request.text) | |
90 | if request.status_code != 200 or 'error' in request.json(): | |
91 | print('ERROR: %s request for URL "%s" failed' % (method, url)) | |
92 | sys.exit(1) | |
93 | ||
94 | print('OK') |