2144.1.1
by patrick crews
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 |
1 |
#! /usr/bin/env python
|
2088.9.1
by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time |
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 |
#
|
|
2121.3.2
by patrick crews
Updated license verbiage |
7 |
# This program is free software; you can redistribute it and/or modify
|
8 |
# it under the terms of the GNU General Public License as published by
|
|
9 |
# the Free Software Foundation; either version 2 of the License, or
|
|
10 |
# (at your option) any later version.
|
|
11 |
#
|
|
12 |
# This program is distributed in the hope that it will be useful,
|
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
# GNU General Public License for more details.
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License
|
|
18 |
# along with this program; if not, write to the Free Software
|
|
19 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2121.3.1
by patrick crews
Added licensing text to dbqp files |
20 |
|
2088.9.1
by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time |
21 |
"""execution_management.py
|
22 |
code for dealing with test execution.
|
|
23 |
The actual nuts and bolts of executing a test lies with the
|
|
24 |
mode-specific test-executor
|
|
25 |
||
26 |
The code here is for managing the executors and such.
|
|
27 |
||
28 |
"""
|
|
29 |
||
30 |
# imports
|
|
31 |
import thread |
|
32 |
import time |
|
33 |
||
34 |
class executionManager: |
|
35 |
""" Manages the mode-specific test-executors
|
|
36 |
and serves as an intermediary between the executors
|
|
37 |
and the other management code (system, server, test)
|
|
38 |
||
39 |
"""
|
|
40 |
||
41 |
def __init__(self, server_manager, system_manager, test_manager |
|
42 |
, executor_type, variables): |
|
43 |
||
44 |
self.server_manager = server_manager |
|
45 |
self.system_manager = system_manager |
|
46 |
self.logging = system_manager.logging |
|
47 |
self.test_manager = test_manager |
|
48 |
if variables['verbose']: |
|
49 |
self.logging.info("Initializing test execution manager...") |
|
50 |
self.skip_keys = [ 'server_manager' |
|
51 |
, 'system_manager' |
|
52 |
, 'test_manager' |
|
53 |
, 'executors' |
|
54 |
, 'executor_start_count' |
|
55 |
, 'executor_current_count' |
|
2124.2.10
by Patrick Crews
Added --start-and-exit option |
56 |
, 'record_flag' |
57 |
, 'start_and_exit' |
|
2088.9.1
by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time |
58 |
]
|
59 |
||
60 |
self.debug = variables['debug'] |
|
61 |
self.verbose = variables['verbose'] |
|
62 |
self.force = variables['force'] |
|
63 |
self.record_flag = variables['record'] |
|
2124.2.10
by Patrick Crews
Added --start-and-exit option |
64 |
# We are currently single-threaded execution-wise
|
65 |
# but in the future, we will likely need to revamp
|
|
66 |
# how we deal with start-and-exit if we have multiple
|
|
67 |
# executors - even if we force-set the executor-count
|
|
68 |
# to 1.
|
|
69 |
self.start_and_exit = variables['startandexit'] |
|
2088.9.1
by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time |
70 |
self.executors = {} |
71 |
self.executor_name_base = 'testbot' |
|
72 |
self.executor_start_count = 0 |
|
73 |
self.executor_current_count = 0 |
|
74 |
# We will eventually allow this to be set
|
|
75 |
# by the user, but we are hard-coded at 1
|
|
76 |
# for the moment (will = --parallel)
|
|
77 |
self.executor_count = 1 |
|
78 |
self.executor_type = executor_type |
|
79 |
||
80 |
if self.debug: |
|
81 |
self.logging.debug_class(self) |
|
82 |
||
83 |
||
84 |
def execute_tests(self): |
|
85 |
""" Execute the testCases stored in the testManager
|
|
86 |
via spawning executor_count of the mode-specific
|
|
87 |
executor_types.
|
|
88 |
|
|
89 |
Currently only supporting single executor, but trying
|
|
90 |
to plan ahead
|
|
91 |
||
92 |
"""
|
|
93 |
||
94 |
# create our testExecutors to execute the tests
|
|
95 |
self.create_test_executors() |
|
96 |
||
97 |
# fire up the testExecutors and let them rip it up
|
|
98 |
for executor_name, executor in self.executors.items(): |
|
99 |
if self.verbose: |
|
100 |
self.logging.verbose("Starting executor: %s" %(executor_name)) |
|
101 |
# thread.start_new(executor.execute,()) # sigh...one day...damned drizzletest!
|
|
2124.2.10
by Patrick Crews
Added --start-and-exit option |
102 |
executor.execute(self.start_and_exit) |
2088.9.1
by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time |
103 |
time.sleep(3) |
104 |
while self.has_running_executors(): |
|
105 |
pass
|
|
106 |
self.test_manager.statistical_report() |
|
107 |
self.logging.info("Test execution complete") |
|
108 |
||
109 |
def has_running_executors(self): |
|
110 |
""" We see if our executors are still running """
|
|
111 |
for executor in self.executors.values(): |
|
112 |
if executor.status == 1: |
|
113 |
return 1 |
|
114 |
return 0 |
|
115 |
||
116 |
def create_test_executors(self): |
|
117 |
""" create however many test executors of executor_type
|
|
118 |
that we need (only supporting 1 for now)
|
|
119 |
||
120 |
"""
|
|
121 |
||
122 |
self.logging.info("Creating %d %s(s)" %(self.executor_count |
|
123 |
, self.executor_name_base)) |
|
124 |
for i in range(self.executor_start_count,self.executor_count,1): |
|
125 |
executor_name = "%s%d" %(self.executor_name_base,i) |
|
126 |
new_executor = self.create_test_executor(executor_name) |
|
127 |
||
128 |
||
129 |
def create_test_executor(self, executor_name): |
|
130 |
""" Create a single testExecutor """
|
|
131 |
||
132 |
if self.verbose: |
|
133 |
self.logging.verbose("Creating %s" %(executor_name)) |
|
134 |
new_executor = self.executor_type( self, executor_name |
|
135 |
, self.verbose, self.debug) |
|
136 |
self.log_executor(executor_name, new_executor) |
|
137 |
||
138 |
def log_executor(self, executor_name, new_executor): |
|
139 |
""" Bookkeeping function to track created executors """
|
|
140 |
self.executors[executor_name] = new_executor |
|
141 |
self.executor_current_count += 1 |
|
142 |
||
143 |