~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/randgen/randgen_test_execution.py

  • Committer: patrick crews
  • Date: 2011-02-23 17:17:25 UTC
  • mto: (2195.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2196.
  • Revision ID: gleebix@gmail.com-20110223171725-4tgewemxhsw1m7q8
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 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
#
 
5
# Copyright (C) 2010 Patrick Crews
 
6
#
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 
 
22
""" dtr_test_execution:
 
23
    code related to the execution of dtr test cases 
 
24
    
 
25
    We are provided access to a testManager with 
 
26
    dtr-specific testCases.  We contact teh executionManager
 
27
    to produce the system and server configurations we need
 
28
    to execute a test.
 
29
 
 
30
"""
 
31
 
 
32
# imports
 
33
import os
 
34
import sys
 
35
import subprocess
 
36
import commands
 
37
 
 
38
import lib.test_mgmt.test_execution as test_execution
 
39
 
 
40
class randgenTestExecutor(test_execution.testExecutor):
 
41
    """ dtr-specific testExecutor 
 
42
        We currently execute by sending test-case
 
43
        data to client/randgen...for now
 
44
 
 
45
    """
 
46
  
 
47
    def execute_testCase (self):
 
48
        """ Execute a dtr testCase via calls to randgen (boo)
 
49
            Eventually, we will replace randgen with pythonic
 
50
            goodness, but we have these classes stored here for the moment
 
51
 
 
52
        """
 
53
        test_execution.testExecutor.execute_testCase(self)
 
54
        self.status = 0
 
55
 
 
56
        # execute the randgen
 
57
        self.execute_randgen()
 
58
 
 
59
        # analyze results
 
60
        self.current_test_status = self.process_randgen_output()
 
61
        self.set_server_status(self.current_test_status)
 
62
 
 
63
 
 
64
    
 
65
 
 
66
    def execute_randgen(self):
 
67
        """ Execute the commandline and return the result.
 
68
            We use subprocess as we can pass os.environ dicts and whatnot 
 
69
 
 
70
        """
 
71
      
 
72
        testcase_name = self.current_testcase.fullname
 
73
        self.time_manager.start(testcase_name,'test')
 
74
        randgen_outfile = os.path.join(self.logdir,'randgen.out')
 
75
        randgen_output = open(randgen_outfile,'w')
 
76
        dsn = "--dsn=dbi:drizzle:host=localhost:port=%d:user=root:password="":database=test" %(self.master_server.master_port)
 
77
        randgen_cmd = " ".join([self.current_testcase.test_command, dsn])
 
78
        randgen_subproc = subprocess.Popen( randgen_cmd
 
79
                                         , shell=True
 
80
                                         , cwd=self.system_manager.randgen_path
 
81
                                         , env=self.working_environment
 
82
                                         , stdout = randgen_output
 
83
                                         , stderr = subprocess.STDOUT
 
84
                                         )
 
85
        randgen_subproc.wait()
 
86
        retcode = randgen_subproc.returncode     
 
87
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
 
88
 
 
89
        randgen_output.close()
 
90
        randgen_file = open(randgen_outfile,'r')
 
91
        output = ''.join(randgen_file.readlines())
 
92
        #print output
 
93
        randgen_file.close()
 
94
 
 
95
        if self.debug:
 
96
            self.logging.debug("randgen_retcode: %d" %(retcode))
 
97
        self.current_test_retcode = retcode
 
98
        self.current_test_output = output
 
99
        self.current_test_exec_time = execution_time
 
100
 
 
101
    def process_randgen_output(self):
 
102
        """ randgen has run, we now check out what we have """
 
103
        retcode = self.current_test_retcode
 
104
        if retcode == 0:
 
105
            return 'pass'
 
106
        else:
 
107
            return 'fail'
 
108
 
 
109
    def handle_system_reqs(self):
 
110
        """ We check our test case and see what we need to do
 
111
            system-wise to get ready.  This is likely to be 
 
112
            mode-dependent and this is just a placeholder
 
113
            method
 
114
 
 
115
        """
 
116
 
 
117
        self.process_environment_reqs()
 
118
        self.process_symlink_reqs()
 
119
        self.process_master_sh()  
 
120
        return
 
121
 
 
122
    def process_master_sh(self):
 
123
        """ We do what we need to if we have a master.sh file """
 
124
        if self.current_testcase.master_sh:
 
125
            retcode, output = self.system_manager.execute_cmd("/bin/sh %s" %(self.current_testcase.master_sh))
 
126
            if self.debug:
 
127
                self.logging.info("retcode: %retcode")
 
128
                self.logging.info("%output")
 
129
 
 
130
    def process_environment_reqs(self):
 
131
        """ We generate the ENV vars we need set
 
132
            and then ask systemManager to do so
 
133
 
 
134
        """
 
135
        env_reqs = { 'randgen_VARDIR': self.master_server.vardir
 
136
                   ,  'DRIZZLE_TMP_DIR': self.master_server.tmpdir
 
137
                   ,  'MASTER_MYSOCK': self.master_server.socket_file
 
138
                   ,  'MASTER_MYPORT': str(self.master_server.master_port)
 
139
                   ,  'MC_PORT': str(self.master_server.mc_port)
 
140
                   ,  'PBMS_PORT': str(self.master_server.pbms_port)
 
141
                   ,  'RABBITMQ_NODE_PORT': str(self.master_server.rabbitmq_node_port)
 
142
                   ,  'DRIZZLE_TCP_PORT': str(self.master_server.drizzle_tcp_port)
 
143
                   ,  'EXE_DRIZZLE': self.master_server.drizzle_client
 
144
                   ,  'MASTER_SERVER_SLAVE_CONFIG' : self.master_server.slave_config_file
 
145
                   ,  'DRIZZLE_DUMP': "%s --no-defaults -uroot -p%d" %( self.master_server.drizzledump
 
146
                                                        , self.master_server.master_port)
 
147
                   ,  'DRIZZLE_SLAP': "%s -uroot -p%d" %( self.master_server.drizzleslap
 
148
                                                        , self.master_server.master_port)
 
149
                   ,  'DRIZZLE_IMPORT': "%s -uroot -p%d" %( self.master_server.drizzleimport
 
150
                                                          , self.master_server.master_port)
 
151
                   ,  'DRIZZLE': "%s -uroot -p%d" %( self.master_server.drizzle_client
 
152
                                                   , self.master_server.master_port)
 
153
                   ,  'DRIZZLE_ADMIN' : "%s -uroot -p%d" %( self.master_server.drizzleadmin
 
154
                                                         , self.master_server.master_port)
 
155
                   }     
 
156
 
 
157
        self.working_environment = self.system_manager.create_working_environment(env_reqs)
 
158
 
 
159
    def process_symlink_reqs(self):
 
160
        """ Create any symlinks we may need """
 
161
        needed_symlinks = []
 
162
 
 
163
        # handle filesystem_engine 
 
164
        if self.current_testcase.suitename == 'filesystem_engine':
 
165
            needed_symlinks.append(( os.path.join(self.current_testcase.suitepath
 
166
                                  , 't')
 
167
                                  , os.path.join(self.master_server.vardir
 
168
                                  , "filesystem_ln")))
 
169
 
 
170
        self.system_manager.create_symlinks(needed_symlinks)
 
171
 
 
172
    
 
173
   
 
174
 
 
175