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.'''
21 import utils.logger as logger
23 headers = {"Content-Type": "application/json"}
24 LOG = logger.Logger(__name__).getLogger()
27 def Get_Reply(test_config, task_id, time_test=1):
28 reply_url = ("http://%s/yardstick/results?task_id=%s"
29 % (test_config['yardstick_test_ip'], task_id))
30 reply_response = requests.get(reply_url)
31 reply_data = json.loads(reply_response.text)
32 LOG.info("return data is %s" % (reply_data))
33 if reply_data["status"] == 1:
34 return(reply_data["result"])
35 if reply_data["status"] == 0:
37 LOG.info("yardstick time out")
40 reply_result_data = Get_Reply(
41 test_config, task_id, time_test=time_test + 1)
42 return(reply_result_data)
43 if reply_data["status"] == 2:
44 LOG.error("yardstick error exit")
48 def Send_Data(test_dict, test_config):
49 base_url = ("http://%s/yardstick/testcases/%s/action"
50 % (test_config['yardstick_test_ip'],
51 test_config['yardstick_test_dir']))
52 LOG.info("test ip addr is %s" % (base_url))
53 reponse = requests.post(
54 base_url, data=json.dumps(test_dict), headers=headers)
55 ask_data = json.loads(reponse.text)
56 task_id = ask_data["result"]
57 LOG.info("yardstick task id is: %s" % (task_id))
61 def Create_Incluxdb(con_dic):
62 base_url = ("http://%s/yardstick/env/action"
63 % (con_dic['yardstick_test_ip']))
65 "action": "createInfluxDBContainer",
67 responce = requests.post(
68 base_url, data=json.dumps(test_dict), headers=headers)
69 ask_data = json.loads(responce.text)
70 task_id = ask_data["result"]["task_id"]
71 LOG.info("waiting for creating InfluxDB")
76 def yardstick_env_prepare(con_dic):
77 base_url = ("http://%s/yardstick/env/action"
78 % (con_dic['yardstick_test_ip']))
80 "action": "prepareYardstickEnv",
82 LOG.info("waiting for yardstick environment prepare")
83 reponse = requests.post(
84 base_url, data=json.dumps(test_dict), headers=headers)
85 ask_data = json.loads(reponse.text)
86 task_id = ask_data["result"]["task_id"]
87 LOG.info("Done, yardstick environment prepare complete!")
91 def find_condition(con_dic):
92 base_url = ("http://%s/yardstick/asynctask?%s"
93 % (con_dic['yardstick_test_ip'].id))
95 base_url, headers=headers)
96 LOG.info("check for creating InfluxDB")