1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
15 from oslo_serialization import jsonutils
17 from yardstick.benchmark.scenarios import base
19 LOG = logging.getLogger(__name__)
22 class StorPerf(base.Scenario):
23 """Execute StorPerf benchmark.
24 Once the StorPerf container has been started and the ReST API exposed,
25 you can interact directly with it using the ReST API. StorPerf comes with a
26 Swagger interface that is accessible through the exposed port at:
27 http://StorPerf:5000/swagger/index.html
30 target = [device or path] (Optional):
31 The path to either an attached storage device (/dev/vdb, etc) or a
32 directory path (/opt/storperf) that will be used to execute the performance
33 test. In the case of a device, the entire device will be used.
34 If not specified, the current directory will be used.
36 workload = [workload module] (Optional):
37 If not specified, the default is to run all workloads.
38 The workload types are:
39 rs: 100% Read, sequential data
40 ws: 100% Write, sequential data
41 rr: 100% Read, random access
42 wr: 100% Write, random access
43 rw: 70% Read / 30% write, random access
46 Do not perform SSD style preconditioning.
49 Do not perform a warmup prior to measurements.
51 report = [job_id] (Optional):
52 Query the status of the supplied job_id and report on metrics.
53 If a workload is supplied, will report on only that subset.
56 __scenario_type__ = "StorPerf"
58 def __init__(self, scenario_cfg, context_cfg):
59 """Scenario construction."""
60 super(StorPerf, self).__init__()
61 self.scenario_cfg = scenario_cfg
62 self.context_cfg = context_cfg
63 self.options = self.scenario_cfg["options"]
65 self.target = self.options.get("StorPerf_ip", None)
66 self.query_interval = self.options.get("query_interval", 10)
67 # Maximum allowed job time
68 self.timeout = self.options.get('timeout', 3600)
70 self.setup_done = False
71 self.job_completed = False
73 def _query_setup_state(self):
74 """Query the stack status."""
75 LOG.info("Querying the stack state...")
76 setup_query = requests.get('http://%s:5000/api/v1.0/configurations'
79 setup_query_content = jsonutils.loads(
81 if setup_query_content["stack_created"]:
82 self.setup_done = True
83 LOG.debug("stack_created: %s",
84 setup_query_content["stack_created"])
87 """Set the configuration."""
89 env_args_payload_list = ["agent_count", "public_network",
90 "agent_image", "volume_size"]
92 for env_argument in env_args_payload_list:
94 env_args[env_argument] = self.options[env_argument]
98 LOG.info("Creating a stack on node %s with parameters %s",
99 self.target, env_args)
100 setup_res = requests.post('http://%s:5000/api/v1.0/configurations'
101 % self.target, json=env_args)
103 setup_res_content = jsonutils.loads(
106 if setup_res.status_code != 200:
107 raise RuntimeError("Failed to create a stack, error message:",
108 setup_res_content["message"])
109 elif setup_res.status_code == 200:
110 LOG.info("stack_id: %s", setup_res_content["stack_id"])
112 while not self.setup_done:
113 self._query_setup_state()
114 time.sleep(self.query_interval)
116 def _query_job_state(self, job_id):
117 """Query the status of the supplied job_id and report on metrics"""
118 LOG.info("Fetching report for %s...", job_id)
119 report_res = requests.get('http://{}:5000/api/v1.0/jobs'.format
121 params={'id': job_id, 'type': 'status'})
123 report_res_content = jsonutils.loads(
126 if report_res.status_code != 200:
127 raise RuntimeError("Failed to fetch report, error message:",
128 report_res_content["message"])
130 job_status = report_res_content["Status"]
132 LOG.debug("Job is: %s...", job_status)
133 self.job_completed = job_status == "Completed"
135 # TODO: Support using StorPerf ReST API to read Job ETA.
137 # if job_status == "completed":
138 # self.job_completed = True
140 # elif job_status == "running":
141 # ETA = report_res_content['time']
145 def run(self, result):
146 """Execute StorPerf benchmark"""
147 if not self.setup_done:
151 job_args_payload_list = ["block_sizes", "queue_depths", "deadline",
152 "target", "nossd", "nowarm", "workload"]
154 for job_argument in job_args_payload_list:
156 job_args[job_argument] = self.options[job_argument]
160 LOG.info("Starting a job with parameters %s", job_args)
161 job_res = requests.post('http://%s:5000/api/v1.0/jobs' % self.target,
164 job_res_content = jsonutils.loads(job_res.content)
166 if job_res.status_code != 200:
167 raise RuntimeError("Failed to start a job, error message:",
168 job_res_content["message"])
169 elif job_res.status_code == 200:
170 job_id = job_res_content["job_id"]
171 LOG.info("Started job id: %s...", job_id)
173 while not self.job_completed:
174 self._query_job_state(job_id)
175 time.sleep(self.query_interval)
177 terminate_res = requests.delete('http://%s:5000/api/v1.0/jobs' %
180 if terminate_res.status_code != 200:
181 terminate_res_content = jsonutils.loads(
182 terminate_res.content)
183 raise RuntimeError("Failed to start a job, error message:",
184 terminate_res_content["message"])
186 # TODO: Support using ETA to polls for completion.
187 # Read ETA, next poll in 1/2 ETA time slot.
188 # If ETA is greater than the maximum allowed job time,
189 # then terminate job immediately.
191 # while not self.job_completed:
192 # esti_time = self._query_state(job_id)
193 # if esti_time > self.timeout:
194 # terminate_res = requests.delete('http://%s:5000/api/v1.0
195 # /jobs' % self.target)
197 # time.sleep(int(est_time)/2)
199 result_res = requests.get('http://%s:5000/api/v1.0/jobs?id=%s' %
200 (self.target, job_id))
201 result_res_content = jsonutils.loads(
204 result.update(result_res_content)
207 """Deletes the agent configuration and the stack"""
208 teardown_res = requests.delete('http://%s:5000/api/v1.0/\
209 configurations' % self.target)
211 if teardown_res.status_code == 400:
212 teardown_res_content = jsonutils.loads(
213 teardown_res.content)
214 raise RuntimeError("Failed to reset environment, error message:",
215 teardown_res_content['message'])
217 self.setup_done = False