~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/sys_mgmt/system_management.py

  • Committer: patrick crews
  • Date: 2011-06-22 16:10:36 UTC
  • mto: (2429.2.1 dbqp_revamp)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: gleebix@gmail.com-20110622161036-adxbog3857fkax79
Added environment manager + test_execution cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# imports
34
34
import os
35
35
import sys
36
 
import copy
37
36
import shutil
38
37
import getpass
39
38
import commands
40
39
 
41
40
from uuid import uuid4
42
41
 
 
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
47
47
 
48
48
class systemManager:
49
49
    """Class to deal with the basics of system-level interaction
62
62
                         , 'port_manager'
63
63
                         , 'logging_manager'
64
64
                         , 'environment_reqs'
65
 
                         , 'env_var_delimiter']
 
65
                         ]
66
66
        self.debug = variables['debug']
67
67
        self.verbose = variables['verbose']
68
 
        self.env_var_delimiter = ':'
69
68
        self.no_shm = variables['noshm']
70
69
        self.shm_path = self.find_path(["/dev/shm", "/tmp"], required=0)
71
70
        self.cur_os = os.uname()[0]
94
93
        # Make sure the tree we are testing looks good
95
94
        self.code_tree = self.code_manager.code_trees['drizzle'][0]
96
95
 
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)
 
98
 
 
99
        self.ld_lib_paths = self.env_manager.join_env_var_values(self.code_tree.ld_lib_paths)
98
100
 
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
114
117
                                                                         , suffix = 0
115
118
                                                                         , quiet = 1
116
119
                                                                         )
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
119
122
                                                                         , suffix = 0
120
123
                                                                         , quiet = 1
122
125
                                }
123
126
        # set the env vars we need
124
127
        # self.process_environment_reqs(self.environment_reqs)
125
 
        self.update_environment_vars(self.environment_reqs)
 
128
        self.env_manager.update_environment_vars(self.environment_reqs)
126
129
 
127
130
        # We find or generate our id file
128
131
        # We use a uuid to identify the symlinked
144
147
        self.handle_additional_reqs(variables)
145
148
     
146
149
        self.logging.debug_class(self)
147
 
        
148
 
 
149
 
    
 
150
 
 
151
 
150
152
    def create_dirset(self, rootdir, dirset):
151
153
        """ We produce the set of directories defined in dirset
152
154
            dirset is a set of dictionaries like
296
298
            source, link_name = needed_symlink
297
299
            self.create_symlink(source, link_name)
298
300
 
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
302
 
 
303
 
        """
304
 
 
305
 
        return self.env_var_delimiter.join(value_list)
306
 
 
307
 
    def set_env_var(self, var_name, var_value, quiet=0):
308
 
        """Set an environment variable.  We really just abstract
309
 
           voodoo on os.environ
310
 
 
311
 
        """
312
 
        if not quiet:
313
 
            self.logging.debug("Setting env var: %s" %(var_name))
314
 
        try:
315
 
            os.environ[var_name]=var_value
316
 
        except Exception, e:
317
 
            self.logging.error("Issue setting environment variable %s to value %s" %(var_name, var_value))
318
 
            self.logging.error("%s" %(e))
319
 
            sys.exit(1)
320
 
 
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
327
 
 
328
 
        """
329
 
 
330
 
        if not working_environment:
331
 
            working_environment = os.environ
332
 
        working_environment.update(desired_vars)
333
 
        return working_environment
334
 
 
335
 
    def create_working_environment(self, desired_vars):
336
 
        """ We return a copy of os.environ updated with desired_vars """
337
 
 
338
 
        working_copy = copy.deepcopy(os.environ)
339
 
        return self.update_environment_vars( desired_vars
340
 
                                    , working_environment = working_copy )
341
 
 
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
346
 
 
347
 
        """
348
 
        new_var_value = ""
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 ]
353
 
            else:
354
 
                new_var_values = [ append_string, cur_var_value ]
355
 
            new_var_value = self.env_var_delimiter.join(new_var_values)
356
 
        else:
357
 
            # No existing variable value
358
 
            new_var_value = append_string
359
 
        return new_var_value
 
301
 
360
302
 
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)
525
467
 
526
468
 
527
469
    def cleanup(self, exit=False):