Bug fix: yardstick result return no content
[bottlenecks.git] / testsuites / posca / testcase_script / posca_factor_system_bandwidth.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 utils.logger as log
18 import utils.infra_setup.runner.yardstick as Runner
19 from utils.parser import Parser as conf_parser
20 # --------------------------------------------------
21 # logging configuration
22 # --------------------------------------------------
23 LOG = log.Logger(__name__).getLogger()
24
25 test_dict = {
26     "action": "runTestCase",
27     "args": {
28         "opts": {
29             "task-args": {}
30         },
31         "testcase": "netperf_bottlenecks"
32     }
33 }
34
35
36 def env_pre():
37     Runner.Create_Incluxdb()
38
39
40 def do_test(test_config, con_dic):
41     test_dict['args']['opts']['task-args'] = test_config
42     Task_id = Runner.Send_Data(test_dict, con_dic['runner_config'])
43     time.sleep(con_dic['test_config']['test_time'])
44     Data_Reply = Runner.Get_Reply(con_dic['runner_config'], Task_id)
45     try:
46         test_date =\
47             Data_Reply[con_dic['runner_config']['yardstick_testcase']][0]
48     except IndexError:
49         test_date = do_test(test_config, con_dic)
50     return test_date
51
52
53 def run(con_dic):
54     data = {}
55     rx_pkt_a = con_dic['test_config']['rx_pkt_sizes'].split(',')
56     tx_pkt_a = con_dic['test_config']['tx_pkt_sizes'].split(',')
57     data["rx_pkt_sizes"] = rx_pkt_a
58     data["tx_pkt_sizes"] = tx_pkt_a
59     con_dic["result_file"] = os.path.dirname(
60         os.path.abspath(__file__)) + "/test_case/result"
61     date_id = 0
62     cur_role_result = 1
63     pre_role_result = 1
64     pre_reply = {}
65     data_return = {}
66     data_max = {}
67     data_return["throughput"] = 1
68     if con_dic["runner_config"]["yardstick_test_ip"] is None:
69         con_dic["runner_config"]["yardstick_test_ip"] =\
70             conf_parser.ip_parser("yardstick_test_ip")
71     for test_x in data["tx_pkt_sizes"]:
72         data_max["throughput"] = 1
73         bandwidth_tmp = 1
74         for test_y in data["rx_pkt_sizes"]:
75             test_config = {
76                 "tx_msg_size": float(test_x),
77                 "rx_msg_size": float(test_y),
78                 "test_time": con_dic['test_config']['test_time']
79             }
80             date_id = date_id + 1
81             data_reply = do_test(test_config, con_dic)
82             bandwidth = float(data_reply["throughput"])
83             if (data_max["throughput"] < bandwidth):
84                 data_max = data_reply
85             if (abs(bandwidth_tmp - bandwidth) / bandwidth_tmp < 0.025):
86                 print(pre_reply)
87                 break
88             else:
89                 pre_reply = data_reply
90                 bandwidth_tmp = bandwidth
91         cur_role_result = float(pre_reply["throughput"])
92         if (abs(pre_role_result - cur_role_result) / pre_role_result < 0.025):
93             print("date_id is %d,package return at line 111\n" % date_id)
94         if data_return["throughput"] < data_max["throughput"]:
95             data_return = data_max
96         pre_role_result = cur_role_result
97     print("date_id is %d,id return success\n" % date_id)
98     return data_return