41
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
43
45
from lib.sys_mgmt.port_management import portManager
44
from lib.sys_mgmt.logging_management import loggingManager
45
46
from lib.sys_mgmt.time_management import timeManager
46
from lib.sys_mgmt.code_management import codeManager
48
48
class systemManager:
49
49
"""Class to deal with the basics of system-level interaction
94
93
# Make sure the tree we are testing looks good
95
94
self.code_tree = self.code_manager.code_trees['drizzle'][0]
97
self.ld_lib_paths = self.join_env_var_values(self.code_tree.ld_lib_paths)
96
# environment manager handles updates / whatever to testing environments
97
self.env_manager = environmentManager(self, variables)
99
self.ld_lib_paths = self.env_manager.join_env_var_values(self.code_tree.ld_lib_paths)
99
101
# Some ENV vars are system-standard
100
102
# We describe and set them here and now
109
111
, 'TOP_BUILDDIR' : self.top_builddir
110
112
, 'DRIZZLE_TEST_DIR' : self.code_tree.testdir
111
113
, 'DTR_BUILD_THREAD' : "-69.5"
112
, 'LD_LIBRARY_PATH' : self.append_env_var( 'LD_LIBRARY_PATH'
114
# Need to move these to server-level
115
, 'LD_LIBRARY_PATH' : self.env_manager.append_env_var( 'LD_LIBRARY_PATH'
113
116
, self.ld_lib_paths
117
, 'DYLD_LIBRARY_PATH' : self.append_env_var( 'DYLD_LIBRARY_PATH'
120
, 'DYLD_LIBRARY_PATH' : self.env_manager.append_env_var( 'DYLD_LIBRARY_PATH'
118
121
, self.ld_lib_paths
296
298
source, link_name = needed_symlink
297
299
self.create_symlink(source, link_name)
299
def join_env_var_values(self, value_list):
300
""" Utility to join multiple values into a nice string
301
for setting an env var to
305
return self.env_var_delimiter.join(value_list)
307
def set_env_var(self, var_name, var_value, quiet=0):
308
"""Set an environment variable. We really just abstract
313
self.logging.debug("Setting env var: %s" %(var_name))
315
os.environ[var_name]=var_value
317
self.logging.error("Issue setting environment variable %s to value %s" %(var_name, var_value))
318
self.logging.error("%s" %(e))
321
def update_environment_vars(self, desired_vars, working_environment=None):
322
""" We update the environment vars with desired_vars
323
The expectation is that you know what you are asking for ; )
324
If working_environment is provided, we will update that with
325
desired_vars. We operate directly on os.environ by default
326
We return our updated environ dictionary
330
if not working_environment:
331
working_environment = os.environ
332
working_environment.update(desired_vars)
333
return working_environment
335
def create_working_environment(self, desired_vars):
336
""" We return a copy of os.environ updated with desired_vars """
338
working_copy = copy.deepcopy(os.environ)
339
return self.update_environment_vars( desired_vars
340
, working_environment = working_copy )
342
def append_env_var(self, var_name, append_string, suffix=1, quiet=0):
343
""" We add the values in var_values to the environment variable
344
var_name. Depending on suffix value, we either append or prepend
345
we return a string suitable for os.putenv
349
if var_name in os.environ:
350
cur_var_value = os.environ[var_name]
351
if suffix: # We add new values to end of existing value
352
new_var_values = [ cur_var_value, append_string ]
354
new_var_values = [ append_string, cur_var_value ]
355
new_var_value = self.env_var_delimiter.join(new_var_values)
357
# No existing variable value
358
new_var_value = append_string
361
303
def find_path(self, paths, required=1):
362
304
"""We search for the files we need / want to be aware of
520
462
# add debug libraries to ld_library_path
521
463
debug_path = '/usr/lib/debug'
522
464
if os.path.exists(debug_path):
523
self.append_env_var("LD_LIBRARY_PATH", debug_path, suffix=1)
524
self.append_env_var("DYLD_LIBRARY_PATH", debug_path, suffix=1)
465
self.env_manager.append_env_var("LD_LIBRARY_PATH", debug_path, suffix=1)
466
self.env_manager.append_env_var("DYLD_LIBRARY_PATH", debug_path, suffix=1)
527
469
def cleanup(self, exit=False):