Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / spirent / appliance.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import os
11 import logging
12
13 import stevedore
14 from vstf.controller.spirent.common.result_analysis import analysis_instance as analysis_instance
15 LOG = logging.getLogger(__name__)
16
17
18 class spirentSTC(object):
19
20     def __init__(self):
21         super(spirentSTC, self).__init__()
22         self.runmodel = None
23
24     def init(self, conner="", measurand="", model="", **kwargs):
25         """
26         :param str    conner: the spirent tester, the agent id of spirent vm
27         :param list   measurand: the tested host's agent id
28         :param str    model: the model used of the tested host
29
30         """
31         mgr = stevedore.driver.DriverManager(namespace="spirent.model.plugins",
32                                              name=model,
33                                              invoke_on_load=False)
34         self.TempMod = mgr.driver(kwargs)
35         self.conner = conner
36         self.measurand = measurand
37
38     @property
39     def run(self):
40         LOG.info(vars(self.runmodel))
41         return True
42
43
44 def run(config):
45     # test option parser
46     if not os.path.exists(config['configfile']):
47         LOG.error('The config file %s does exist.', config.get("configfile"))
48         return False
49
50     runmodel = None  # Tnv_Model(config = config)
51
52     # check parameter valid
53     flag = runmodel.check_parameter_invalid()
54     if not flag:
55         LOG.error("[ERROR]Check parameter invalid.")
56         return False
57
58     # check logical parameter in the
59     flag = runmodel.check_logic_invalid
60     if not flag:
61         LOG.error("[ERROR]Check logic parameter with host invalid.")
62         return False
63
64     init_flows_tables = runmodel.read_flow_init
65     LOG.info(init_flows_tables)
66
67     # print init_flows_tables
68     update_flows = runmodel.flow_build
69     # print update_flows
70     LOG.info(update_flows)
71
72     flag = runmodel.affinity_bind(aff_strategy=1)
73     if not flag:
74         LOG.error("runmodel affinity bind failed.")
75         return False
76
77     # Get the result
78     result = {}
79     for suite in ["frameloss", "throughput"]:
80         ret, test_result = runmodel.Test_Run(suite)
81         if not ret:
82             LOG.error("[ERROR]Run rfc2544 %s test failed.", suite)
83             return False
84         try:
85             ret, result_dict = restrucData(test_result)
86         except:
87             LOG.error("[ERROR]Restructure the test data failed.")
88         perfdata = getResult(result_dict)
89         columndata = getResultColumn(result_dict)
90         column_array, data_array = analysis_instance.analyseResult(
91             suite, columndata, perfdata)
92         temp = {'columns': column_array, 'data': data_array}
93         result[suite] = temp
94     return result
95
96
97 if __name__ == "__main__":
98     run(None)