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):
21 def __init__(self, path="/etc/vstf", filename="sw_perf.tool-settings", mode=sets.SETS_DEFAULT):
22 super(ToolSettings, self).__init__(path, filename, mode)
24 def _register_func(self):
31 func_name = "set_%s" % (item)
32 setattr(self, func_name,
33 self._setting_file(func_name, self._mset, self._fset, item, check=self._check_keys))
35 def _check_keys(self, value):
36 keys = ['threads', 'wait', 'time']
37 if not isinstance(value, dict):
38 raise Exception("type is error: %s" % (str(value)))
40 if key not in value.keys():
41 raise Exception("keys[%s] is missing: %s" % (key, str(value)))
48 info = "if set %s properties" % tool
50 properties = self.raw_properties()
51 func = getattr(self, "set_%s" % tool)
54 print "%s set finish: " % self._filename
55 print "+++++++++++++++++++++++++++++++++++++++++"
56 pprint.pprint(self.settings, indent=4)
57 print "+++++++++++++++++++++++++++++++++++++++++"
59 @deco.vstf_input("time", types=int)
60 @deco.vstf_input("wait", types=int)
61 @deco.vstf_input("threads", types=int)
62 def raw_properties(self):
63 print "---------------------------------------"
64 print "Please vstf set tool properties like:"
65 print " 'threads': 2,"
68 print "---------------------------------------"
72 from vstf.common.log import setup_logging
73 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/tool-settings.log", clevel=logging.INFO)
74 tool_settings = ToolSettings()
80 tool_settings.set_pktgen(value)
81 tool_settings.set_netperf(value)
82 tool_settings.set_iperf(value)
83 tool_settings.set_qperf(value)
84 LOG.info(tool_settings.settings)
87 if __name__ == '__main__':