JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / 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     def __init__(self):
20         super(spirentSTC, self).__init__()
21         self.runmodel = None
22
23     def init(self, conner="", measurand="", model="", **kwargs):
24         """
25         :param str    conner: the spirent tester, the agent id of spirent vm
26         :param list   measurand: the tested host's agent id
27         :param str    model: the model used of the tested host
28         
29         """
30         mgr = stevedore.driver.DriverManager(namespace="spirent.model.plugins",
31                                              name=model,
32                                              invoke_on_load=False)
33         self.TempMod = mgr.driver(kwargs)
34         self.conner = conner
35         self.measurand = measurand
36
37     @property
38     def run(self):
39         LOG.info(vars(self.runmodel))
40         return True
41
42
43 def run(config):
44     # test option parser 
45     if not os.path.exists(config['configfile']):
46         LOG.error('The config file %s does exist.', config.get("configfile"))
47         return False
48
49     runmodel = None  # Tnv_Model(config = config)
50
51     # check parameter valid
52     flag = runmodel.check_parameter_invalid()
53     if not flag:
54         LOG.error("[ERROR]Check parameter invalid.")
55         return False
56
57     # check logical parameter in the 
58     flag = runmodel.check_logic_invalid
59     if not flag:
60         LOG.error("[ERROR]Check logic parameter with host invalid.")
61         return False
62
63     init_flows_tables = runmodel.read_flow_init
64     LOG.info(init_flows_tables)
65
66     # print init_flows_tables
67     update_flows = runmodel.flow_build
68     # print update_flows
69     LOG.info(update_flows)
70
71     flag = runmodel.affinity_bind(aff_strategy=1)
72     if not flag:
73         LOG.error("runmodel affinity bind failed.")
74         return False
75
76     # Get the result
77     result = {}
78     for suite in ["frameloss", "throughput"]:
79         ret, test_result = runmodel.Test_Run(suite)
80         if not ret:
81             LOG.error("[ERROR]Run rfc2544 %s test failed.", suite)
82             return False
83         try:
84             ret, result_dict = restrucData(test_result)
85         except:
86             LOG.error("[ERROR]Restructure the test data failed.")
87         perfdata = getResult(result_dict)
88         columndata = getResultColumn(result_dict)
89         column_array, data_array = analysis_instance.analyseResult(suite, columndata, perfdata)
90         temp = {'columns': column_array, 'data': data_array}
91         result[suite] = temp
92     return result
93
94
95 if __name__ == "__main__":
96     run(None)