Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / controller / settings / perf_settings.py
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3 # author: wly
4 # date: 2015-09-28
5 # see license for license details
6
7 import pprint
8 import logging
9
10 import vstf.common.decorator as deco
11 import vstf.common.constants as cst
12 import vstf.controller.settings.settings as sets
13 from vstf.common.input import raw_choice
14 from vstf.controller.database.dbinterface import DbManage
15
16 LOG = logging.getLogger(__name__)
17
18
19 class PerfSettings(sets.Settings):
20     def __init__(self, path="/etc/vstf/perf/",
21                  filename="sw_perf.batch-settings",
22                  mode=sets.SETS_SINGLE):
23         self.dbconn = DbManage()
24         super(PerfSettings, self).__init__(path, filename, mode)
25
26     def clear(self):
27         for item in cst.SCENARIOS:
28             func = getattr(self, "set_" + item)
29             func([])
30
31     def mclear(self):
32         for item in cst.SCENARIOS:
33             func = getattr(self, "mset_" + item)
34             func([])
35
36     def add_case(self, value):
37         scenario = self.dbconn.query_scenario(value["case"])
38         LOG.info(scenario)
39         if not scenario:
40             LOG.warn("not support the case:%s", value["case"])
41             return
42         self._adding_file("add", self._mset, self._fset, scenario, check=self._check_add)(value)
43
44     def madd_case(self, case):
45         scenario = self.dbconn.query_scenario(case)
46         if not scenario:
47             LOG.warn("not support the case:%s", case)
48             return
49         self._adding_memory("madd", self._mset, scenario, check=self._check_add)(case)
50
51     @deco.dcheck('sizes')
52     @deco.dcheck("type", choices=cst.TTYPES)
53     @deco.dcheck("profile", choices=cst.PROFILES)
54     @deco.dcheck("protocol", choices=cst.TPROTOCOLS)
55     @deco.dcheck("tool", choices=cst.TOOLS)
56     @deco.dcheck('case')
57     def _check_add(self, value):
58         LOG.info("check successfully")
59
60     def sinput(self):
61         if raw_choice("if clean all Test case"):
62             self.clear()
63         while True:
64             if raw_choice("if add a new Test case"):
65                 case = self.raw_addcase()
66                 self.add_case(case)
67             else:
68                 break
69         print "%s set finish: " % (self._filename)
70         print "+++++++++++++++++++++++++++++++++++"
71         pprint.pprint(self.settings)
72         print "+++++++++++++++++++++++++++++++++++"
73         return True
74     
75     @deco.vstf_input('sizes', types=list)
76     @deco.vstf_input("type", types=str, choices=cst.TTYPES)
77     @deco.vstf_input("profile", types=str, choices=cst.PROFILES)
78     @deco.vstf_input("protocol", types=str, choices=cst.TPROTOCOLS)
79     @deco.vstf_input("tool", types=str, choices=cst.TOOLS)
80     @deco.vstf_input('case')
81     def raw_addcase(self):
82         print "---------------------------------------"
83         print "Please vstf add case info like:"
84         print "    'case': 'Ti-1',"
85         print "    'tool': 'netperf',"
86         print "    'protocol': 'udp',"
87         print "    'profile': 'rdp',"
88         print "    'type': 'latency',"
89         print "    'sizes': [64, 128, 512, 1024]"
90         print "---------------------------------------"
91
92
93 def unit_test():
94     perf_settings = PerfSettings()
95     perf_settings.sinput()
96
97     from vstf.common.log import setup_logging
98     setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-perf-settings.log", clevel=logging.DEBUG)
99
100
101 if __name__ == '__main__':
102     unit_test()