1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
13 import vstf.common.decorator as deco
14 import vstf.common.constants as cst
15 import vstf.controller.settings.settings as sets
16 from vstf.common.input import raw_choice
17 from vstf.controller.database.dbinterface import DbManage
19 LOG = logging.getLogger(__name__)
22 class PerfSettings(sets.Settings):
23 def __init__(self, path="/etc/vstf/perf/",
24 filename="sw_perf.batch-settings",
25 mode=sets.SETS_SINGLE):
26 self.dbconn = DbManage()
27 super(PerfSettings, self).__init__(path, filename, mode)
30 for item in cst.SCENARIOS:
31 func = getattr(self, "set_" + item)
35 for item in cst.SCENARIOS:
36 func = getattr(self, "mset_" + item)
39 def add_case(self, value):
40 scenario = self.dbconn.query_scenario(value["case"])
43 LOG.warn("not support the case:%s", value["case"])
45 self._adding_file("add", self._mset, self._fset, scenario, check=self._check_add)(value)
47 def madd_case(self, case):
48 scenario = self.dbconn.query_scenario(case)
50 LOG.warn("not support the case:%s", case)
52 self._adding_memory("madd", self._mset, scenario, check=self._check_add)(case)
55 @deco.dcheck("type", choices=cst.TTYPES)
56 @deco.dcheck("profile", choices=cst.PROVIDERS)
57 @deco.dcheck("protocol", choices=cst.TPROTOCOLS)
58 @deco.dcheck("tool", choices=cst.TOOLS)
60 def _check_add(self, value):
61 LOG.info("check successfully")
64 if raw_choice("if clean all Test case"):
67 if raw_choice("if add a new Test case"):
68 case = self.raw_addcase()
72 print "%s set finish: " % (self._filename)
73 print "+++++++++++++++++++++++++++++++++++"
74 pprint.pprint(self.settings)
75 print "+++++++++++++++++++++++++++++++++++"
78 @deco.vstf_input('sizes', types=list)
79 @deco.vstf_input("type", types=str, choices=cst.TTYPES)
80 @deco.vstf_input("profile", types=str, choices=cst.PROVIDERS)
81 @deco.vstf_input("protocol", types=str, choices=cst.TPROTOCOLS)
82 @deco.vstf_input("tool", types=str, choices=cst.TOOLS)
83 @deco.vstf_input('case')
84 def raw_addcase(self):
85 print "---------------------------------------"
86 print "Please vstf add case info like:"
87 print " 'case': 'Ti-1',"
88 print " 'tool': 'netperf',"
89 print " 'protocol': 'udp',"
90 print " 'profile': 'rdp',"
91 print " 'type': 'latency',"
92 print " 'sizes': [64, 128, 512, 1024]"
93 print "---------------------------------------"
97 perf_settings = PerfSettings()
98 perf_settings.sinput()
100 from vstf.common.log import setup_logging
101 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-perf-settings.log", clevel=logging.DEBUG)
104 if __name__ == '__main__':