Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / controller / spirent / appliance.py
1 #!/usr/bin/python
2 """
3     @author: l00190809
4     @group: Huawei Ltd 
5 """
6 import os
7 import logging
8
9 import stevedore
10 from vstf.controller.spirent.common.result_analysis import analysis_instance as analysis_instance
11 LOG = logging.getLogger(__name__)
12
13
14 class spirentSTC(object):
15     def __init__(self):
16         super(spirentSTC, self).__init__()
17         self.runmodel = None
18
19     def init(self, conner="", measurand="", model="", **kwargs):
20         """
21         :param str    conner: the spirent tester, the agent id of spirent vm
22         :param list   measurand: the tested host's agent id
23         :param str    model: the model used of the tested host
24         
25         """
26         mgr = stevedore.driver.DriverManager(namespace="spirent.model.plugins",
27                                              name=model,
28                                              invoke_on_load=False)
29         self.TempMod = mgr.driver(kwargs)
30         self.conner = conner
31         self.measurand = measurand
32
33     @property
34     def run(self):
35         LOG.info(vars(self.runmodel))
36         return True
37
38
39 def run(config):
40     # test option parser 
41     if not os.path.exists(config['configfile']):
42         LOG.error('The config file %s does exist.', config.get("configfile"))
43         return False
44
45     runmodel = None  # Tnv_Model(config = config)
46
47     # check parameter valid
48     flag = runmodel.check_parameter_invalid()
49     if not flag:
50         LOG.error("[ERROR]Check parameter invalid.")
51         return False
52
53     # check logical parameter in the 
54     flag = runmodel.check_logic_invalid
55     if not flag:
56         LOG.error("[ERROR]Check logic parameter with host invalid.")
57         return False
58
59     init_flows_tables = runmodel.read_flow_init
60     LOG.info(init_flows_tables)
61
62     # print init_flows_tables
63     update_flows = runmodel.flow_build
64     # print update_flows
65     LOG.info(update_flows)
66
67     flag = runmodel.affinity_bind(aff_strategy=1)
68     if not flag:
69         LOG.error("runmodel affinity bind failed.")
70         return False
71
72     # Get the result
73     result = {}
74     for suite in ["frameloss", "throughput"]:
75         ret, test_result = runmodel.Test_Run(suite)
76         if not ret:
77             LOG.error("[ERROR]Run rfc2544 %s test failed.", suite)
78             return False
79         try:
80             ret, result_dict = restrucData(test_result)
81         except:
82             LOG.error("[ERROR]Restructure the test data failed.")
83         perfdata = getResult(result_dict)
84         columndata = getResultColumn(result_dict)
85         column_array, data_array = analysis_instance.analyseResult(suite, columndata, perfdata)
86         temp = {'columns': column_array, 'data': data_array}
87         result[suite] = temp
88     return result
89
90
91 if __name__ == "__main__":
92     run(None)