X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fstorage%2Fstorperf.py;h=f0b2361d6cf7982ec6924f23d2342f99cad932a0;hb=1a773377337cea9b238c8447d2de1b48e89baae0;hp=d39c23aa2b0b2cd8ada11e6338c5bc67e04798e0;hpb=147ef861038a8a9b17c828c201d6fceab9feb565;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/storage/storperf.py b/yardstick/benchmark/scenarios/storage/storperf.py index d39c23aa2..f0b2361d6 100644 --- a/yardstick/benchmark/scenarios/storage/storperf.py +++ b/yardstick/benchmark/scenarios/storage/storperf.py @@ -6,11 +6,15 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import + +import os import logging -import json -import requests import time +import requests +from oslo_serialization import jsonutils + from yardstick.benchmark.scenarios import base LOG = logging.getLogger(__name__) @@ -54,6 +58,7 @@ class StorPerf(base.Scenario): def __init__(self, scenario_cfg, context_cfg): """Scenario construction.""" + super(StorPerf, self).__init__() self.scenario_cfg = scenario_cfg self.context_cfg = context_cfg self.options = self.scenario_cfg["options"] @@ -72,58 +77,62 @@ class StorPerf(base.Scenario): setup_query = requests.get('http://%s:5000/api/v1.0/configurations' % self.target) - setup_query_content = json.loads(setup_query.content) + setup_query_content = jsonutils.loads( + setup_query.content) if setup_query_content["stack_created"]: self.setup_done = True - LOG.debug("stack_created: %s" - % setup_query_content["stack_created"]) + LOG.debug("stack_created: %s", + setup_query_content["stack_created"]) def setup(self): """Set the configuration.""" env_args = {} - env_args_payload_list = ["agent_count", "public_network", - "agent_image", "volume_size"] + env_args_payload_list = ["agent_count", "agent_flavor", + "public_network", "agent_image", + "volume_size"] for env_argument in env_args_payload_list: - if env_argument in self.options: + try: env_args[env_argument] = self.options[env_argument] + except KeyError: + pass - LOG.info("Creating a stack on node %s with parameters %s" % - (self.target, env_args)) + LOG.info("Creating a stack on node %s with parameters %s", + self.target, env_args) setup_res = requests.post('http://%s:5000/api/v1.0/configurations' % self.target, json=env_args) - setup_res_content = json.loads(setup_res.content) + setup_res_content = jsonutils.loads( + setup_res.content) - if setup_res.status_code == 400: + if setup_res.status_code != 200: raise RuntimeError("Failed to create a stack, error message:", setup_res_content["message"]) elif setup_res.status_code == 200: - LOG.info("stack_id: %s" % setup_res_content["stack_id"]) + LOG.info("stack_id: %s", setup_res_content["stack_id"]) while not self.setup_done: self._query_setup_state() time.sleep(self.query_interval) - # TODO: Support Storperf job status. - - # def _query_job_state(self, job_id): - # """Query the status of the supplied job_id and report on metrics""" - # LOG.info("Fetching report for %s..." % job_id) - # report_res = requests.get('http://%s:5000/api/v1.0/jobs?id=%s' % - # (self.target, job_id)) + def _query_job_state(self, job_id): + """Query the status of the supplied job_id and report on metrics""" + LOG.info("Fetching report for %s...", job_id) + report_res = requests.get('http://{}:5000/api/v1.0/jobs'.format + (self.target), + params={'id': job_id, 'type': 'status'}) - # report_res_content = json.loads(report_res.content) + report_res_content = jsonutils.loads( + report_res.content) - # if report_res.status_code == 400: - # raise RuntimeError("Failed to fetch report, error message:", - # report_res_content["message"]) - # else: - # job_status = report_res_content["status"] + if report_res.status_code != 200: + raise RuntimeError("Failed to fetch report, error message:", + report_res_content["message"]) + else: + job_status = report_res_content["Status"] - # LOG.debug("Job is: %s..." % job_status) - # if job_status == "completed": - # self.job_completed = True + LOG.debug("Job is: %s...", job_status) + self.job_completed = job_status == "Completed" # TODO: Support using StorPerf ReST API to read Job ETA. @@ -140,42 +149,53 @@ class StorPerf(base.Scenario): if not self.setup_done: self.setup() - job_args = {} + metadata = {"build_tag": "latest", "test_case": "opnfv_yardstick_tc074"} + metadata_payload_dict = {"pod_name": "NODE_NAME", + "scenario_name": "DEPLOY_SCENARIO", + "version": "YARDSTICK_BRANCH"} + + for key, value in metadata_payload_dict.items(): + try: + metadata[key] = os.environ[value] + except KeyError: + pass + + job_args = {"metadata": metadata} job_args_payload_list = ["block_sizes", "queue_depths", "deadline", "target", "nossd", "nowarm", "workload"] for job_argument in job_args_payload_list: - if job_argument in self.options: + try: job_args[job_argument] = self.options[job_argument] + except KeyError: + pass - LOG.info("Starting a job with parameters %s" % job_args) + LOG.info("Starting a job with parameters %s", job_args) job_res = requests.post('http://%s:5000/api/v1.0/jobs' % self.target, json=job_args) - job_res_content = json.loads(job_res.content) + job_res_content = jsonutils.loads(job_res.content) - if job_res.status_code == 400: + if job_res.status_code != 200: raise RuntimeError("Failed to start a job, error message:", job_res_content["message"]) elif job_res.status_code == 200: job_id = job_res_content["job_id"] - LOG.info("Started job id: %s..." % job_id) + LOG.info("Started job id: %s...", job_id) + + while not self.job_completed: + self._query_job_state(job_id) + time.sleep(self.query_interval) - time.sleep(self.timeout) terminate_res = requests.delete('http://%s:5000/api/v1.0/jobs' % self.target) - if terminate_res.status_code == 400: - terminate_res_content = json.loads(terminate_res.content) + if terminate_res.status_code != 200: + terminate_res_content = jsonutils.loads( + terminate_res.content) raise RuntimeError("Failed to start a job, error message:", terminate_res_content["message"]) - # TODO: Support Storperf job status. - - # while not self.job_completed: - # self._query_job_state(job_id) - # time.sleep(self.query_interval) - # TODO: Support using ETA to polls for completion. # Read ETA, next poll in 1/2 ETA time slot. # If ETA is greater than the maximum allowed job time, @@ -187,11 +207,12 @@ class StorPerf(base.Scenario): # terminate_res = requests.delete('http://%s:5000/api/v1.0 # /jobs' % self.target) # else: - # time.sleep(int(est_time)/2) + # time.sleep(int(esti_time)/2) result_res = requests.get('http://%s:5000/api/v1.0/jobs?id=%s' % (self.target, job_id)) - result_res_content = json.loads(result_res.content) + result_res_content = jsonutils.loads( + result_res.content) result.update(result_res_content) @@ -201,7 +222,8 @@ class StorPerf(base.Scenario): configurations' % self.target) if teardown_res.status_code == 400: - teardown_res_content = json.loads(teardown_res.content) + teardown_res_content = jsonutils.loads( + teardown_res.content) raise RuntimeError("Failed to reset environment, error message:", teardown_res_content['message'])