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