2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2010 Patrick Crews
7
## This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
""" sysbench_test_management:
22
code related to the gathering / analysis / management of
24
ie - collecting the list of tests in each suite, then
25
gathering additional, relevant information for sysbench mode
33
from ConfigParser import RawConfigParser
35
import lib.test_mgmt.test_management as test_management
40
"""Holds info on a single sysbench test
43
def __init__( self, system_manager, name=None
44
, fullname = None, server_requirements=[[]]
45
, comment=None, test_command=None, cnf_path=None
47
self.system_manager = system_manager
48
self.logging = self.system_manager.logging
49
self.skip_keys = ['system_manager','logging']
51
self.fullname = fullname
52
self.suitename = 'sysbench_tests'
54
self.comment = comment
55
self.server_requirements = server_requirements
56
self.test_command = test_command
57
self.cnf_path = cnf_path
60
self.system_manager.logging.debug_class(self)
63
if self.skip_flag or self.disable:
72
class testManager(test_management.testManager):
73
"""Deals with scanning test directories, gathering test cases, and
74
collecting per-test information (opt files, etc) for use by the
79
def __init__(self, verbose, debug, default_engine, dotest, skiptest
80
, reorder, suitelist, suitepaths, system_manager
82
super(testManager, self).__init__( verbose, debug, default_engine
83
, dotest, skiptest, reorder
84
, suitelist, suitepaths
85
, system_manager, test_cases, mode)
86
self.suitepaths = [os.path.join(self.testdir,'sysbench_tests')]
88
self.suitelist = ['readonly']
90
self.suitelist = suitelist
92
def process_suite(self,suite_dir):
93
"""Process a test suite.
94
Look for sysbench tests, which are nice clean conf files
98
# We know this based on how we organize sysbench test conf files
99
suite_name = os.path.basename(suite_dir)
101
self.system_manager.logging.verbose("Processing suite: %s" %(suite_name))
102
testlist = [os.path.join(suite_dir,test_file) for test_file in sorted(os.listdir(suite_dir)) if test_file.endswith('.cnf')]
104
# Search for specific test names
105
if self.desired_tests: # We have specific, named tests we want from the suite(s)
107
for test in self.desired_tests:
108
if test.endswith('.cnf'):
112
test = os.path.join(suite_dir,test)
114
tests_to_use.append(test)
115
testlist = tests_to_use
116
for test_case in testlist:
117
self.add_test(self.process_test_file(suite_name, test_case))
120
def process_test_file(self, suite_name, testfile):
121
""" We convert the info in a testfile into a testCase object """
123
config_reader = RawConfigParser()
124
config_reader.read(testfile)
125
# test_name = filename - .cnf...simpler
126
test_name = os.path.basename(testfile).replace('.cnf','')
127
test_comment = config_reader.get('test_info','comment')
128
server_requirements = self.process_server_reqs(config_reader.get('test_servers','servers'))
129
test_command = config_reader.get('test_command','command')
130
return testCase( self.system_manager
132
, fullname = "%s.%s" %(suite_name, test_name)
133
, server_requirements = server_requirements
134
, test_command = test_command
135
, cnf_path = testfile
136
, debug = self.debug )
140
def process_server_reqs(self,data_string):
141
""" We read in the list of lists as a string, so we need to
142
handle this / break it down into proper chunks
146
# We expect to see a list of lists and throw away the
148
option_sets = data_string[1:-1].strip().split(',')
149
for option_set in option_sets:
150
server_reqs.append([option_set[1:-1].strip()])
153
def record_test_result(self, test_case, test_status, output, exec_time):
154
""" Accept the results of an executed testCase for further
158
if test_status not in self.executed_tests:
159
self.executed_tests[test_status] = [test_case]
161
self.executed_tests[test_status].append(test_case)
163
self.logging.test_report( test_case.fullname, test_status
164
, str(exec_time), output
165
, report_output= True)