Browse Source

Generalize framework-specific install directories

- adds an '--install-strategy' option
- framework_test properly sets the install location before calling setup.py
- removes '--install-software' option (checks for '--install' instead)

Still proof-of-concept, only 'go' works!
Hamilton Turner 11 years ago
parent
commit
bdebad6f63

+ 4 - 3
go/bash_profile.sh

@@ -1,6 +1,7 @@
-# IROOT=${FWROOT}/go/installs
-
+# Set the root of our go installation
 export GOROOT=${IROOT}/go
+
+# Where to find the go executable
 export PATH="$GOROOT/bin:$PATH"
 
-export GOPATH=${FWROOT}/go
+export GOPATH=${FWROOT}/go

+ 7 - 2
toolset/benchmark/benchmarker.py

@@ -1,4 +1,6 @@
 from setup.linux.installer import Installer
+from setup.linux import setup_util
+
 from benchmark import framework_test
 
 import os
@@ -861,6 +863,9 @@ class Benchmarker:
     if self.database_host == None: self.database_host = self.client_host
     if self.database_identity_file == None: self.database_identity_file = self.client_identity_file
 
+    # Remember root directory
+    self.fwroot = setup_util.get_fwroot()
+
     # setup results and latest_results directories 
     self.result_directory = os.path.join("results", self.name)
     self.latest_results_directory = self.latest_results_directory()
@@ -968,8 +973,8 @@ class Benchmarker:
     if self.client_identity_file != None:
       self.client_ssh_string = self.client_ssh_string + " -i " + self.client_identity_file
 
-    if self.install_software:
-      install = Installer(self)
+    if self.install is not None:
+      install = Installer(self, self.install_strategy)
       install.install_software()
 
   ############################################################

+ 13 - 1
toolset/benchmark/framework_test.py

@@ -286,8 +286,13 @@ class FrameworkTest:
   # Start the test using it's setup file
   ############################################################
   def start(self, out, err):
+    # First replace the environment with the one defined in 
+    # this tests bash_profile.sh
     profile="%s/bash_profile.sh" % self.directory
-    setup_util.replace_environ(config=profile, command="IROOT=$FWROOT/go/installs")
+    
+    set_iroot="IROOT=%s" % self.install_root
+    setup_util.replace_environ(config=profile, command=set_iroot)
+
     return self.setup_module.start(self.benchmarker, out, err)
   ############################################################
   # End start
@@ -903,6 +908,13 @@ class FrameworkTest:
     self.directory = directory
     self.benchmarker = benchmarker
     self.runTests = runTests
+    self.fwroot = benchmarker.fwroot
+    
+    if benchmarker.install_strategy is 'pertest':
+      self.install_root = "%s/%s" % (directory, "installs")
+    else:
+      self.install_root = "%s/%s" % (self.fwroot, "installs")
+
     self.__dict__.update(args)
 
     # ensure directory has __init__.py file so that we can use it as a Python package

+ 8 - 2
toolset/run-tests.py

@@ -28,7 +28,10 @@ def main(argv=None):
     sys.path.append('toolset/setup/linux')
 
     # Update environment for shell scripts
-    setup_util.replace_environ(config='config/benchmark_profile', root=os.getcwd())
+    fwroot = setup_util.get_fwroot()
+    if not fwroot: 
+        fwroot = os.getcwd()
+    setup_util.replace_environ(config='config/benchmark_profile', root=fwroot)
 
     conf_parser = argparse.ArgumentParser(
         description=__doc__,
@@ -83,12 +86,15 @@ def main(argv=None):
     parser.add_argument('--database-identity-file', default=dbIdenFile, dest='database_identity_file',
                         help='The key to use for SSH to the database instance.  If not provided, defaults to the value of --client-identity-file.')
     parser.add_argument('-p', dest='password_prompt', action='store_true', help='Prompt for password')
-    parser.add_argument('--install-software', action='store_true', help='runs the installation script before running the rest of the commands')
+    
     
     # Install options
     parser.add_argument('--install', choices=['client', 'database', 'server', 'all'], default=None,
                         help='Runs installation script(s) before continuing on to execute the tests.')
     parser.add_argument('--install-error-action', choices=['abort', 'continue'], default='continue', help='action to take in case of error during installation')
+    parser.add_argument('--install-strategy', choices=['unified', 'pertest'], default='pertest', 
+        help='''Affects `--install server`: With unified, all server software is installed into a single directory. 
+        With pertest each test gets its own installs directory, but installation takes longer''')
 
     # Test options
     parser.add_argument('--test', nargs='+', help='names of tests to run')

+ 13 - 23
toolset/setup/linux/installer.py

@@ -31,7 +31,7 @@ class Installer:
   # __install_server_software
   ############################################################
   def __install_server_software(self):
-    print("\nINSTALL: Installing server software\n")
+    print("\nINSTALL: Installing server software (strategy=%s)\n"%self.strategy)
     
     # Install global prerequisites
     bash_functions_path='$FWROOT/toolset/setup/linux/bash_functions.sh'
@@ -45,13 +45,13 @@ class Installer:
         exclude = []
 
     # Locate all known tests
-    install_files = glob.glob("%s/*/install.sh" % self.root)
+    install_files = glob.glob("%s/*/install.sh" % self.fwroot)
 
     # Run install for selected tests
     for test_install_file in install_files:
         test_dir = os.path.dirname(test_install_file)
         test_name = os.path.basename(test_dir)
-        test_rel_dir = self.__path_relative_to_root(test_dir)
+        test_rel_dir = setup_util.path_relative_to_root(test_dir)
 
         if test_name in exclude:
             logging.debug("%s has been excluded", test_name)
@@ -63,8 +63,11 @@ class Installer:
             logging.info("Running installation for %s"%test_name)
 
             # Find installation directory e.g. FWROOT/go/installs
-            test_install_dir="%s/%s" % (test_dir, self.install_dir)
-            test_rel_install_dir=self.__path_relative_to_root(test_install_dir)
+            if self.strategy is 'pertest':
+              test_install_dir="%s/%s" % (test_dir, self.install_dir)
+            else:
+              test_install_dir="%s/%s" % (self.fwroot, self.install_dir)
+            test_rel_install_dir=setup_util.path_relative_to_root(test_install_dir)
             if not os.path.exists(test_install_dir):
               os.makedirs(test_install_dir)
 
@@ -76,7 +79,7 @@ class Installer:
               logging.warning("Framework %s does not have a bash_profile"%test_name)
 
             # Find relative installation file
-            test_rel_install_file = "$FWROOT%s"%self.__path_relative_to_root(test_install_file)
+            test_rel_install_file = "$FWROOT%s" % setup_util.path_relative_to_root(test_install_file)
 
             # Then run test installer file
             # Give all installers FWROOT, IROOT, and bash_functions
@@ -283,7 +286,7 @@ EOF
     if send_yes:
       command = "yes yes | " + command
         
-    rel_cwd = self.__path_relative_to_root(cwd)
+    rel_cwd = setup_util.path_relative_to_root(cwd)
     print("INSTALL: %s (cwd=%s)" % (command, rel_cwd))
 
     while attempt <= max_attempts:
@@ -326,20 +329,6 @@ EOF
   # End __bash_from_string
   ############################################################
 
-  ############################################################
-  # __path_relative_to_root
-  # Returns path minus the FWROOT prefix. Useful for clean 
-  # presentation of paths 
-  # e.g. /foo/bar/benchmarks/go/bash_profile.sh
-  # v.s. FWROOT/go/bash_profile.sh 
-  ############################################################
-  def __path_relative_to_root(self, path):
-    # Requires bash shell parameter expansion
-    return subprocess.check_output("D=%s && printf ${D#%s}"%(path, self.root), shell=True, executable='/bin/bash')
-  ############################################################
-  # End __path_relative_to_root
-  ############################################################
-
   ############################################################
   # __download
   # Downloads a file from a URI.
@@ -360,10 +349,11 @@ EOF
   ############################################################
   # __init__(benchmarker)
   ############################################################
-  def __init__(self, benchmarker):
+  def __init__(self, benchmarker, install_strategy):
     self.benchmarker = benchmarker
     self.install_dir = "installs"
-    self.root = subprocess.check_output('printf $FWROOT', shell=True)
+    self.fwroot = benchmarker.fwroot
+    self.strategy = install_strategy
     
     # setup logging
     logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

+ 26 - 8
toolset/setup/linux/setup_util.py

@@ -11,15 +11,13 @@ def replace_text(file, to_replace, replacement):
         f.write(replaced_text)
 
 # Replaces the current process environment with the one found in 
-# config file. Retains original HOME/PATH/USER by default (although)
-# this can be overwritten by config if desired
+# config file. Retains a few original vars (HOME,PATH, etc) by default. 
+# Optionally allows specification of a command to be run before loading
+# the environment, to allow the framework to set environment variables
+# Note: This command *cannot* print to stdout!
 #
-# Note: This will not work if the command you are running from python
-# starts with sudo (e.g. subprocess.check_call("sudo <command>")). 
-# If you must do this, consider sudo sh -c ". <config> && your_command"
-#
-# This will work if you run a command that internally calls sudo, 
-# as long as your /etc/sudoers correctly has the NOPASSWD option set
+# Note: This will not replace the sudo environment (e.g. subprocess.check_call("sudo <command>")). 
+# If you must use sudo, consider sudo sh -c ". <config> && your_command"
 def replace_environ(config=None, root=None, print_result=False, command='true'):
     # Source file and print resulting environment
     setup_env = "%s && . %s && env" % (command, config)
@@ -59,3 +57,23 @@ def replace_environ(config=None, root=None, print_result=False, command='true'):
         out = subprocess.check_output('env', shell=True, executable='/bin/bash')
         print "Environment after loading %s" %config
         print out
+
+# Queries the shell for the value of FWROOT
+def get_fwroot():
+    try:
+        # Use printf to avoid getting a newline
+        # Redirect to avoid stderr printing
+        fwroot = subprocess.check_output('printf $FWROOT 2> /dev/null', shell=True, executable='/bin/bash')
+        return fwroot
+    except subprocess.CalledProcessError:
+        return "";
+
+# Turns absolute path into path relative to FWROOT
+# Assumes path is underneath FWROOT, not above
+# 
+# Useful for clean presentation of paths 
+# e.g. /foo/bar/benchmarks/go/bash_profile.sh
+# v.s. FWROOT/go/bash_profile.sh 
+def path_relative_to_root(path):
+    # Requires bash shell parameter expansion
+    return subprocess.check_output("D=%s && printf ${D#%s}"%(path, get_fwroot()), shell=True, executable='/bin/bash')