VNF characterization scale_up test, untested
[bottlenecks.git] / testsuites / posca / testcase_script / posca_factor_vnf_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 utils.logger as log
18 import utils.infra_setup.runner.yardstick as Runner
19 from utils.parser import Parser as conf_parser
20 import testsuites.posca.testcase_dashboard.system_bandwidth as DashBoard
21 # --------------------------------------------------
22 # logging configuration
23 # --------------------------------------------------
24 LOG = log.Logger(__name__).getLogger()
25
26 testfile = os.path.basename(__file__)
27 testcase, file_format = os.path.splitext(testfile)
28
29
30 def env_pre(con_dic):
31     Runner.Create_Incluxdb(con_dic['runner_config'])
32
33
34 def config_to_result(test_config, test_result):
35     testdata = {}
36     test_result["throughput"] = float(test_result["throughput"])
37     test_result.update(test_config)
38     testdata["data_body"] = test_result
39     testdata["testcase"] = testcase
40     return testdata
41
42
43 def do_test(test_config, con_dic):
44     # this will change
45     test_case = con_dic['runner_config']['yardstick_testcase']
46     test_dict = {
47         "action": "runTestCase",
48         "args": {
49             "opts": {
50                 "task-args": test_config
51             },
52             "testcase": test_case
53         }
54     }
55     Task_id = Runner.Send_Data(test_dict, con_dic['runner_config'])
56     time.sleep(con_dic['test_config']['test_time'])
57     Data_Reply = Runner.Get_Reply(con_dic['runner_config'], Task_id)
58     try:
59         test_date =\
60             Data_Reply[con_dic['runner_config']['yardstick_testcase']][0]
61     except IndexError:
62         test_date = do_test(test_config, con_dic)
63
64     save_data = config_to_result(test_config, test_date)
65     if con_dic['runner_config']['dashboard'] == 'y':
66         DashBoard.dashboard_send_data(con_dic['runner_config'], save_data)
67
68     return save_data["data_body"]
69
70
71 def run(con_dic):
72     s = con_dic['test_config']['scale_up_values']
73
74     scale_up_values = [
75         (c, m * s['mem_unit']) for c in
76         range(s['cpus_min'], s['cpus_max'], s['cpus_incr'])
77         for m in range(s['mem_min'], s['mem_max'], s['mem_incr'])
78     ]
79     data = {
80         "scale_up_values": scale_up_values
81     }
82     con_dic["result_file"] = os.path.dirname(
83         os.path.abspath(__file__)) + "/test_case/result"
84     pre_role_result = 1
85     data_return = {}
86     data_max = {}
87     data_return["throughput"] = 1
88
89     if con_dic["runner_config"]["yardstick_test_ip"] is None:
90         con_dic["runner_config"]["yardstick_test_ip"] =\
91             conf_parser.ip_parser("yardstick_test_ip")
92
93     env_pre(con_dic)
94
95     if con_dic["runner_config"]["dashboard"] == 'y':
96         if con_dic["runner_config"]["dashboard_ip"] is None:
97             con_dic["runner_config"]["dashboard_ip"] =\
98                 conf_parser.ip_parser("dashboard")
99         LOG.info("Create Dashboard data")
100         DashBoard.dashboard_system_bandwidth(con_dic["runner_config"])
101
102     bandwidth_tmp = 1
103     # vcpus and mem are scaled together
104     for vcpus, mem in data["scale_up_values"]:
105         data_max["throughput"] = 1
106         test_config = {
107             "vcpus": vcpus,
108             "mem": mem,
109             "test_time": con_dic['test_config']['test_time']
110         }
111         data_reply = do_test(test_config, con_dic)
112         conf_parser.result_to_file(data_reply, con_dic["out_file"])
113         # TODO: figure out which KPI to use
114         bandwidth = data_reply["throughput"]
115         if data_max["throughput"] < bandwidth:
116             data_max = data_reply
117         if abs(bandwidth_tmp - bandwidth) / float(bandwidth_tmp) < 0.025:
118             LOG.info("this group of data has reached top output")
119             break
120         else:
121             pre_reply = data_reply
122             bandwidth_tmp = bandwidth
123         cur_role_result = float(pre_reply["throughput"])
124         if (abs(pre_role_result - cur_role_result) /
125                 float(pre_role_result) < 0.025):
126             LOG.info("The performance increases slowly")
127         if data_return["throughput"] < data_max["throughput"]:
128             data_return = data_max
129         pre_role_result = cur_role_result
130     LOG.info("Find bottlenecks of this config")
131     LOG.info("The max data is %d", data_return["throughput"])
132     return data_return