~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-01-15 21:27:41 UTC
  • mto: (2119.2.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2121.
  • Revision ID: gleebix@gmail.com-20110115212741-htz3af0cib4fwdlv
Updated tree so that test-run.pl and test-run.py may live together in peace for a time

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/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
""" test_execution:
 
8
    code related to the execution of est cases 
 
9
    
 
10
    We are provided access to a testManager with 
 
11
    mode-specific testCases.  We contact the executionManager
 
12
    to produce the system and server configurations we need
 
13
    to execute a test.
 
14
 
 
15
"""
 
16
 
 
17
# imports
 
18
import os
 
19
 
 
20
class testExecutor():
 
21
    """ class for handling the execution of testCase
 
22
        objects.  Mode-specific executors inherit
 
23
        from me.
 
24
 
 
25
    """
 
26
 
 
27
    def __init__(self, execution_manager, name, verbose, debug):
 
28
        self.skip_keys = [ 'execution_manager'
 
29
                         , 'system_manager'
 
30
                         , 'test_manager'
 
31
                         , 'server_manager']
 
32
        self.debug = debug
 
33
        self.verbose = verbose
 
34
        self.initial_run = 1
 
35
        self.status = 0 # not running
 
36
        self.execution_manager = execution_manager
 
37
        self.system_manager = self.execution_manager.system_manager
 
38
        self.logging = self.system_manager.logging
 
39
        self.test_manager = self.execution_manager.test_manager
 
40
        self.server_manager = self.execution_manager.server_manager
 
41
        self.name = name
 
42
        self.master_server = None
 
43
        self.record_flag=self.execution_manager.record_flag
 
44
        self.environment_vars = {}
 
45
        self.current_servers = []
 
46
        self.current_testcase = None    
 
47
        self.current_test_status = None   
 
48
        self.dirset = { self.name : { 'log': None } }
 
49
        self.workdir = self.system_manager.create_dirset( self.system_manager.workdir
 
50
                                                        , self.dirset)
 
51
        self.logdir = os.path.join(self.workdir,'log')
 
52
         
 
53
        if self.debug:
 
54
            self.logging.debug_class(self)
 
55
 
 
56
    def get_testCase(self):
 
57
        """ Ask our execution_manager for a testCase to work on """
 
58
        
 
59
        #self.test_manager.mutex.acquire()
 
60
        self.current_testcase = self.test_manager.get_testCase(self.name)
 
61
        #self.test_manager.mutex.release()
 
62
        if self.debug:
 
63
            self.logging.debug("Executor: %s, assigned test: %s" %(self.name
 
64
                                            , self.current_testcase.fullname))
 
65
 
 
66
    def handle_server_reqs(self):
 
67
        """ Get the servers required to execute the testCase """
 
68
       
 
69
        master_count, slave_count, server_options = self.process_server_reqs()
 
70
        self.current_servers = self.server_manager.request_servers( self.name
 
71
                                                              , self.workdir
 
72
                                                              , master_count
 
73
                                                              , slave_count
 
74
                                                              , server_options)
 
75
        if self.current_servers == 0:
 
76
            # error allocating servers, test is a failure
 
77
            return 1
 
78
        if self.initial_run:
 
79
            self.initial_run = 0
 
80
            self.current_servers[0].report()
 
81
        self.master_server = self.current_servers[0]
 
82
        return 0
 
83
 
 
84
    def process_server_reqs(self):
 
85
        """ Check out our current_testcase to see what kinds of servers 
 
86
            we need up and running.  The executionManager sees to 
 
87
            serving the reqs
 
88
 
 
89
        """
 
90
     
 
91
        master_count = self.current_testcase.master_count
 
92
        slave_count = self.current_testcase.slave_count
 
93
        server_options = self.current_testcase.server_options
 
94
 
 
95
        return(master_count, slave_count, server_options)
 
96
 
 
97
    def execute(self):
 
98
        """ Execute a test case.  The details are *very* mode specific """
 
99
        self.status = 1 # we are running
 
100
        keep_running = 1
 
101
        if self.verbose:
 
102
            self.logging.verbose("Executor: %s beginning test execution..." %(self.name))
 
103
        while self.test_manager.has_tests() and keep_running == 1:
 
104
            self.get_testCase()
 
105
            self.handle_server_reqs()
 
106
            test_status = self.execute_testCase()
 
107
            if test_status == 'fail' and not self.execution_manager.force:
 
108
                self.logging.error("Failed test.  Use --force to execute beyond the first test failure")
 
109
                keep_running = 0
 
110
        self.status = 0
 
111
 
 
112
    def execute_testCase(self):
 
113
        """ Do whatever evil voodoo we must do to execute a testCase """
 
114
        if self.verbose:
 
115
            self.logging.verbose("Executor: %s executing test: %s" %(self.name, self.current_testcase.fullname))
 
116
 
 
117
   
 
118
 
 
119
    
 
120
  
 
121