~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-02-04 20:41:08 UTC
  • mto: (2145.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: gleebix@gmail.com-20110204204108-cyhtpo5kfu7wy88q
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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
 
1
#! /usr/bin/env python
2
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
#
33
33
# imports
34
34
import os
35
35
import sys
 
36
import copy
36
37
import shutil
37
38
import getpass
38
39
import commands
84
85
        # Make sure the tree we are testing looks good
85
86
        self.code_tree = self.get_code_tree(variables, tree_type)
86
87
 
87
 
        self.ld_lib_paths = self.code_tree.ld_lib_paths
 
88
        self.ld_lib_paths = self.join_env_var_values(self.code_tree.ld_lib_paths)
88
89
 
89
90
        # Some ENV vars are system-standard
90
91
        # We describe and set them here and now
91
92
        # The format is name: (value, append, suffix)
92
 
        self.environment_reqs = { 'UMASK':('0660',0,0)
93
 
                                , 'UMASK_DIR' : ('0770',0,0)
94
 
                                , 'LC_ALL' : ('C',0,0)
95
 
                                , 'LC_CTYPE' : ('C',0,0)
96
 
                                , 'LC_COLLATE' : ('C',0,0)
97
 
                                , 'USE_RUNNING_SERVER' : ("0",0,0)
98
 
                                , 'TOP_SRCDIR' : (self.top_srcdir,0,0)
99
 
                                , 'TOP_BUILDDIR' : (self.top_builddir,0,0)
100
 
                                , 'DRIZZLE_TEST_DIR' : (self.code_tree.testdir,0,0)
101
 
                                , 'DTR_BUILD_THREAD' : ("-69.5",0,0)
102
 
                                , 'LD_LIBRARY_PATH' : (self.ld_lib_paths,1,1)
103
 
                                , 'DYLD_LIBRARY_PATH' : (self.ld_lib_paths,1,1)
 
93
        self.environment_reqs = { 'UMASK':'0660'
 
94
                                , 'UMASK_DIR' : '0770'
 
95
                                , 'LC_ALL' : 'C'
 
96
                                , 'LC_CTYPE' : 'C'
 
97
                                , 'LC_COLLATE' : 'C'
 
98
                                , 'USE_RUNNING_SERVER' : "0"
 
99
                                , 'TOP_SRCDIR' : self.top_srcdir
 
100
                                , 'TOP_BUILDDIR' : self.top_builddir
 
101
                                , 'DRIZZLE_TEST_DIR' : self.code_tree.testdir
 
102
                                , 'DTR_BUILD_THREAD' : "-69.5"
 
103
                                , 'LD_LIBRARY_PATH' : self.append_env_var( 'LD_LIBRARY_PATH'
 
104
                                                                         , self.ld_lib_paths
 
105
                                                                         , suffix = 0
 
106
                                                                         , quiet = 1
 
107
                                                                         )
 
108
                                , 'DYLD_LIBRARY_PATH' : self.append_env_var( 'DYLD_LIBRARY_PATH'
 
109
                                                                         , self.ld_lib_paths
 
110
                                                                         , suffix = 0
 
111
                                                                         , quiet = 1
 
112
                                                                         )
104
113
                                }
105
114
        # set the env vars we need
106
 
        self.process_environment_reqs(self.environment_reqs)
 
115
        # self.process_environment_reqs(self.environment_reqs)
 
116
        self.update_environment_vars(self.environment_reqs)
107
117
 
108
118
        # initialize our workdir
109
119
        self.process_workdir()
153
163
            return test_tree
154
164
        else:
155
165
            self.logging.error("Tree_type: %s not supported yet" %(tree_type))
156
 
            sys.exit(1)
157
 
 
158
 
   
159
 
    def process_environment_reqs(self, environment_reqs, quiet=0):
160
 
        """ We process a dictionary in a specific format
161
 
            that asks for various env vars to be set
162
 
            These values can be used to overwrite,
163
 
            append, or prepend a new value string to
164
 
            a named variable.
165
 
 
166
 
            Currently, we require multiple values to
167
 
            already to joined into a single string
168
 
            We can fix this later
169
 
 
170
 
        """
171
 
 
172
 
        for var_name, data_tuple in environment_reqs.items():
173
 
            value, append_flag, suffix_flag = data_tuple
174
 
            if type(value) is list:
175
 
                value = self.join_env_var_values(value)
176
 
            if append_flag:
177
 
                self.append_env_var(var_name, value, suffix_flag, quiet=quiet)
178
 
            else:
179
 
                self.set_env_var(var_name, value, quiet)
180
 
            
181
 
            
 
166
            sys.exit(1)        
182
167
 
183
168
    def get_port_block(self, requester, base_port, block_size):
184
169
        """ Try to assign a block of ports for test execution
341
326
            self.logging.error("%s" %(e))
342
327
            sys.exit(1)
343
328
 
 
329
    def update_environment_vars(self, desired_vars, working_environment=None):
 
330
        """ We update the environment vars with desired_vars
 
331
            The expectation is that you know what you are asking for ; )
 
332
            If working_environment is provided, we will update that with
 
333
            desired_vars.  We operate directly on os.environ by default
 
334
            We return our updated environ dictionary
 
335
 
 
336
        """
 
337
 
 
338
        if not working_environment:
 
339
            working_environment = os.environ
 
340
        working_environment.update(desired_vars)
 
341
        return working_environment
 
342
 
 
343
    def create_working_environment(self, desired_vars):
 
344
        """ We return a copy of os.environ updated with desired_vars """
 
345
 
 
346
        working_copy = copy.deepcopy(os.environ)
 
347
        return self.update_environment_vars( desired_vars
 
348
                                    , working_environment = working_copy )
 
349
 
344
350
    def append_env_var(self, var_name, append_string, suffix=1, quiet=0):
345
351
        """ We add the values in var_values to the environment variable 
346
352
            var_name.  Depending on suffix value, we either append or prepend
347
 
            Use set_env_var to just overwrite an ENV var
 
353
            we return a string suitable for os.putenv
348
354
 
349
355
        """
350
356
        new_var_value = ""
358
364
        else:
359
365
            # No existing variable value
360
366
            new_var_value = append_string
361
 
        self.set_env_var(var_name, new_var_value, quiet=quiet)
 
367
        return new_var_value
362
368
 
363
369
    def find_path(self, paths, required=1):
364
370
        """We search for the files we need / want to be aware of
450
456
        if os.path.exists(debug_path):
451
457
            self.append_env_var("LD_LIBRARY_PATH", debug_path, suffix=1)
452
458
            self.append_env_var("DYLD_LIBRARY_PATH", debug_path, suffix=1)
 
459
 
 
460
   
453
461
    
454
462
 
455
463