diff options
author | liyin <liyin11@huawei.com> | 2016-11-30 12:27:53 +0800 |
---|---|---|
committer | Ace Lee <liyin11@huawei.com> | 2016-11-30 06:41:29 +0000 |
commit | ab7055e7dafc6a1cf2f9b1daf755602ec437b9bf (patch) | |
tree | d8ebcd665b3103eb7b0256af9f189b979f0d7005 /testsuites/posca/testcase_script | |
parent | afea25c89a2d1ae1b1c7ca6641652c0adc0dba02 (diff) |
POSCA test case complete
JIRA: BOTTLENECK-107
JIRA: BOTTLENECK-106
This patch has done the flowings:
1.Using the RESTful API form yardstick
2.Common function reuse.
3.If there is no test_ip it would use host ip and port as test_ip.
4.A little demo of dashboard. Now is can't work
Change-Id: I1063176c762c40238019c73f5359f23bc5aab19c
Signed-off-by: liyin <liyin11@huawei.com>
Diffstat (limited to 'testsuites/posca/testcase_script')
-rw-r--r-- | testsuites/posca/testcase_script/common_script.py | 122 | ||||
-rw-r--r-- | testsuites/posca/testcase_script/posca_factor_system_bandwidth.py | 179 |
2 files changed, 209 insertions, 92 deletions
diff --git a/testsuites/posca/testcase_script/common_script.py b/testsuites/posca/testcase_script/common_script.py new file mode 100644 index 00000000..9234d938 --- /dev/null +++ b/testsuites/posca/testcase_script/common_script.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +############################################################################## +# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import json +import requests +import time +import subprocess as sub +from pyroute2 import IPDB +import sys + +headers = {"Content-Type": "application/json"} + + +def posca_tran_data(ES_ip, file_name): + p = sub.Popen(['curl', '-s', '-XPOST', "%s/_bulk" % ES_ip, + '--data-binary', "@" + file_name], stdout=sub.PIPE) + for line in iter(p.stdout.readline, b''): + ret_dict = json.loads(line) + if not ret_dict['errors']: + print("INFO: %6s lines no errors, total cost %d ms." + % (len(ret_dict['items']), ret_dict['took'])) + return len(ret_dict['items']) + else: + print("ERROR: %6s lines have errors, total cost %d ms." + % (len(ret_dict['items']), ret_dict['took'])) + + +def posca_config_read(config_str, con_str, config): + print("========== posca system bandwidth config read ===========") + con_dic = {} + print(config_str) + idx = 0 + with open(config_str, "rd") as cfgfile: + config.readfp(cfgfile) + while idx < len(con_str): + con_dic[str(con_str[idx])] = \ + config.get("config", str(con_str[idx])) + idx += 1 + with IPDB() as ip: + GATEWAY_IP = ip.routes['default'].gateway + if str(con_dic["test_ip"]) is "": + con_dic["test_ip"] = GATEWAY_IP+":3333" + print("test_ip is null get local ip is %s" %(con_dic["test_ip"])) + if con_dic["ES_ip"] is "": + con_dic["ES_ip"] = GATEWAY_IP+":9200" + print("ES_ip is null get local ip is %s" %(con_dic["ES_ip"])) + return con_dic + + +def posca_output_result(file_config, data_reply): + data_head = {} + data_head["index"] = {} + data_head["index"]["_index"] = "bottlenecks" + data_head["index"]["_type"] = file_config["test_type"] + data_head["index"]["_id"] = file_config["test_id"] + + data_reply["throughput"] = float(data_reply["throughput"]) + data_reply["mean_latency"] = float(data_reply["mean_latency"]) + data_reply["remote_cpu_util"] = float(data_reply["remote_cpu_util"]) + data_reply["local_cpu_util"] = float(data_reply["local_cpu_util"]) + data_reply["local_transport_retrans"] =\ + float(data_reply["local_transport_retrans"]) + with open(file_config["file_path"], "a") as f: + f.write(json.dumps(data_head, f)) + f.write("\n") + f.write(json.dumps(data_reply, f)) + f.write("\n") + f.close() + + +def posca_get_reply(con_dic, task_id, time_test=1): + reply_url = "http://%s/yardstick/result/action?action=getResult&task_id=%s\ +&measurement=tc100" % (con_dic["test_ip"], task_id) + time.sleep(float(con_dic["test_time"])) + reply_response = requests.get(reply_url) + reply_data = json.loads(reply_response.text) + print(reply_data) + if reply_data["status"] == 1: + return(reply_data["result"][0]) + if reply_data["status"] == 0: + if time_test == 3: + print("yardstick time out") + sys.exit() + posca_get_reply(con_dic, task_id, time_test=time_test+1) + if reply_data["status"] == 2: + print("yardstick error exit") + sys.exit() + +def posca_send_data(con_dic, test_config, file_config): + base_url = "http://%s/yardstick/test/action" % (con_dic['test_ip']) + print(con_dic["test_ip"]) + test_dict = { + "action":"runTestCase", + "args":{ + "opts": { + "task-args": { + 'tx_msg_size': '%s' % str(test_config["tx_msg_size"]), + 'rx_msg_size': '%s' % str(test_config["rx_msg_size"]), + 'test_time': '%s' % str(int(con_dic["test_time"]) - 20), + 'host': 'node3.LF', + 'target': 'node4.LF' + } + }, + "testcase":"tc100" + } + } + # print(base_url) + reponse = requests.post( + base_url, data=json.dumps(test_dict), headers=headers) + ask_data = json.loads(reponse.text) + task_id = ask_data["task_id"] + data_reply = posca_get_reply(con_dic, task_id) + data_reply.update(test_config) + posca_output_result(file_config, data_reply) + return data_reply diff --git a/testsuites/posca/testcase_script/posca_factor_system_bandwidth.py b/testsuites/posca/testcase_script/posca_factor_system_bandwidth.py index f3e950b6..63192023 100644 --- a/testsuites/posca/testcase_script/posca_factor_system_bandwidth.py +++ b/testsuites/posca/testcase_script/posca_factor_system_bandwidth.py @@ -13,7 +13,9 @@ import argparse import time import logging import ConfigParser -import json +import common_script +import datetime +import subprocess # ------------------------------------------------------ # parser for configuration files in each test case @@ -22,14 +24,12 @@ parser = argparse.ArgumentParser() parser.add_argument("-c", "--conf", help="configuration files for the testcase,\ in yaml format", - default="/home/opnfv/bottlenecks/testsuites/posca/\ - testcase_cfg/posca_factor_tx_pkt_size.yaml") + default="/home/opnfv/bottlenecks/testsuites/posca\ +/testcase_cfg/posca_factor_system_bandwidth.yaml") args = parser.parse_args() +headers = {"Content-Type": "application/json"} +INTERPRETER = "/usr/bin/python" -cmd = "curl -i" -order_arg = "-H \"Content-Type: application/json\" -X POST -d \'{\"cmd\": \ - \"start\", \"opts\":{\"output-file\": \"/tem/yardstick.out\"}, \ - \"args\": \"../samples/netperf.yaml\"}'" # -------------------------------------------------- # logging configuration @@ -43,94 +43,73 @@ def posca_env_check(): if os.path.exists(filepath): return True else: - os.mkdirs(r'/home/opnfv/bottlenecks/testsuites/posca/test_result/') - - -def posca_output_result(time_new, input_1, input_2, input_3, - input_4, input_5, input_6): - save_dic = {} - save_dic['tx_pkt_size'] = input_1 - save_dic['rx_cache_size'] = input_2 - save_dic['tx_cache_size'] = input_3 - save_dic['throughput '] = input_4 - save_dic['latency'] = input_5 - save_dic['cpu_load'] = input_6 - with open("/home/opnfv/bottlenecks/testsuites/posca/test_result/\ - factor_tx_cache_size_%s.json" % (time_new), "a") as f: - f.write(json.dumps(save_dic, f)) - f.write("\n") - - -def posca_config_read(config_str): - print("========== posca system bandwidth config read ===========") - con_dic = {} - config = ConfigParser.ConfigParser() - with open(config_str, "rd") as cfgfile: - config.readfp(cfgfile) - con_dic['test_ip'] = config.get("config", "test_ip") - con_dic['test_tool'] = config.get("config", "tool") - con_dic['test_time'] = config.get("config", "test_time") - con_dic['test_protocol'] = config.get("config", "protocol") - con_dic['test_tx_pkt_s'] = config.get("config", "tx pkt sizes") - con_dic['test_rx_pkt_s'] = config.get("config", "rx pkt sizes") - con_dic['test_tx_cache_s'] = config.get("config", "tx cache sizes") - con_dic['test_rx_cache_s'] = config.get("config", "rx cache sizes") - con_dic['test_cpu_load'] = config.get("config", "cpu load") - con_dic['test_latency'] = config.get("config", "latency") - - return con_dic + os.mkdir(r'/home/opnfv/bottlenecks/testsuites/posca/test_result/') + + +def system_pkt_bandwidth(test_id, data, file_config, con_dic): + date_id = test_id + print("package test is is begin from %d" % test_id) + cur_role_result = 1 + pre_role_result = 1 + pre_reply = {} + data_return = {} + data_max = {} + data_return["throughput"] = 1 + for test_x in data["tx_pkt_sizes"]: + data_max["throughput"] = 1 + bandwidth_tmp = 1 + for test_y in data["rx_pkt_sizes"]: + test_config = { + "tx_msg_size": float(test_x), + "rx_msg_size": float(test_y), + } + date_id = date_id + 1 + file_config["test_id"] = date_id + data_reply = common_script.posca_send_data( + con_dic, test_config, file_config) + bandwidth = data_reply["throughput"] + if (data_max["throughput"] < bandwidth): + data_max = data_reply + if (abs(bandwidth_tmp - bandwidth)/bandwidth_tmp < 0.025): + print(pre_reply) + break + else: + pre_reply = data_reply + bandwidth_tmp = bandwidth + cur_role_result = pre_reply["throughput"] + if (abs(pre_role_result - cur_role_result)/pre_role_result < 0.025): + print("date_id is %d,package return at line 111\n" % date_id) + # return data_return + if data_return["throughput"] < data_max["throughput"]: + data_return = data_max + pre_role_result = cur_role_result + print("date_id is %d,id return success\n" % date_id) + return data_return def posca_run(con_dic): print("========== run posca system bandwidth ===========") - - test_rx_pkt_s_e = 87380 - test_tx_pkt_s_a = con_dic['test_tx_pkt_s'].split(',') - test_tx_cache_s_a = con_dic['test_tx_cache_s'].split(',') - test_rx_cache_s_a = con_dic['test_rx_cache_s'].split(',') + test_con_id = 0 + file_config = {} + data = {} + rx_pkt_s_a = con_dic['rx_pkt_sizes'].split(',') + tx_pkt_s_a = con_dic['tx_pkt_sizes'].split(',') time_new = time.strftime('%H_%M', time.localtime(time.time())) - bandwidth_tmp = 1 - - for test_rx_cache_s_e in test_rx_cache_s_a: - for test_tx_cache_s_e in test_tx_cache_s_a: - for test_tx_pkt_s_e in test_tx_pkt_s_a: - print("%s,%s,%s") % (test_tx_pkt_s_e, test_rx_cache_s_e, - test_tx_cache_s_e) - order_excute = os.popen("%s %s http://%s/api/v3/yardstick/\ - tasks/task %s %s %s" % (cmd, order_arg, con_dic['test_ip'], - test_rx_pkt_s_e, test_rx_cache_s_e, - test_tx_cache_s_e)) - order_result = order_excute.read() - task_id = order_result.find("task_id") - time.sleep(con_dic['test_time']) - cmd_excute = os.popen("%s http://%s/api/v3/yardstick/testre\ - sults?task_id=%s" % (cmd, con_dic['test_ip'], task_id)) - bandwidth = cmd_excute.find("bandwidth") - cpu_load = cmd_excute.find("cpu_load") - latency = cmd_excute.find("latency") - posca_output_result(time_new, test_rx_pkt_s_e, - test_rx_cache_s_e, - bandwidth, latency, cpu_load) - if (cpu_load < con_dic['test_cpu_load\ - ']) and (latency < con_dic['test_latency']): - if (abs(bandwidth_tmp-bandwidth)/bandwidth < 0.05): - print("%s,%s,%s,%s,%s,%s") % (test_rx_pkt_s_e, - test_rx_cache_s_e, - test_tx_cache_s_e, - bandwidth, - latency, - cpu_load) - return True - else: - bandwidth_tmp = bandwidth - else: - print("%s,%s,%s,%s,%s,%s") % (test_rx_pkt_s_e, - test_rx_cache_s_e, - test_tx_cache_s_e, - bandwidth, - latency, - cpu_load) - return True + file_config["file_path"] = "/home/opnfv/bottlenecks/testsuites/posca/\ +test_result/factor_system_system_bandwidth_%s.json" % (time_new) + file_config["test_type"] = "system_bandwidth_biggest" + data["rx_pkt_sizes"] = rx_pkt_s_a + data["tx_pkt_sizes"] = tx_pkt_s_a + print("######test package begin######") + pkt_reply = system_pkt_bandwidth( + test_con_id, data, file_config, con_dic) + + print("######find system bandwidth######") + print("rx_msg_size:%d tx_msg_size:%d\n" % + (pkt_reply["rx_msg_size"], pkt_reply["tx_msg_size"])) + date_tran = common_script.posca_tran_data( + con_dic['ES_ip'], file_config["file_path"]) + return True def main(): @@ -141,11 +120,27 @@ def main(): else: testcase_cfg = args.conf - con_dic = posca_config_read(testcase_cfg) + con_str = [ + 'test_ip', 'tool', 'test_time', 'protocol', + 'tx_pkt_sizes', 'rx_pkt_sizes', 'cpu_load', + 'latency', 'ES_ip', 'dashboard' + ] + starttime = datetime.datetime.now() + config = ConfigParser.ConfigParser() + con_dic = common_script.posca_config_read(testcase_cfg, con_str, config) posca_env_check() posca_run(con_dic) - + endtime = datetime.datetime.now() + if con_dic["dashboard"] == "y": + cmd = '/home/opnfv/bottlenecks/testsuites/posca/testcase_dashboard/\ +system_bandwidth.py' + pargs = [INTERPRETER, cmd] + print("Begin to establish dashboard, False means already exist.\n") + sub_result = subprocess.Popen(pargs) + sub_result.wait() + print("System Bandwidth testing time : %s" %(endtime - starttime)) time.sleep(5) if __name__ == '__main__': main() + |