]> git.proxmox.com Git - ceph.git/blame_incremental - ceph/qa/workunits/rest/test_mgr_rest_api.py
bump version to 12.2.5-pve1
[ceph.git] / ceph / qa / workunits / rest / test_mgr_rest_api.py
... / ...
CommitLineData
1#! /usr/bin/env python
2
3import requests
4import time
5import sys
6import json
7
8# Do not show the stupid message about verify=False. ignore exceptions bc
9# this doesn't work on some distros.
10try:
11 from requests.packages.urllib3.exceptions import InsecureRequestWarning
12 requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
13except:
14 pass
15
16if len(sys.argv) < 3:
17 print("Usage: %s <url> <admin_key>" % sys.argv[0])
18 sys.exit(1)
19
20addr = sys.argv[1]
21auth = ('admin', sys.argv[2])
22headers = {'Content-type': 'application/json'}
23
24request = None
25
26# Create a pool and get its id
27request = 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)
33print(request.text)
34request = requests.get(addr + '/pool', verify=False, auth=auth)
35assert(request.json()[-1]['pool_name'] == 'supertestfriends')
36pool_id = request.json()[-1]['pool']
37
38# get a mon name
39request = requests.get(addr + '/mon', verify=False, auth=auth)
40firstmon = request.json()[0]['name']
41print('first mon is %s' % firstmon)
42
43# get a server name
44request = requests.get(addr + '/osd', verify=False, auth=auth)
45aserver = request.json()[0]['server']
46print('a server is %s' % aserver)
47
48
49screenplay = [
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
77for 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
94print('OK')