2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2010 Patrick Crews
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.
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.
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
22
""" dtr_test_execution:
23
code related to the execution of dtr test cases
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
38
import lib.test_mgmt.test_execution as test_execution
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
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
53
test_execution.testExecutor.execute_testCase(self)
57
self.execute_randgen()
60
self.current_test_status = self.process_randgen_output()
61
self.set_server_status(self.current_test_status)
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
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
80
, cwd=self.system_manager.randgen_path
81
, env=self.working_environment
82
, stdout = randgen_output
83
, stderr = subprocess.STDOUT
85
randgen_subproc.wait()
86
retcode = randgen_subproc.returncode
87
execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
89
randgen_output.close()
90
randgen_file = open(randgen_outfile,'r')
91
output = ''.join(randgen_file.readlines())
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
101
def process_randgen_output(self):
102
""" randgen has run, we now check out what we have """
103
retcode = self.current_test_retcode
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
117
self.process_environment_reqs()
118
self.process_symlink_reqs()
119
self.process_master_sh()
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))
127
self.logging.info("retcode: %retcode")
128
self.logging.info("%output")
130
def process_environment_reqs(self):
131
""" We generate the ENV vars we need set
132
and then ask systemManager to do so
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)
157
self.working_environment = self.system_manager.create_working_environment(env_reqs)
159
def process_symlink_reqs(self):
160
""" Create any symlinks we may need """
163
# handle filesystem_engine
164
if self.current_testcase.suitename == 'filesystem_engine':
165
needed_symlinks.append(( os.path.join(self.current_testcase.suitepath
167
, os.path.join(self.master_server.vardir
170
self.system_manager.create_symlinks(needed_symlinks)