Browse Source

Attempting to REALLY kill tests

msmith-techempower 10 years ago
parent
commit
339022960c
3 changed files with 26 additions and 25 deletions
  1. 3 2
      benchmark.cfg.example
  2. 14 22
      toolset/benchmark/framework_test.py
  3. 9 1
      toolset/run-tests.py

+ 3 - 2
benchmark.cfg.example

@@ -2,11 +2,12 @@
 # Available Keys: 
 client_host=localhost
 client_identity_file=None
-client_user=localhost
+client_user=techempower
+runner_user=testrunner
 database_host=localhost
 database_identity_file=None
 database_os=linux
-database_user=tfb
+database_user=techempower
 duration=60
 exclude=None
 install=server

+ 14 - 22
toolset/benchmark/framework_test.py

@@ -192,25 +192,20 @@ class FrameworkTest:
     previousDir = os.getcwd()
     os.chdir(os.path.dirname(self.troot))
     logging.info("Running setup module start (cwd=%s)", os.path.dirname(self.troot))
-    try:
-      retcode = self.setup_module.start(self, out, err)    
-      if retcode == None: 
-        retcode = 0
-    except Exception:
-      retcode = 1
-      st = traceback.format_exc()
-      st = '\n'.join((4 * ' ') + x for x in st.splitlines())
-      st = "Start exception:\n%s" % st
-      logging.info(st)
-      err.write(st + '\n')
-    os.chdir(previousDir)
+    
+    # Run the start script for the test as the "testrunner" user.
+    # This requires superuser privs, so `sudo` is necessary.
+    #   -u [username] The username
+    #   -E Preserves the current environment variables
+    print 'sudo -u %s -E ./%s' % (self.benchmarker.runner_user, self.setup_file)
+    subprocess.Popen('sudo -u %s -E ./%s' % (self.benchmarker.runner_user, self.setup_file), cwd=self.directory, shell=True, stderr=err, stdout=out)
 
     # Stop the progress printer
     stopFlag.set()
 
     logging.info("Called setup.py start")
 
-    return retcode
+    return 0
   ############################################################
   # End start
   ############################################################
@@ -236,17 +231,14 @@ class FrameworkTest:
     previousDir = os.getcwd()
     os.chdir(os.path.dirname(self.troot))
     logging.info("Running setup module stop (cwd=%s)", os.path.dirname(self.troot))
+
+    # Meganuke
     try:
-      retcode = self.setup_module.stop(out, err)
-      if retcode == None: 
-        retcode = 0
+      subprocess.check_call('sudo killall -s 9 -u testrunner', shell=True, stderr=err, stdout=out)
+      retcode = 0
     except Exception:
-      retcode = 1 
-      st = traceback.format_exc()
-      st = '\n'.join((4 * ' ') + x for x in st.splitlines())
-      st = "Stop exception:\n%s\n" % st
-      logging.info(st)
-      err.write(st + '\n')
+      retcode = 1
+
     os.chdir(previousDir)
 
     # Give processes sent a SIGTERM a moment to shut down gracefully

+ 9 - 1
toolset/run-tests.py

@@ -99,6 +99,7 @@ def main(argv=None):
     clientHost = os.environ.get('TFB_CLIENT_HOST')
     clientUser = os.environ.get('TFB_CLIENT_USER')
     clientIden = os.environ.get('TFB_CLIENT_IDENTITY_FILE')
+    runnerUser = os.environ.get('TFB_RUNNER_USER')
     databaHost = os.getenv('TFB_DATABASE_HOST', clientHost)
     databaUser = os.getenv('TFB_DATABASE_USER', clientUser)
     dbIdenFile = os.getenv('TFB_DATABASE_IDENTITY_FILE', clientIden)
@@ -125,6 +126,7 @@ def main(argv=None):
     parser.add_argument('-s', '--server-host', default=serverHost, help='The application server.')
     parser.add_argument('-c', '--client-host', default=clientHost, help='The client / load generation server.')
     parser.add_argument('-u', '--client-user', default=clientUser, help='The username to use for SSH to the client instance.')
+    parser.add_argument('-r', '--runner-user', default=runnerUser, help='The user to run each test as.')
     parser.add_argument('-i', '--client-identity-file', dest='client_identity_file', default=clientIden,
                         help='The key to use for SSH to the client instance.')
     parser.add_argument('-d', '--database-host', default=databaHost,
@@ -172,11 +174,17 @@ def main(argv=None):
 
     # Verify and massage options
     if args.client_user is None:
-      print 'Usernames (e.g. --client-user and --database-user) are required!'
+      print 'Usernames (e.g. --client-user, --runner-user, and --database-user) are required!'
       print 'The system will SSH into the client and the database for the install stage'
       print 'Aborting'
       exit(1)
 
+    if args.runner_user is None:
+      print 'Usernames (e.g. --client-user, --runner-user, and --database-user) are required!'
+      print 'The system will run each test as the runner-user'
+      print 'Aborting'
+      exit(1)        
+
     if args.database_user is None:
       args.database_user = args.client_user