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.controller.settings.settings as sets
14 import vstf.common.decorator as deco
15 from vstf.common.input import raw_choice
17 LOG = logging.getLogger(__name__)
20 class ToolSettings(sets.Settings):
25 filename="sw_perf.tool-settings",
26 mode=sets.SETS_DEFAULT):
27 super(ToolSettings, self).__init__(path, filename, mode)
29 def _register_func(self):
36 func_name = "set_%s" % (item)
45 check=self._check_keys))
47 def _check_keys(self, value):
48 keys = ['threads', 'wait', 'time']
49 if not isinstance(value, dict):
50 raise Exception("type is error: %s" % (str(value)))
52 if key not in value.keys():
53 raise Exception("keys[%s] is missing: %s" % (key, str(value)))
60 info = "if set %s properties" % tool
62 properties = self.raw_properties()
63 func = getattr(self, "set_%s" % tool)
66 print "%s set finish: " % self._filename
67 print "+++++++++++++++++++++++++++++++++++++++++"
68 pprint.pprint(self.settings, indent=4)
69 print "+++++++++++++++++++++++++++++++++++++++++"
71 @deco.vstf_input("time", types=int)
72 @deco.vstf_input("wait", types=int)
73 @deco.vstf_input("threads", types=int)
74 def raw_properties(self):
75 print "---------------------------------------"
76 print "Please vstf set tool properties like:"
77 print " 'threads': 2,"
80 print "---------------------------------------"
84 from vstf.common.log import setup_logging
87 log_file="/var/log/vstf/tool-settings.log",
89 tool_settings = ToolSettings()
95 tool_settings.set_pktgen(value)
96 tool_settings.set_netperf(value)
97 tool_settings.set_iperf(value)
98 tool_settings.set_qperf(value)
99 LOG.info(tool_settings.settings)
102 if __name__ == '__main__':