bottlenecks offiline support
[bottlenecks.git] / testsuites / posca / testcase_script / posca_feature_testpmd_scale_up.py
1 #!/usr/bin/env python
2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 #
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 realize the function of run systembandwidth script.
11 for example this contain two part first run_script,
12 second is algorithm, this part is about how to judge the bottlenecks.
13 This test is using yardstick as a tool to begin test.'''
14
15 import os
16 import time
17 import uuid
18 import json
19 import utils.logger as log
20 from utils.parser import Parser as conf_parser
21 import utils.env_prepare.stack_prepare as stack_prepare
22 import utils.infra_setup.runner.docker_env as docker_env
23 import utils.infra_setup.runner.yardstick as yardstick_task
24
25 # --------------------------------------------------
26 # logging configuration
27 # --------------------------------------------------
28 LOG = log.Logger(__name__).getLogger()
29
30 testfile = os.path.basename(__file__)
31 testcase, file_format = os.path.splitext(testfile)
32 cidr = "/home/opnfv/repos/yardstick/samples/pvp_throughput_bottlenecks.yaml"
33 runner_DEBUG = True
34
35
36 def env_pre(con_dic):
37     LOG.info("yardstick environment prepare!")
38     stack_prepare._prepare_env_daemon(True)
39
40
41 def config_to_result(test_config, test_result):
42     final_data = []
43     print(test_result)
44     out_data = test_result["result"]["testcases"]
45     test_data = out_data["pvp_throughput_bottlenecks"]["tc_data"]
46     for result in test_data:
47         testdata = {}
48         testdata["vcpu"] = test_config["vcpu"]
49         testdata["memory"] = test_config["memory"]
50         testdata["nrFlows"] = result["data"]["nrFlows"]
51         testdata["packet_size"] = result["data"]["packet_size"]
52         testdata["throughput"] = result["data"]["throughput_rx_mbps"]
53         final_data.append(testdata)
54     return final_data
55
56
57 def testcase_parser(out_file="yardstick.out", **parameter_info):
58     cmd = yardstick_task.yardstick_command_parser(debug=runner_DEBUG,
59                                                   cidr=cidr,
60                                                   outfile=out_file,
61                                                   parameter=parameter_info)
62     return cmd
63
64
65 def do_test(test_config, Use_Dashboard, context_conf):
66     yardstick_container = docker_env.yardstick_info['container']
67     out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
68     cmd = testcase_parser(out_file=out_file, **test_config)
69     print(cmd)
70     stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
71     LOG.info(stdout)
72     loop_value = 0
73     while loop_value < 60:
74         time.sleep(2)
75         loop_value = loop_value + 1
76         with open(out_file) as f:
77             data = json.load(f)
78             if data["status"] == 1:
79                 LOG.info("yardstick run success")
80                 break
81             elif data["status"] == 2:
82                 LOG.error("yardstick error exit")
83                 exit()
84
85     save_data = config_to_result(test_config, data)
86     if Use_Dashboard is True:
87         print("use dashboard")
88     return save_data
89
90
91 def run(test_config):
92     load_config = test_config["load_manager"]
93     scenarios_conf = load_config["scenarios"]
94     Use_Dashboard = False
95
96     env_pre(None)
97     if test_config["contexts"]["yardstick_ip"] is None:
98         load_config["contexts"]["yardstick_ip"] =\
99             conf_parser.ip_parser("yardstick_test_ip")
100
101     if "dashboard" in test_config["contexts"].keys():
102         if test_config["contexts"]["dashboard_ip"] is None:
103             test_config["contexts"]["dashboard_ip"] =\
104                 conf_parser.ip_parser("dashboard")
105         LOG.info("Create Dashboard data")
106         Use_Dashboard = True
107
108     cpus = conf_parser.str_to_list(scenarios_conf["cpus"])
109     mems = conf_parser.str_to_list(scenarios_conf["mems"])
110     pkt_size = conf_parser.str_to_list(scenarios_conf["pkt_size"])
111     multistream = conf_parser.str_to_list(scenarios_conf["multistream"])
112     search_interval = scenarios_conf["search_interval"]
113
114     load_config["result_file"] = os.path.dirname(
115         os.path.abspath(__file__)) + "/test_case/result"
116
117     if len(cpus) != len(mems):
118         LOG.error("the cpus and mems config data number is not same!")
119         os._exit()
120
121     result = []
122
123     for i in range(0, len(cpus)):
124         case_config = {"vcpu": cpus[i],
125                        "memory": int(mems[i]) * 1024,
126                        "multistreams": multistream,
127                        "pktsize": pkt_size,
128                        "search_interval": search_interval}
129
130         data_reply = do_test(case_config, Use_Dashboard,
131                              test_config["contexts"])
132         result.append(data_reply)
133
134     LOG.info("Finished bottlenecks testcase")
135     LOG.info("The result data is %s", result)
136     return result