JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / 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     def __init__(self, path="/etc/vstf/perf/",
24                  filename="sw_perf.batch-settings",
25                  mode=sets.SETS_SINGLE):
26         self.dbconn = DbManage()
27         super(PerfSettings, self).__init__(path, filename, mode)
28
29     def clear(self):
30         for item in cst.SCENARIOS:
31             func = getattr(self, "set_" + item)
32             func([])
33
34     def mclear(self):
35         for item in cst.SCENARIOS:
36             func = getattr(self, "mset_" + item)
37             func([])
38
39     def add_case(self, value):
40         scenario = self.dbconn.query_scenario(value["case"])
41         LOG.info(scenario)
42         if not scenario:
43             LOG.warn("not support the case:%s", value["case"])
44             return
45         self._adding_file("add", self._mset, self._fset, scenario, check=self._check_add)(value)
46
47     def madd_case(self, case):
48         scenario = self.dbconn.query_scenario(case)
49         if not scenario:
50             LOG.warn("not support the case:%s", case)
51             return
52         self._adding_memory("madd", self._mset, scenario, check=self._check_add)(case)
53
54     @deco.dcheck('sizes')
55     @deco.dcheck("type", choices=cst.TTYPES)
56     @deco.dcheck("profile", choices=cst.PROVIDERS)
57     @deco.dcheck("protocol", choices=cst.TPROTOCOLS)
58     @deco.dcheck("tool", choices=cst.TOOLS)
59     @deco.dcheck('case')
60     def _check_add(self, value):
61         LOG.info("check successfully")
62
63     def sinput(self):
64         if raw_choice("if clean all Test case"):
65             self.clear()
66         while True:
67             if raw_choice("if add a new Test case"):
68                 case = self.raw_addcase()
69                 self.add_case(case)
70             else:
71                 break
72         print "%s set finish: " % (self._filename)
73         print "+++++++++++++++++++++++++++++++++++"
74         pprint.pprint(self.settings)
75         print "+++++++++++++++++++++++++++++++++++"
76         return True
77     
78     @deco.vstf_input('sizes', types=list)
79     @deco.vstf_input("type", types=str, choices=cst.TTYPES)
80     @deco.vstf_input("profile", types=str, choices=cst.PROVIDERS)
81     @deco.vstf_input("protocol", types=str, choices=cst.TPROTOCOLS)
82     @deco.vstf_input("tool", types=str, choices=cst.TOOLS)
83     @deco.vstf_input('case')
84     def raw_addcase(self):
85         print "---------------------------------------"
86         print "Please vstf add case info like:"
87         print "    'case': 'Ti-1',"
88         print "    'tool': 'netperf',"
89         print "    'protocol': 'udp',"
90         print "    'profile': 'rdp',"
91         print "    'type': 'latency',"
92         print "    'sizes': [64, 128, 512, 1024]"
93         print "---------------------------------------"
94
95
96 def unit_test():
97     perf_settings = PerfSettings()
98     perf_settings.sinput()
99
100     from vstf.common.log import setup_logging
101     setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-perf-settings.log", clevel=logging.DEBUG)
102
103
104 if __name__ == '__main__':
105     unit_test()