forked from red-hat-storage/ceph-qe-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api_config.py
86 lines (61 loc) · 2.28 KB
/
test_api_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import json
import config as config
import utils.log as log
from utils.test_desc import AddTestInfo
class APIConfig(object):
def __init__(self, **api_details):
self.fsid = api_details["fsid"]
self.base_api = "cluster/"
self.api = None
def construct_api(self):
self.api = self.base_api + self.fsid + "/" + "config"
log.debug(self.api)
return self.api
class APIConfigOps(APIConfig):
def __init__(self, **kwargs):
self.auth = kwargs["auth"]
super(APIConfigOps, self).__init__(**kwargs)
self.json_config = None
def get_config(self):
api = self.construct_api()
response = self.auth.request("GET", api, verify=False)
response.raise_for_status()
pretty_response = json.dumps(response.json(), indent=2)
log.debug("pretty json response from config api")
log.debug(pretty_response)
self.json_config = json.loads(pretty_response)
def get_config_key(self):
log.debug("api testing with each key in the config")
log.debug("****************************************")
for each_key in self.json_config:
api = self.construct_api() + "/" + each_key["key"]
log.debug("config with key %s" % each_key["key"])
log.debug("api: %s" % api)
response = self.auth.request("GET", api, verify=False)
response.raise_for_status()
log.debug("response: \n %s" % response.json())
pretty_response = json.dumps(response.json(), indent=2)
log.debug("pretty json response \n %s" % pretty_response)
def put(self):
pass
def post(self):
pass
def exec_test(config_data):
add_test_info = AddTestInfo(1, "config and config with keys")
add_test_info.started_info()
try:
api_config_ops = APIConfigOps(**config_data)
api_config_ops.get_config()
api_config_ops.get_config_key()
add_test_info.status("ok")
except Exception, e:
log.error("test error")
log.error(e)
add_test_info.status("error")
add_test_info.completed_info()
if __name__ == "__main__":
config_data = config.get_config()
if not config_data["auth"]:
log.error("auth failed")
else:
exec_test(config_data)