~drizzle-trunk/drizzle/development

2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
1
#! /usr/bin/env python
2235.5.2 by Stewart Smith
dbqp source (and all its libs) should use emacs python mode, not emacs C mode
2
# -*- mode: python; indent-tabs-mode: nil; -*-
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
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
""" randgen_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 randgen
26
    mode. (stocastic model-based testing)
27
28
"""
29
30
# imports
31
import os
32
import re
33
import sys
34
from ConfigParser import RawConfigParser
35
36
import lib.test_mgmt.test_management as test_management
37
38
39
    
40
class testCase:
41
    """Holds info on a single randgen test
42
 
43
    """
44
    def __init__( self, system_manager, name=None
45
                , fullname = None, server_requirements=[[]]
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
46
                , comment=None, test_command=None, cnf_path=None
47
                , debug=False ):
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
48
        self.system_manager = system_manager
49
        self.logging = self.system_manager.logging
50
        self.skip_keys = ['system_manager','logging']
51
        self.name = name
52
        self.fullname = fullname
53
        self.suitename = 'randgen_tests'
54
        self.master_sh = None
55
        self.comment = comment
56
        self.server_requirements = server_requirements
57
        self.test_command = test_command
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
58
        self.cnf_path = cnf_path
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
59
        
60
        if debug:
61
            self.system_manager.logging.debug_class(self)
62
63
    def should_run(self):
64
        if self.skip_flag or self.disable:
65
            return 0
66
        else:
67
            return 1
68
69
 
70
        
71
        
72
          
73
class testManager(test_management.testManager):
74
    """Deals with scanning test directories, gathering test cases, and 
75
       collecting per-test information (opt files, etc) for use by the
76
       test-runner
77
78
    """
79
80
    def __init__(self, verbose, debug, default_engine, dotest, skiptest
81
                , reorder, suitelist, suitepaths, system_manager
82
                , test_cases, mode):
83
        super(testManager, self).__init__( verbose, debug, default_engine
84
                                         , dotest, skiptest, reorder
85
                                         , suitelist, suitepaths
86
                                         , system_manager, test_cases, mode)
87
        self.suitepaths = [os.path.join(self.testdir,'randgen_tests')]
88
        if suitelist is None:
89
            self.suitelist = ['main']
90
        else:
91
            self.suitelist = suitelist
92
93
    def process_suite(self,suite_dir):
94
        """Process a test suite.
95
           Look for randgen tests, which are nice clean conf files
96
        
97
        """
98
99
        # We know this based on how we organize randgen test conf files
100
        suite_name = os.path.basename(suite_dir) 
101
        if self.verbose:
102
                self.system_manager.logging.verbose("Processing suite: %s" %(suite_name))
103
        testlist = [os.path.join(suite_dir,test_file) for test_file in sorted(os.listdir(suite_dir)) if test_file.endswith('.cnf')]
104
105
        # Search for specific test names
106
        if self.desired_tests: # We have specific, named tests we want from the suite(s)
107
           tests_to_use = []
108
           for test in self.desired_tests:
109
               if test.endswith('.cnf'): 
110
                   pass
111
               else:
112
                   test = test+'.cnf'
113
               test = os.path.join(suite_dir,test)
114
               if test in testlist:
115
                   tests_to_use.append(test)
116
           testlist = tests_to_use
117
        for test_case in testlist:
118
            self.add_test(self.process_test_file(suite_name, test_case))
119
120
121
    def process_test_file(self, suite_name, testfile):
122
        """ We convert the info in a testfile into a testCase object """
123
124
        config_reader = RawConfigParser()
125
        config_reader.read(testfile)
126
        # test_name = filename - .cnf...simpler
127
        test_name = os.path.basename(testfile).replace('.cnf','')
128
        test_comment = config_reader.get('test_info','comment')
129
        server_requirements = self.process_server_reqs(config_reader.get('test_servers','servers'))
130
        test_command = config_reader.get('test_command','command')
131
        return testCase( self.system_manager
132
                       , name = test_name
133
                       , fullname = "%s.%s" %(suite_name, test_name)
134
                       , server_requirements = server_requirements
135
                       , test_command = test_command
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
136
                       , cnf_path = testfile
2194.2.1 by patrick crews
Integrated randgen with dbqp. We now have mode=randgen and a set of randgen test suites (very basic now). Output = same as dtr : ) We also have mode=cleanup to kill any servers we have started. Docs updates too. Gendata utility allows us to populate test servers
137
                       , debug = self.debug )
138
139
        #sys.exit(0)
140
141
    def process_server_reqs(self,data_string):
142
        """ We read in the list of lists as a string, so we need to 
143
            handle this / break it down into proper chunks
144
145
        """
146
        server_reqs = []
147
        # We expect to see a list of lists and throw away the 
148
        # enclosing brackets
149
        option_sets = data_string[1:-1].strip().split(',')
150
        for option_set in option_sets:
151
            server_reqs.append([option_set[1:-1].strip()])
152
        return server_reqs