~drizzle-trunk/drizzle/development

2317.1.1 by patrick crews
Updates to dbqp to add a sysbench mode. Created test suites to duplicate readonly / readwrite drizzle-automation tests. Still needs some work, but tests execute
1
#! /usr/bin/env python
2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
#
5
# Copyright (C) 2010 Patrick Crews
6
#
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.
11
#
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.
16
#
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
20
21
""" sysbench_test_management:
22
    code related to the gathering / analysis / management of 
23
    the test cases
24
    ie - collecting the list of tests in each suite, then
25
    gathering additional, relevant information for sysbench mode
26
27
"""
28
29
# imports
30
import os
31
import re
32
import sys
33
from ConfigParser import RawConfigParser
34
35
import lib.test_mgmt.test_management as test_management
36
37
38
    
39
class testCase:
40
    """Holds info on a single sysbench test
41
 
42
    """
43
    def __init__( self, system_manager, name=None
44
                , fullname = None, server_requirements=[[]]
45
                , comment=None, test_command=None, cnf_path=None
46
                , debug=False ):
47
        self.system_manager = system_manager
48
        self.logging = self.system_manager.logging
49
        self.skip_keys = ['system_manager','logging']
50
        self.name = name
51
        self.fullname = fullname
52
        self.suitename = 'sysbench_tests'
53
        self.master_sh = None
54
        self.comment = comment
55
        self.server_requirements = server_requirements
56
        self.test_command = test_command
57
        self.cnf_path = cnf_path
58
        
59
        if debug:
60
            self.system_manager.logging.debug_class(self)
61
62
    def should_run(self):
63
        if self.skip_flag or self.disable:
64
            return 0
65
        else:
66
            return 1
67
68
 
69
        
70
        
71
          
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
75
       test-runner
76
77
    """
78
79
    def __init__(self, verbose, debug, default_engine, dotest, skiptest
80
                , reorder, suitelist, suitepaths, system_manager
81
                , test_cases, mode):
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')]
87
        if suitelist is None:
88
            self.suitelist = ['readonly']
89
        else:
90
            self.suitelist = suitelist
91
92
    def process_suite(self,suite_dir):
93
        """Process a test suite.
94
           Look for sysbench tests, which are nice clean conf files
95
        
96
        """
97
98
        # We know this based on how we organize sysbench test conf files
99
        suite_name = os.path.basename(suite_dir) 
100
        if self.verbose:
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')]
103
104
        # Search for specific test names
105
        if self.desired_tests: # We have specific, named tests we want from the suite(s)
106
           tests_to_use = []
107
           for test in self.desired_tests:
108
               if test.endswith('.cnf'): 
109
                   pass
110
               else:
111
                   test = test+'.cnf'
112
               test = os.path.join(suite_dir,test)
113
               if test in testlist:
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))
118
119
120
    def process_test_file(self, suite_name, testfile):
121
        """ We convert the info in a testfile into a testCase object """
122
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
131
                       , name = test_name
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 )
137
138
        #sys.exit(0)
139
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
143
144
        """
145
        server_reqs = []
146
        # We expect to see a list of lists and throw away the 
147
        # enclosing brackets
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()])
151
        return server_reqs
152
153
    def record_test_result(self, test_case, test_status, output, exec_time):
154
        """ Accept the results of an executed testCase for further
155
            processing.
156
 
157
        """
158
        if test_status not in self.executed_tests:
159
            self.executed_tests[test_status] = [test_case]
160
        else:
161
            self.executed_tests[test_status].append(test_case)
162
        # report
163
        self.logging.test_report( test_case.fullname, test_status
164
                                , str(exec_time), output
165
                                , report_output= True)