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):
24 def __init__(self, path="/etc/vstf/perf/",
25 filename="sw_perf.batch-settings",
26 mode=sets.SETS_SINGLE):
27 self.dbconn = DbManage()
28 super(PerfSettings, self).__init__(path, filename, mode)
31 for item in cst.SCENARIOS:
32 func = getattr(self, "set_" + item)
36 for item in cst.SCENARIOS:
37 func = getattr(self, "mset_" + item)
40 def add_case(self, value):
41 scenario = self.dbconn.query_scenario(value["case"])
44 LOG.warn("not support the case:%s", value["case"])
51 check=self._check_add)(value)
53 def madd_case(self, case):
54 scenario = self.dbconn.query_scenario(case)
56 LOG.warn("not support the case:%s", case)
62 check=self._check_add)(case)
65 @deco.dcheck("type", choices=cst.TTYPES)
66 @deco.dcheck("profile", choices=cst.PROVIDERS)
67 @deco.dcheck("protocol", choices=cst.TPROTOCOLS)
68 @deco.dcheck("tool", choices=cst.TOOLS)
70 def _check_add(self, value):
71 LOG.info("check successfully")
74 if raw_choice("if clean all Test case"):
77 if raw_choice("if add a new Test case"):
78 case = self.raw_addcase()
82 print "%s set finish: " % (self._filename)
83 print "+++++++++++++++++++++++++++++++++++"
84 pprint.pprint(self.settings)
85 print "+++++++++++++++++++++++++++++++++++"
88 @deco.vstf_input('sizes', types=list)
89 @deco.vstf_input("type", types=str, choices=cst.TTYPES)
90 @deco.vstf_input("profile", types=str, choices=cst.PROVIDERS)
91 @deco.vstf_input("protocol", types=str, choices=cst.TPROTOCOLS)
92 @deco.vstf_input("tool", types=str, choices=cst.TOOLS)
93 @deco.vstf_input('case')
94 def raw_addcase(self):
95 print "---------------------------------------"
96 print "Please vstf add case info like:"
97 print " 'case': 'Ti-1',"
98 print " 'tool': 'netperf',"
99 print " 'protocol': 'udp',"
100 print " 'profile': 'rdp',"
101 print " 'type': 'latency',"
102 print " 'sizes': [64, 128, 512, 1024]"
103 print "---------------------------------------"
107 perf_settings = PerfSettings()
108 perf_settings.sinput()
110 from vstf.common.log import setup_logging
113 log_file="/var/log/vstf/vstf-perf-settings.log",
114 clevel=logging.DEBUG)
117 if __name__ == '__main__':