5 # see license for license details
10 import vstf.common.decorator as deco
11 import vstf.common.constants as cst
12 import vstf.controller.settings.settings as sets
13 from vstf.common.input import raw_choice
14 from vstf.controller.database.dbinterface import DbManage
16 LOG = logging.getLogger(__name__)
19 class PerfSettings(sets.Settings):
20 def __init__(self, path="/etc/vstf/perf/",
21 filename="sw_perf.batch-settings",
22 mode=sets.SETS_SINGLE):
23 self.dbconn = DbManage()
24 super(PerfSettings, self).__init__(path, filename, mode)
27 for item in cst.SCENARIOS:
28 func = getattr(self, "set_" + item)
32 for item in cst.SCENARIOS:
33 func = getattr(self, "mset_" + item)
36 def add_case(self, value):
37 scenario = self.dbconn.query_scenario(value["case"])
40 LOG.warn("not support the case:%s", value["case"])
42 self._adding_file("add", self._mset, self._fset, scenario, check=self._check_add)(value)
44 def madd_case(self, case):
45 scenario = self.dbconn.query_scenario(case)
47 LOG.warn("not support the case:%s", case)
49 self._adding_memory("madd", self._mset, scenario, check=self._check_add)(case)
52 @deco.dcheck("type", choices=cst.TTYPES)
53 @deco.dcheck("profile", choices=cst.PROFILES)
54 @deco.dcheck("protocol", choices=cst.TPROTOCOLS)
55 @deco.dcheck("tool", choices=cst.TOOLS)
57 def _check_add(self, value):
58 LOG.info("check successfully")
61 if raw_choice("if clean all Test case"):
64 if raw_choice("if add a new Test case"):
65 case = self.raw_addcase()
69 print "%s set finish: " % (self._filename)
70 print "+++++++++++++++++++++++++++++++++++"
71 pprint.pprint(self.settings)
72 print "+++++++++++++++++++++++++++++++++++"
75 @deco.vstf_input('sizes', types=list)
76 @deco.vstf_input("type", types=str, choices=cst.TTYPES)
77 @deco.vstf_input("profile", types=str, choices=cst.PROFILES)
78 @deco.vstf_input("protocol", types=str, choices=cst.TPROTOCOLS)
79 @deco.vstf_input("tool", types=str, choices=cst.TOOLS)
80 @deco.vstf_input('case')
81 def raw_addcase(self):
82 print "---------------------------------------"
83 print "Please vstf add case info like:"
84 print " 'case': 'Ti-1',"
85 print " 'tool': 'netperf',"
86 print " 'protocol': 'udp',"
87 print " 'profile': 'rdp',"
88 print " 'type': 'latency',"
89 print " 'sizes': [64, 128, 512, 1024]"
90 print "---------------------------------------"
94 perf_settings = PerfSettings()
95 perf_settings.sinput()
97 from vstf.common.log import setup_logging
98 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-perf-settings.log", clevel=logging.DEBUG)
101 if __name__ == '__main__':