~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-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:
78
78
        if self.debug:
79
79
            self.logging.debug_class(self)
80
80
 
 
81
    def execute(self, start_and_exit):
 
82
        """ Execute a test case.  The details are *very* mode specific """
 
83
        self.status = 1 # we are running
 
84
        keep_running = 1
 
85
        if self.verbose:
 
86
            self.logging.verbose("Executor: %s beginning test execution..." %(self.name))
 
87
        while self.test_manager.has_tests() and keep_running == 1:
 
88
            self.get_testCase()
 
89
            for i in range(self.testcase_repeat_count):
 
90
                self.handle_system_reqs()
 
91
                self.handle_server_reqs()
 
92
                self.handle_utility_reqs()
 
93
                self.handle_start_and_exit(start_and_exit)
 
94
                if self.current_test_status != 'fail':
 
95
                    self.execute_testCase()
 
96
                self.record_test_result()
 
97
                if self.current_test_status == 'fail' and not self.execution_manager.force:
 
98
                    self.logging.error("Failed test.  Use --force to execute beyond the first test failure")
 
99
                    keep_running = 0
 
100
        self.status = 0
 
101
 
81
102
    def get_testCase(self):
82
103
        """ Ask our execution_manager for a testCase to work on """
83
104
        
86
107
        #self.test_manager.mutex.release()
87
108
        
88
109
 
89
 
    def handle_server_reqs(self, start_and_exit):
 
110
    def handle_server_reqs(self):
90
111
        """ Get the servers required to execute the testCase 
91
112
            and ensure that we have servers and they were started
92
113
            as expected.  We take necessary steps if not
93
114
            We also handle --start-and-exit here
94
115
 
95
116
        """
96
 
       
97
 
        master_count, slave_count, server_options = self.process_server_reqs()
 
117
 
 
118
        server_requirements = self.current_testcase.server_requirements
98
119
        (self.current_servers,bad_start) = self.server_manager.request_servers( self.name
99
120
                                                              , self.workdir
100
 
                                                              , master_count
101
 
                                                              , slave_count
102
 
                                                              , server_options
 
121
                                                              , server_requirements
103
122
                                                              , self.working_environment)
104
123
        if self.current_servers == 0 or bad_start:
105
124
            # error allocating servers, test is a failure
107
126
            self.current_test_status = 'fail'
108
127
            self.set_server_status(self.current_test_status)
109
128
            output = ''           
110
 
        else:
111
 
            if start_and_exit:
112
 
                # TODO:  Report out all started servers via server_manager/server objects?
113
 
                self.current_servers[0].report()
114
 
                self.logging.info("User specified --start-and-exit.  dbqp.py exiting and leaving servers running...") 
 
129
        if self.initial_run:
 
130
            self.initial_run = 0
 
131
            self.current_servers[0].report()
 
132
        self.master_server = self.current_servers[0]
 
133
        return 
 
134
 
 
135
    def handle_start_and_exit(self, start_and_exit):
 
136
        """ Do what needs to be done if we have the
 
137
            --start-and-exit flag
 
138
 
 
139
        """
 
140
        if start_and_exit:
115
141
                # We blow away any port_management files for our ports
116
142
                # Technically this won't let us 'lock' any ports that 
117
143
                # we aren't explicitly using (visible to netstat scan)
119
145
                # We shouldn't hog it ; )
120
146
                # We might need to do this better later
121
147
                for server in self.current_servers:
 
148
                    if server != self.master_server:
 
149
                        server.report()
122
150
                    server.cleanup() # this only removes any port files
 
151
                self.logging.info("User specified --start-and-exit.  dbqp.py exiting and leaving servers running...") 
123
152
                sys.exit(0)
124
 
        if self.initial_run:
125
 
            self.initial_run = 0
126
 
            self.current_servers[0].report()
127
 
        self.master_server = self.current_servers[0]
128
 
        return 
129
153
 
130
 
    def process_server_reqs(self):
131
 
        """ Check out our current_testcase to see what kinds of servers 
132
 
            we need up and running.  The executionManager sees to 
133
 
            serving the reqs
 
154
    def handle_utility_reqs(self):
 
155
        """ Call any utilities we want to use before starting a test
 
156
            At present this is envisioned for use with datagen
 
157
            but there may be other things we wish to use
 
158
            At that point, we may need to explore other ways of
 
159
            defining our testing environment, such as with
 
160
            nice config files / modules
134
161
 
135
162
        """
136
 
     
137
 
        master_count = self.current_testcase.master_count
138
 
        slave_count = self.current_testcase.slave_count
139
 
        server_options = self.current_testcase.server_options
140
 
 
141
 
        return(master_count, slave_count, server_options)
142
 
 
143
 
    def execute(self, start_and_exit):
144
 
        """ Execute a test case.  The details are *very* mode specific """
145
 
        self.status = 1 # we are running
146
 
        keep_running = 1
147
 
        if self.verbose:
148
 
            self.logging.verbose("Executor: %s beginning test execution..." %(self.name))
149
 
        while self.test_manager.has_tests() and keep_running == 1:
150
 
            self.get_testCase()
151
 
            self.handle_system_reqs()
152
 
            self.handle_server_reqs(start_and_exit)
153
 
            for i in range(self.testcase_repeat_count):
154
 
                self.execute_testCase()
155
 
                self.record_test_result()
156
 
                if self.current_test_status == 'fail' and not self.execution_manager.force:
157
 
                    self.logging.error("Failed test.  Use --force to execute beyond the first test failure")
158
 
                    keep_running = 0
159
 
        self.status = 0
 
163
 
 
164
        # We call gendata against the server(s) with the
 
165
        # specified file
 
166
        if self.execution_manager.gendata_file:
 
167
            dsn = "--dsn=dbi:drizzle:host=localhost:port=%d:user=root:password="":database=test" %(self.master_server.master_port)
 
168
            gendata_cmd = "./gendata.pl %s --spec=%s" %( dsn 
 
169
                                                       , self.execution_manager.gendata_file
 
170
                                                       )
 
171
            #self.system_manager.execute_cmd(gendata_cmd)
 
172
            gendata_subproc = subprocess.Popen( gendata_cmd
 
173
                                              , shell=True
 
174
                                              , cwd=self.system_manager.randgen_path
 
175
                                              , stdout = None
 
176
                                              , stderr = None
 
177
                                              )
 
178
            gendata_subproc.wait()
 
179
            gendata_retcode = gendata_subproc.returncode
 
180
            if gendata_retcode:
 
181
                self.logging.error("gendata command: %s failed with retcode: %d" %(gendata_cmd
 
182
                                                                             , gendata_retcode))
160
183
 
161
184
    def execute_testCase(self):
162
185
        """ Do whatever evil voodoo we must do to execute a testCase """