41
from lib.uuid import uuid4
40
from uuid import uuid4
42
from lib.sys_mgmt.code_management import codeManager
43
from lib.sys_mgmt.environment_management import environmentManager
44
from lib.sys_mgmt.logging_management import loggingManager
42
45
from lib.sys_mgmt.port_management import portManager
43
from lib.sys_mgmt.logging_management import loggingManager
44
46
from lib.sys_mgmt.time_management import timeManager
46
48
class systemManager:
55
57
if variables['verbose']:
56
58
self.logging.verbose("Initializing system manager...")
58
self.skip_keys = [ 'code_tree'
60
self.skip_keys = [ 'port_manager'
61
61
, 'logging_manager'
62
64
, 'environment_reqs'
63
, 'env_var_delimiter']
64
66
self.debug = variables['debug']
65
67
self.verbose = variables['verbose']
66
self.env_var_delimiter = ':'
67
68
self.no_shm = variables['noshm']
68
69
self.shm_path = self.find_path(["/dev/shm", "/tmp"], required=0)
69
70
self.cur_os = os.uname()[0]
75
76
self.top_builddir = os.path.abspath(variables['topbuilddir'])
76
77
self.start_dirty = variables['startdirty']
77
78
self.valgrind = variables['valgrind']
79
self.valgrind_suppress_file = variables['valgrindsuppressions']
78
80
self.gdb = variables['gdb']
79
81
self.manual_gdb = variables['manualgdb']
80
82
self.randgen_path = variables['randgenpath']
85
87
self.port_manager = portManager(self,variables['debug'])
86
88
self.time_manager = timeManager(self)
88
# Make sure the tree we are testing looks good
89
self.code_tree = self.get_code_tree(variables, tree_type)
91
self.ld_lib_paths = self.join_env_var_values(self.code_tree.ld_lib_paths)
90
# use our code_manager to handle the various basedirs
92
self.code_manager = codeManager(self, variables)
94
# environment manager handles updates / whatever to testing environments
95
self.env_manager = environmentManager(self, variables)
93
97
# Some ENV vars are system-standard
94
98
# We describe and set them here and now
101
105
, 'USE_RUNNING_SERVER' : "0"
102
106
, 'TOP_SRCDIR' : self.top_srcdir
103
107
, 'TOP_BUILDDIR' : self.top_builddir
104
, 'DRIZZLE_TEST_DIR' : self.code_tree.testdir
108
, 'DRIZZLE_TEST_DIR' : self.testdir
105
109
, 'DTR_BUILD_THREAD' : "-69.5"
106
, 'LD_LIBRARY_PATH' : self.append_env_var( 'LD_LIBRARY_PATH'
111
, 'DYLD_LIBRARY_PATH' : self.append_env_var( 'DYLD_LIBRARY_PATH'
117
111
# set the env vars we need
118
112
# self.process_environment_reqs(self.environment_reqs)
119
self.update_environment_vars(self.environment_reqs)
113
self.env_manager.update_environment_vars(self.environment_reqs)
121
115
# We find or generate our id file
122
116
# We use a uuid to identify the symlinked
137
131
# options like valgrind and gdb
138
132
self.handle_additional_reqs(variables)
141
self.logging.debug_class(self)
143
def get_code_tree(self, variables, tree_type):
144
"""Find out the important files, directories, and env. vars
145
for a particular type of tree. We import a definition module
146
depending on the tree_type. The module lets us know
147
what to look for, etc
151
# Import the appropriate module that defines
152
# where we find what we need depending on
154
test_tree = self.process_tree_type(tree_type, variables)
157
def process_tree_type(self, tree_type, variables):
158
"""Import the appropriate module depending on the type of tree
161
Drizzle is the only supported type currently
166
self.logging.verbose("Processing source tree under test...")
167
if tree_type == 'drizzle':
169
from lib.sys_mgmt.codeTree import drizzleTree
170
test_tree = drizzleTree(variables,self)
173
self.logging.error("Tree_type: %s not supported yet" %(tree_type))
134
self.logging.debug_class(self)
177
137
def create_dirset(self, rootdir, dirset):
178
138
""" We produce the set of directories defined in dirset
179
139
dirset is a set of dictionaries like
310
268
def create_symlink(self, source, link_name):
311
269
""" We create a symlink to source named link_name """
313
self.logging.debug("Creating symlink from %s to %s" %(source, link_name))
271
self.logging.debug("Creating symlink from %s to %s" %(source, link_name))
314
272
if os.path.exists(link_name) or os.path.islink(link_name):
315
273
os.remove(link_name)
316
274
return os.symlink(source, link_name)
325
283
source, link_name = needed_symlink
326
284
self.create_symlink(source, link_name)
328
def join_env_var_values(self, value_list):
329
""" Utility to join multiple values into a nice string
330
for setting an env var to
334
return self.env_var_delimiter.join(value_list)
336
def set_env_var(self, var_name, var_value, quiet=0):
337
"""Set an environment variable. We really just abstract
341
if self.debug and not quiet:
342
self.logging.debug("Setting env var: %s" %(var_name))
344
os.environ[var_name]=var_value
346
self.logging.error("Issue setting environment variable %s to value %s" %(var_name, var_value))
347
self.logging.error("%s" %(e))
350
def update_environment_vars(self, desired_vars, working_environment=None):
351
""" We update the environment vars with desired_vars
352
The expectation is that you know what you are asking for ; )
353
If working_environment is provided, we will update that with
354
desired_vars. We operate directly on os.environ by default
355
We return our updated environ dictionary
359
if not working_environment:
360
working_environment = os.environ
361
working_environment.update(desired_vars)
362
return working_environment
364
def create_working_environment(self, desired_vars):
365
""" We return a copy of os.environ updated with desired_vars """
367
working_copy = copy.deepcopy(os.environ)
368
return self.update_environment_vars( desired_vars
369
, working_environment = working_copy )
371
def append_env_var(self, var_name, append_string, suffix=1, quiet=0):
372
""" We add the values in var_values to the environment variable
373
var_name. Depending on suffix value, we either append or prepend
374
we return a string suitable for os.putenv
378
if var_name in os.environ:
379
cur_var_value = os.environ[var_name]
380
if suffix: # We add new values to end of existing value
381
new_var_values = [ cur_var_value, append_string ]
383
new_var_values = [ append_string, cur_var_value ]
384
new_var_value = self.env_var_delimiter.join(new_var_values)
386
# No existing variable value
387
new_var_value = append_string
390
288
def find_path(self, paths, required=1):
391
289
"""We search for the files we need / want to be aware of
551
446
# add debug libraries to ld_library_path
552
447
debug_path = '/usr/lib/debug'
553
448
if os.path.exists(debug_path):
554
self.append_env_var("LD_LIBRARY_PATH", debug_path, suffix=1)
555
self.append_env_var("DYLD_LIBRARY_PATH", debug_path, suffix=1)
449
self.env_manager.append_env_var("LD_LIBRARY_PATH", debug_path, suffix=1)
450
self.env_manager.append_env_var("DYLD_LIBRARY_PATH", debug_path, suffix=1)
558
453
def cleanup(self, exit=False):