fixed kill_qemus : uses qemu -pidfile for locating pids
[tests.git] / system / TestMain.py
index 9d7753f..661a8f9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # $Id$
 
-import os, sys
+import sys, os, os.path
 from optparse import OptionParser
 import traceback
 
@@ -21,21 +21,26 @@ class TestMain:
                      'clear_ssh_config','store_keys', 'initscripts', 
                      'sites', 'nodes', 'slices', 
                      'bootcd', 'nodegroups', 
-                     'start_nodes', 'standby_4','nodes_booted','standby_6','nodes_ssh', 'check_slices' ]
-    other_steps = [ 'fresh_install', 'stop', 
+                     'kill_all_qemus', 'start_nodes', 
+                     'standby_10', 'nodes_booted',
+                     'standby_6','nodes_ssh', 'check_slices','check_initscripts',
+                     'force_kill_qemus', ]
+    other_steps = [ 'stop_all_vservers','fresh_install', 'stop','check_tcp', 
                     'clean_sites', 'clean_nodes', 'clean_slices', 'clean_keys',
-                    'stop_nodes' ,  'db_dump' , 'db_restore',
+                    'list_all_qemus', 'list_qemus', 'stop_nodes' ,  
+                    'db_dump' , 'db_restore',
                     'standby_1 through 20',
                     ]
     default_build_url = "http://svn.planet-lab.org/svn/build/trunk"
 
     def __init__ (self):
        self.path=os.path.dirname(sys.argv[0])
+        os.chdir(self.path)
 
     @staticmethod
     def show_env (options, message):
         utils.header (message)
-        utils.show_spec("main options",options)
+        utils.pprint("main options",options)
 
     @staticmethod
     def optparse_list (option, opt, value, parser):
@@ -81,6 +86,8 @@ steps refer to a method in TestPlc or to a step_* module
                           help="Specify the set of IP addresses to use in vserver mode (disable scanning)")
         parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
                           help="Run in verbose mode")
+        parser.add_option("-q","--quiet", action="store_true", dest="quiet", default=False, 
+                          help="Run in quiet mode")
         parser.add_option("-n","--dry-run", action="store_true", dest="dry_run", default=False,
                           help="Show environment and exits")
         parser.add_option("-f","--forcenm", action="store_true", dest="forcenm", default=False, 
@@ -103,12 +110,14 @@ steps refer to a method in TestPlc or to a step_* module
             self.options.steps = self.args
 
         # handle defaults and option persistence
-        for (recname,filename,default) in ( ('myplc_url','arg-myplc-url',"") , 
-                                            ('build_url','arg-build-url',TestMain.default_build_url) ,
-                                            ('ips','arg-ips',[]) , 
-                                            ('config','arg-config',TestMain.default_config) , ) :
-            print 'handling',recname
-            path="%s/%s"%(self.path,filename)
+        for (recname,filename,default) in (
+            ('build_url','arg-build-url',TestMain.default_build_url) ,
+            ('ips','arg-ips',[]) , 
+            ('config','arg-config',TestMain.default_config) , 
+            ('myplc_url','arg-myplc-url',"") , 
+            ) :
+#            print 'handling',recname
+            path=filename
             is_list = isinstance(default,list)
             if not getattr(self.options,recname):
                 try:
@@ -128,7 +137,8 @@ steps refer to a method in TestPlc or to a step_* module
                         print "Cannot determine",recname
                         print "Run %s --help for help"%sys.argv[0]                        
                         sys.exit(1)
-            utils.header('* Using %s = %s'%(recname,getattr(self.options,recname)))
+            if not self.options.quiet:
+                utils.header('* Using %s = %s'%(recname,getattr(self.options,recname)))
 
             # save for next run
             fsave=open(path,"w")
@@ -138,7 +148,7 @@ steps refer to a method in TestPlc or to a step_* module
                 for value in getattr(self.options,recname):
                     fsave.write(value + "\n")
             fsave.close()
-            utils.header('Saved %s into %s'%(recname,filename))
+#            utils.header('Saved %s into %s'%(recname,filename))
 
         # steps
         if not self.options.steps:
@@ -146,8 +156,8 @@ steps refer to a method in TestPlc or to a step_* module
             #self.options.steps=['dump','clean','install','populate']
             self.options.steps=TestMain.default_steps
 
-        # store self.path in options.path for the various callbacks
-        self.options.path = self.path
+        # this is useful when propagating on host boxes, to avoid conflicts
+        self.options.buildname = os.path.basename (os.path.abspath (self.path))
 
         if self.options.verbose:
             self.show_env(self.options,"Verbose")
@@ -164,19 +174,28 @@ steps refer to a method in TestPlc or to a step_* module
                 print 'Cannot load config %s -- ignored'%modulename
                 raise
         # show config
-        utils.show_spec("Test specifications",all_plc_specs)
+        if not self.options.quiet:
+            utils.show_test_spec("Test specifications",all_plc_specs)
         # build a TestPlc object from the result
         for spec in all_plc_specs:
             spec['disabled'] = False
         all_plcs = [ (x, TestPlc(x)) for x in all_plc_specs]
+        # expose to the various objects
+        for (spec,obj) in all_plcs:
+            obj.options=self.options
 
         overall_result = True
         testplc_method_dict = __import__("TestPlc").__dict__['TestPlc'].__dict__
         all_step_infos=[]
         for step in self.options.steps:
+            force=False
+            # is it a forcedstep
+            if step.find("force_") == 0:
+                step=step.replace("force_","")
+                force=True
             # try and locate a method in TestPlc
             if testplc_method_dict.has_key(step):
-                all_step_infos += [ (step, testplc_method_dict[step] )]
+                all_step_infos += [ (step, testplc_method_dict[step] , force)]
             # otherwise search for the 'run' method in the step_<x> module
             else:
                 modulename='step_'+step
@@ -187,7 +206,7 @@ steps refer to a method in TestPlc or to a step_* module
                     if not names:
                         raise Exception,"No run* method in module %s"%modulename
                     names.sort()
-                    all_step_infos += [ ("%s.%s"%(step,name),module_dict[name]) for name in names ]
+                    all_step_infos += [ ("%s.%s"%(step,name),module_dict[name],force) for name in names ]
                 except :
                     print 'Step %s -- ignored'%(step)
                     traceback.print_exc()
@@ -198,26 +217,33 @@ steps refer to a method in TestPlc or to a step_* module
             return 0
             
         # do all steps on all plcs
-        for (stepname,method) in all_step_infos:
+        for (stepname,method,force) in all_step_infos:
             for (spec,obj) in all_plcs:
                 plcname=spec['name']
-                if spec['disabled']:
-                    utils.header("Plc %s is disabled - skipping step %s"%(plcname,stepname))
-                else:
+
+                # run the step
+                if not spec['disabled'] or force:
                     try:
-                        utils.header("Running step %s on plc %s"%(stepname,plcname))
+                        force_msg=""
+                        if force: force_msg=" (forced)"
+                        utils.header("Running step %s%s on plc %s"%(stepname,force_msg,plcname))
                         step_result = method(obj,self.options)
                         if step_result:
-                            utils.header('Successful step %s on %s'%(stepname,plcname))
+                            utils.header('********** SUCCESSFUL step %s on %s'%(stepname,plcname))
                         else:
                             overall_result = False
                             spec['disabled'] = True
-                            utils.header('Step %s on %s FAILED - discarding that plc from further steps'%(stepname,plcname))
+                            utils.header('********** Step %s on %s FAILED - discarding that plc from further steps'%(stepname,plcname))
                     except:
                         overall_result=False
                         spec['disabled'] = True
-                        utils.header ('Step %s on plc %s FAILED (exception) - discarding this plc from further steps'%(stepname,plcname))
                         traceback.print_exc()
+                        utils.header ('********** Step %s on plc %s FAILED (exception) - discarding this plc from further steps'%(stepname,plcname))
+
+                # do not run, just display it's skipped
+                else:
+                    utils.header("Plc %s is disabled - skipping step %s"%(plcname,stepname))
+
         return overall_result
 
     # wrapper to run, returns a shell-compatible result