Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / settings / perf_settings.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 import pprint
11 import logging
12
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
18
19 LOG = logging.getLogger(__name__)
20
21
22 class PerfSettings(sets.Settings):
23
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)
29
30     def clear(self):
31         for item in cst.SCENARIOS:
32             func = getattr(self, "set_" + item)
33             func([])
34
35     def mclear(self):
36         for item in cst.SCENARIOS:
37             func = getattr(self, "mset_" + item)
38             func([])
39
40     def add_case(self, value):
41         scenario = self.dbconn.query_scenario(value["case"])
42         LOG.info(scenario)
43         if not scenario:
44             LOG.warn("not support the case:%s", value["case"])
45             return
46         self._adding_file(
47             "add",
48             self._mset,
49             self._fset,
50             scenario,
51             check=self._check_add)(value)
52
53     def madd_case(self, case):
54         scenario = self.dbconn.query_scenario(case)
55         if not scenario:
56             LOG.warn("not support the case:%s", case)
57             return
58         self._adding_memory(
59             "madd",
60             self._mset,
61             scenario,
62             check=self._check_add)(case)
63
64     @deco.dcheck('sizes')
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)
69     @deco.dcheck('case')
70     def _check_add(self, value):
71         LOG.info("check successfully")
72
73     def sinput(self):
74         if raw_choice("if clean all Test case"):
75             self.clear()
76         while True:
77             if raw_choice("if add a new Test case"):
78                 case = self.raw_addcase()
79                 self.add_case(case)
80             else:
81                 break
82         print "%s set finish: " % (self._filename)
83         print "+++++++++++++++++++++++++++++++++++"
84         pprint.pprint(self.settings)
85         print "+++++++++++++++++++++++++++++++++++"
86         return True
87
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 "---------------------------------------"
104
105
106 def unit_test():
107     perf_settings = PerfSettings()
108     perf_settings.sinput()
109
110     from vstf.common.log import setup_logging
111     setup_logging(
112         level=logging.DEBUG,
113         log_file="/var/log/vstf/vstf-perf-settings.log",
114         clevel=logging.DEBUG)
115
116
117 if __name__ == '__main__':
118     unit_test()