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 function about yardstick API.
11 At present, This file contain the following function:
12 1.Ask Yardstick to run testcase and get a task id.
13 2.use task id to ask yardstick for data.
14 3.Ask yardstick for InfluxDB create
15 4.how the process of task.'''
23 import utils.logger as logger
24 from utils.parser import Parser as config
25 import utils.env_prepare.stack_prepare as env
27 headers = {"Content-Type": "application/json"}
28 LOG = logger.Logger(__name__).getLogger()
31 def yardstick_image_prepare():
32 if not os.path.exists(config.bottlenecks_config["yardstick_image_dir"]):
33 urllib.urlretrieve(config.bottlenecks_config["image_url"],
34 config.bottlenecks_config["yardstick_image_dir"])
35 env.prepare_image(config.bottlenecks_config["yardstick_image_name"],
36 config.bottlenecks_config["yardstick_image_dir"])
39 def yardstick_command_parser(debug, cidr, outfile, parameter):
45 cmd += " --output-file " + outfile
46 image_name = config.bottlenecks_config["yardstick_image_name"]
47 parameter["image_name"] = image_name
49 if parameter is not None:
50 cmd += " --task-args " + '"' + str(parameter) + '"'
54 def Get_Reply(test_config, task_id, time_test=1):
55 reply_url = ("http://%s/yardstick/results?task_id=%s"
56 % (test_config['yardstick_test_ip'], task_id))
57 reply_response = requests.get(reply_url)
58 reply_data = json.loads(reply_response.text)
59 LOG.info("return data is %s" % (reply_data))
60 if reply_data["status"] == 1:
61 return(reply_data["result"])
62 if reply_data["status"] == 0:
64 LOG.info("yardstick time out")
67 reply_result_data = Get_Reply(
68 test_config, task_id, time_test=time_test + 1)
69 return(reply_result_data)
70 if reply_data["status"] == 2:
71 LOG.error("yardstick error exit")
75 def Send_Data(test_dict, test_config):
76 base_url = ("http://%s/yardstick/testcases/%s/action"
77 % (test_config['yardstick_test_ip'],
78 test_config['yardstick_test_dir']))
79 LOG.info("test ip addr is %s" % (base_url))
80 reponse = requests.post(
81 base_url, data=json.dumps(test_dict), headers=headers)
82 ask_data = json.loads(reponse.text)
83 task_id = ask_data["result"]
84 LOG.info("yardstick task id is: %s" % (task_id))
88 def Create_Incluxdb(con_dic):
89 base_url = ("http://%s/yardstick/env/action"
90 % (con_dic['yardstick_test_ip']))
92 "action": "createInfluxDBContainer",
94 responce = requests.post(
95 base_url, data=json.dumps(test_dict), headers=headers)
96 ask_data = json.loads(responce.text)
97 task_id = ask_data["result"]["task_id"]
98 LOG.info("waiting for creating InfluxDB")
103 def yardstick_env_prepare(con_dic):
104 base_url = ("http://%s/yardstick/env/action"
105 % (con_dic['yardstick_test_ip']))
107 "action": "prepareYardstickEnv",
109 LOG.info("waiting for yardstick environment prepare")
110 reponse = requests.post(
111 base_url, data=json.dumps(test_dict), headers=headers)
112 ask_data = json.loads(reponse.text)
113 task_id = ask_data["result"]["task_id"]
114 LOG.info("Done, yardstick environment prepare complete!")
118 def find_condition(con_dic):
119 base_url = ("http://%s/yardstick/asynctask?%s"
120 % (con_dic['yardstick_test_ip'].id))
122 base_url, headers=headers)
123 LOG.info("check for creating InfluxDB")