2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 '''This file contain all functions about storperf API.
11 At present, This file contain the following function:
12 1. Ask storperf to configure the environment.
13 2. Ask Storperf to run testcase and get the job id.
14 3. Use Job id to ask storperf for status, metrics and metadata.
15 4. Query information about current jobs, environment and view logs.'''
21 import utils.logger as logger
24 "Content-Type": "application/json",
25 "Accept": "application/json"
27 LOG = logger.Logger(__name__).getLogger()
30 def storperf_env_prepare(con_dic, storperf_count, storperf_image,
31 storperf_flavor, volume_size):
32 base_url = ("http://%s/api/v1.0/configurations"
33 % (con_dic['storperf_test_ip']))
35 "agent_count": storperf_count,
36 "agent_image": storperf_image,
37 "agent_flavor": storperf_flavor,
38 "public_network": os.environ.get("EXTERNAL_NETWORK"),
39 "volume_size": volume_size
41 LOG.info("waiting for storperf environment to prepare")
42 reponse = requests.post(
43 base_url, data=json.dumps(test_dict), headers=headers)
44 ask_data = json.loads(reponse.text)
45 stack_id = ask_data["stack_id"]
46 LOG.info("Done, storperf environment prepare complete!")
52 base_url = ("http://%s/api/v1.0/jobs"
53 % (con_dic['storperf_test_ip']))
55 "workload": "_warm_up"
57 LOG.info("filling the cinder volume with random data")
58 reponse = requests.post(
59 base_url, data=json.dumps(test_dict), headers=headers)
60 ask_data = json.loads(reponse.text)
61 job_id = ask_data["job_id"]
62 LOG.info("Done, filled the cinder volume with random data!")
68 base_url = ("http://%s/api/v1.0/jobs"
69 % (con_dic['storperf_test_ip']))
71 "block_sizes": con_dic['block_sizes'],
72 "deadline": con_dic['deadline'],
73 "steady_state_samples": con_dic['steady_state_samples'],
74 "queue_depths": con_dic['queue_depths'],
75 "workload": con_dic['workload']
77 deadline = con_dic['deadline']
78 LOG.info("running the storage performance testcase")
79 reponse = requests.post(
80 base_url, data=json.dumps(test_dict), headers=headers)
81 ask_data = json.loads(reponse.text)
82 job_id = ask_data["job_id"]
83 LOG.info("Done, testcase still executing for specified deadline")
88 def current_jobs(con_dic):
89 base_url = ("http://%s/api/v1.0/jobs"
90 % (con_dic['storperf_test_ip']))
91 reply_response = requests.get(
92 base_url, headers=headers)
93 reply_data = json.loads(reply_response.text)
94 LOG.info("current storperf jobs are %s" % (reply_data))
98 def job_status(con_dic, job_id):
99 base_url = ("http://%s/api/v1.0/jobs?id=%s&type=status"
100 % (con_dic['storperf_test_ip'], job_id))
101 reply_response = requests.get(
102 base_url, headers=headers)
103 reply_data = json.loads(reply_response.text)
104 LOG.info("job status is %s" % (reply_data))
108 def job_metrics(con_dic, job_id):
109 base_url = ("http://%s/api/v1.0/jobs?id=%s&type=metrics"
110 % (con_dic['storperf_test_ip'], job_id))
111 reply_response = requests.get(
112 base_url, headers=headers)
113 reply_data = json.loads(reply_response.text)
114 LOG.info("job metrics is %s" % (reply_data))
118 def job_metadata(con_dic, job_id):
119 base_url = ("http://%s/api/v1.0/jobs?id=%s&type=metadata"
120 % (con_dic['storperf_test_ip'], job_id))
121 reply_response = requests.get(
122 base_url, headers=headers)
123 reply_data = json.loads(reply_response.text)
124 LOG.info("job metadata is %s" % (reply_data))
128 def get_logs(con_dic):
129 base_url = ("http://%s/api/v1.0/logs?lines=all"
130 % (con_dic['storperf_test_ip']))
131 reply_response = requests.get(
132 base_url, headers=headers)
133 reply_data = json.loads(reply_response.text)
134 LOG.info("All storperf logs: %s" % (reply_data))
138 def get_quotas(con_dic):
139 base_url = ("http://%s/api/v1.0/quotas"
140 % (con_dic['storperf_test_ip']))
141 reply_response = requests.get(
142 base_url, headers=headers)
143 reply_data = json.loads(reply_response.text)
144 LOG.info("current quotas is %s" % (reply_data))
148 def get_configurations(con_dic):
149 base_url = ("http://%s/api/v1.0/configurations"
150 % (con_dic['storperf_test_ip']))
151 reply_response = requests.get(
152 base_url, headers=headers)
153 reply_data = json.loads(reply_response.text)
154 LOG.info("current configurations is %s" % (reply_data))
158 def delete_configurations(con_dic):
159 base_url = ("http://%s/api/v1.0/configurations"
160 % (con_dic['storperf_test_ip']))
162 base_url, headers=headers)
163 LOG.info("delete the storperf environment")
166 def delete_jobs(con_dic):
167 base_url = ("http://%s/api/v1.0/jobs"
168 % (con_dic['storperf_test_ip']))
170 base_url, headers=headers)
171 LOG.info("delete current storperf jobs")