~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/test_mgmt/test_execution.py

  • Committer: patrick crews
  • Date: 2011-02-04 20:41:08 UTC
  • mto: (2145.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: gleebix@gmail.com-20110204204108-cyhtpo5kfu7wy88q
Overhaul of code.  We can run rabbitmq : )  We now better encapsulate a per-executor working environment = one step closer to --parallel >: ) using subprocess goodness for server control

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
 
1
#! /usr/bin/env python
2
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
#
56
56
        self.server_manager = self.execution_manager.server_manager
57
57
        self.time_manager = self.system_manager.time_manager
58
58
        self.name = name
59
 
        self.master_server = None
 
59
        self.working_environment = {} # we pass env dict to define what we need
 
60
        self.dirset = { self.name : { 'log': None } }
 
61
        self.workdir = self.system_manager.create_dirset( self.system_manager.workdir
 
62
                                                        , self.dirset)
 
63
        self.logdir = os.path.join(self.workdir,'log')
 
64
        self.master_server = self.server_manager.allocate_server( self.name
 
65
                                                                , []
 
66
                                                                , self.workdir
 
67
                                                                )
60
68
        self.record_flag=self.execution_manager.record_flag
61
69
        self.environment_vars = {}
62
 
        self.current_servers = []
 
70
        self.current_servers = [self.master_server]
63
71
        self.current_testcase = None    
64
72
        self.current_test_status = None
65
73
        self.current_test_retcode = None
66
74
        self.current_test_output = None
67
 
        self.current_test_exec_time = 0
68
 
        self.dirset = { self.name : { 'log': None } }
69
 
        self.workdir = self.system_manager.create_dirset( self.system_manager.workdir
70
 
                                                        , self.dirset)
71
 
        self.logdir = os.path.join(self.workdir,'log')
 
75
        self.current_test_exec_time = 0 
72
76
         
73
77
        if self.debug:
74
78
            self.logging.debug_class(self)
83
87
            self.logging.debug("Executor: %s, assigned test: %s" %(self.name
84
88
                                            , self.current_testcase.fullname))
85
89
 
86
 
    def handle_server_reqs(self):
87
 
        """ Get the servers required to execute the testCase """
 
90
    def handle_server_reqs(self, start_and_exit):
 
91
        """ Get the servers required to execute the testCase 
 
92
            and ensure that we have servers and they were started
 
93
            as expected.  We take necessary steps if not
 
94
            We also handle --start-and-exit here
 
95
 
 
96
        """
88
97
       
89
98
        master_count, slave_count, server_options = self.process_server_reqs()
90
99
        (self.current_servers,bad_start) = self.server_manager.request_servers( self.name
91
100
                                                              , self.workdir
92
101
                                                              , master_count
93
102
                                                              , slave_count
94
 
                                                              , server_options)
 
103
                                                              , server_options
 
104
                                                              , self.working_environment)
95
105
        if self.current_servers == 0 or bad_start:
96
106
            # error allocating servers, test is a failure
97
 
            return 1
 
107
            self.logging.warning("Problem starting server(s) for test...failing test case")
 
108
            self.current_test_status = 'fail'
 
109
            self.set_server_status(self.current_test_status)
 
110
            output = ''           
 
111
        else:
 
112
            if start_and_exit:
 
113
                # TODO:  Report out all started servers via server_manager/server objects?
 
114
                self.logging.info("User specified --start-and-exit.  dbqp.py exiting and leaving servers running...")
 
115
                sys.exit(0)
98
116
        if self.initial_run:
99
117
            self.initial_run = 0
100
118
            self.current_servers[0].report()
101
119
        self.master_server = self.current_servers[0]
102
 
        return 0
 
120
        return 
103
121
 
104
122
    def process_server_reqs(self):
105
123
        """ Check out our current_testcase to see what kinds of servers 
123
141
        while self.test_manager.has_tests() and keep_running == 1:
124
142
            self.get_testCase()
125
143
            self.handle_system_reqs()
126
 
            bad_start = self.handle_server_reqs()
127
 
            if bad_start:
128
 
                # Our servers didn't start, we mark it a failure
129
 
                self.logging.warning("Problem starting server(s) for test...failing test case")
130
 
                self.current_test_status = 'fail'
131
 
                self.set_server_status(self.current_test_status)
132
 
                output = ''
133
 
            if start_and_exit:
134
 
                # TODO:  Report out all started servers via server_manager/server objects?
135
 
                self.logging.info("User specified --start-and-exit.  dbqp.py exiting and leaving servers running...")
136
 
                sys.exit(0)
137
 
            else:
138
 
                self.execute_testCase()
139
 
            self.test_manager.record_test_result( self.current_testcase
140
 
                                                , self.current_test_status
141
 
                                                , self.current_test_output
142
 
                                                , self.current_test_exec_time )
 
144
            self.handle_server_reqs(start_and_exit)
 
145
            self.execute_testCase()
 
146
            self.record_test_result()
143
147
            if self.current_test_status == 'fail' and not self.execution_manager.force:
144
148
                self.logging.error("Failed test.  Use --force to execute beyond the first test failure")
145
149
                keep_running = 0
150
154
        if self.verbose:
151
155
            self.logging.verbose("Executor: %s executing test: %s" %(self.name, self.current_testcase.fullname))
152
156
 
 
157
    def record_test_result(self):
 
158
        """ We get the test_manager to record the result """
 
159
 
 
160
        self.test_manager.record_test_result( self.current_testcase
 
161
                                                , self.current_test_status
 
162
                                                , self.current_test_output
 
163
                                                , self.current_test_exec_time )
 
164
 
153
165
            
154
 
 
155
166
    def set_server_status(self, test_status):
156
167
        """ We update our servers to indicate if a test passed or failed """
157
168
        for server in self.current_servers:
161
172
   
162
173
    def handle_system_reqs(self):
163
174
        """ We check our test case and see what we need to do
164
 
            system-wise to get ready
 
175
            system-wise to get ready.  This is likely to be 
 
176
            mode-dependent and this is just a placeholder
 
177
            method
165
178
 
166
179
        """
 
180
        
 
181
        return
167
182
 
168
 
        if self.current_testcase.master_sh:
169
 
                self.system_manager.execute_cmd("/bin/sh %s" %(self.current_testcase.master_sh))
 
183