import traceback
from time import strftime
import readline
+import glob
import utils
from TestPlc import TestPlc
sys.path.append(os.environ['HOME'])
import LocalSubstrate
+class Step:
+
+ natives=TestPlc.__dict__
+
+ def __init__ (self, name):
+ self.name=name.replace('-','_')
+ # a native step is implemented as a method on TestPlc
+ self.native = name in Step.natives
+ if self.native:
+ self.method=Step.natives[self.name]
+ else:
+ # non-native steps (macros) are implemented as a 'Step'
+ try:
+ modulename = 'macro_' + self.name
+ module = __import__ (modulename)
+ self.substeps = module.sequence
+ except Exception,e:
+ print "Cannot load macro step %s (%s) - exiting"%(self.name,e)
+ raise
+
+ def norm_name (self): return self.name.replace('_','-')
+
+ def print_doc (self):
+ if self.native:
+ print '*',self.norm_name(),"\r",4*"\t",
+ try:
+ print self.method.__doc__
+ except:
+ print "*** no doc found"
+ else:
+ print '*',self.norm_name(),"\r",3*"\t","========== BEG MACRO step"
+ for step in self.substeps:
+ Step(step).print_doc()
+ print '*',self.norm_name(),"\r",3*"\t","========== END MACRO step"
+
+ # return a list of (name, method) for all native steps involved
+ def tuples (self):
+ if self.native: return [ (self.name, self.method,) ]
+ else:
+ result=[]
+ for substep in [ Step(name) for name in self.substeps ] :
+ result += substep.tuples()
+ return result
+
+ # convenience for listing macros
+ # just do a listdir, hoping we're in the right directory...
+ @staticmethod
+ def list_macros ():
+ names= [ filename.replace('macro_','').replace('.py','') for filename in glob.glob ('macro_*.py')]
+ names.sort()
+ return names
+
class TestMain:
subversion_id = "Now using git -- version tracker broken"
def init_steps(self):
self.steps_message = 20*'x'+" Defaut steps are\n"+TestPlc.printable_steps(TestPlc.default_steps)
self.steps_message += 20*'x'+" Other useful steps are\n"+TestPlc.printable_steps(TestPlc.other_steps)
+ self.steps_message += 20*'x'+" Macro steps are\n"+" ".join(Step.list_macros())
def list_steps(self):
if not self.options.verbose:
print self.steps_message,
else:
- testplc_method_dict = __import__("TestPlc").__dict__['TestPlc'].__dict__
- scopes = [("Default steps",TestPlc.default_steps)]
- if self.options.all_steps:
- scopes.append ( ("Other steps",TestPlc.other_steps) )
+ # steps mentioned on the command line
+ if self.options.args:
+ scopes = [("Argument steps",self.options.args)]
+ else:
+ scopes = [("Default steps",TestPlc.default_steps)]
+ if self.options.all_steps:
+ scopes.append ( ("Other steps",TestPlc.other_steps) )
+ # try to list macro steps as well
+ scopes.append ( ("Macro steps", Step.list_macros()) )
for (scope,steps) in scopes:
print '--------------------',scope
for step in [step for step in steps if TestPlc.valid_step(step)]:
stepname=step
for special in ['force']:
stepname = stepname.replace(special+'_',"")
- print '*',step,"\r",4*"\t",
- try:
- doc=testplc_method_dict[stepname].__doc__
- except:
- try:
- # locate the step_<name> module
- modulename='step_'+stepname
- doc = __import__(modulename).__doc__
- except:
- doc=None
- if doc: print doc
- else: print "*** no doc found"
+ Step(stepname).print_doc()
def run (self):
self.init_steps()
TestPlc.check_whether_build_has_sfa(self.options.arch_rpms_url)
# no step specified
+ self.options.args = self.args
if len(self.args) == 0:
self.options.steps=TestPlc.default_steps
else:
try: (step,qualifier)=step.split('@')
except: qualifier=self.options.qualifier
- # try and locate a method in TestPlc
- if testplc_method_dict.has_key(step):
- all_step_infos += [ (step, testplc_method_dict[step] , force, cross, qualifier)]
- # otherwise search for the 'run' method in the step_<x> module
- else:
- modulename='step_'+step
- try:
- # locate all methods named run* in the module
- module_dict = __import__(modulename).__dict__
- names = [ key for key in module_dict.keys() if key.find("run")==0 ]
- if not names:
- raise Exception,"No run* method in module %s"%modulename
- names.sort()
- all_step_infos += [ ("%s.%s"%(step,name),module_dict[name],force,cross,qualifier) for name in names ]
- except :
- utils.header("********** FAILED step %s (NOT FOUND) -- won't be run"%step)
- traceback.print_exc()
- overall_result = False
+ try:
+ stepobj = Step (step)
+ for (substep, method) in stepobj.tuples():
+ all_step_infos.append ( (substep, method, force, cross, qualifier, ) )
+ except :
+ utils.header("********** FAILED step %s (NOT FOUND) -- won't be run"%step)
+ traceback.print_exc()
+ overall_result = False
if self.options.dry_run:
self.show_env(self.options,"Dry run")
'force_gather_logs', SEP,
]
other_steps = [
- 'export',
- 'check_hooks',
- 'free_all',
- 'show_boxes', 'local_list','local_rel','local_rel_plc','local_rel_qemu',SEP,
- 'plc_stop', 'vs_start', 'vs_stop', SEP,
+ 'export', 'show_boxes', SEP,
+ 'check_hooks', 'plc_stop', 'vs_start', 'vs_stop', SEP,
'delete_initscripts', 'delete_nodegroups','delete_all_sites', SEP,
'delete_sites', 'delete_nodes', 'delete_slices', 'keys_clean', SEP,
'delete_leases', 'list_leases', SEP,
'qemu_list_all', 'qemu_list_mine', 'qemu_kill_all', SEP,
'sfa_plcclean', 'sfa_dbclean', 'sfa_stop','sfa_uninstall', 'sfi_clean', SEP,
'plc_db_dump' , 'plc_db_restore', SEP,
- 'standby_1 through 20',SEP,
+ 'standby_1_through_20',SEP,
]
@staticmethod
now=int(time.time())
return utils.system(self.test_ssh.actual_command("echo %d > /vservers/%s.timestamp"%(now,self.vservername)))==0
- def local_pre (self):
- "run site-dependant pre-test script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_pre(self)
-
- def local_post (self):
- "run site-dependant post-test script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_post(self)
-
- def local_list (self):
- "run site-dependant list script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_list(self)
-
- def local_rel (self):
- "run site-dependant release script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_release(self)
-
- def local_rel_plc (self):
- "run site-dependant release script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_release_plc(self)
-
- def local_rel_qemu (self):
- "run site-dependant release script as defined in LocalTestResources"
- from LocalTestResources import local_resources
- return local_resources.step_release_qemu(self)
-
+# def local_pre (self):
+# "run site-dependant pre-test script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_pre(self)
+#
+# def local_post (self):
+# "run site-dependant post-test script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_post(self)
+#
+# def local_list (self):
+# "run site-dependant list script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_list(self)
+#
+# def local_rel (self):
+# "run site-dependant release script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_release(self)
+#
+# def local_rel_plc (self):
+# "run site-dependant release script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_release_plc(self)
+#
+# def local_rel_qemu (self):
+# "run site-dependant release script as defined in LocalTestResources"
+# from LocalTestResources import local_resources
+# return local_resources.step_release_qemu(self)
+#
def vs_delete(self):
"vserver delete the test myplc"
self.run_in_host("vserver --silent %s delete"%self.vservername)
utils.header('Database restored from ' + dump)
+ def standby_1_through_20(self):
+ """convenience function to wait for a specified number of minutes"""
+ pass
@standby_generic
def standby_1(): pass
@standby_generic
--- /dev/null
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
+# Copyright (C) 2010 INRIA
+#
+# a macro for releasing all local resources and cleanup trackers
+
+"release local resources (stop vs, kill qemus, clean trackers)"
+
+# no trackers anymore
+sequence = [ 'vs_stop', 'qemu_kill_mine', ]
+
--- /dev/null
+sequence = [
+'sfa_plcclean',
+'sfa_dbclean',
+'sfa_import',
+'sfi_configure',
+'sfa_add_user',
+'sfa_add_slice',
+'sfa_discover',
+'sfa_create_slice',
+'sfa_check_slice_plc',
+'sfa_update_user',
+'sfa_update_slice',
+'sfa_view',
+'sfa_utest',
+'sfa_delete_slice',
+'sfa_delete_user',
+]
--- /dev/null
+sequence = [
+'sfa_plcclean',
+'sfa_dbclean',
+'sfa_stop',
+'sfi_clean',
+'sfa_configure',
+'sfa_import',
+'sfa_start',
+'sfi_configure',
+]
+++ /dev/null
-# Thierry Parmentelat <thierry.parmentelat@inria.fr>
-# Copyright (C) 2010 INRIA
-#
-# a macro for releasing all local resources and cleanup trackers
-
-"release local resources (stop vs, kill qemus, clean trackers)"
-
-from TestPlc import TestPlc
-
-def run01_vs_stop (test_plc):
- return test_plc.vs_stop()
-
-def run02_qemu_stop (test_plc):
- return test_plc.qemu_kill_mine()
-
-def run03_free_trackers (test_plc):
- return test_plc.local_rel()
+++ /dev/null
-# Thierry Parmentelat <thierry.parmentelat@inria.fr>
-# Copyright (C) 2010 INRIA
-#
-from TestPlc import TestPlc
-
-def run01_uninstall (test_plc):
- return test_plc.uninstall()
-def run02_install (test_plc):
- return test_plc.install()
-def run03_configure (test_plc):
- return test_plc.configure()
-def run04_dump_just_installed (test_plc):
- options.dbname='just-installed'
- return test_plc.plc_db_dump()
+++ /dev/null
-# Thierry Parmentelat <thierry.parmentelat@inria.fr>
-# Copyright (C) 2010 INRIA
-#
-from TestPlc import TestPlc
-
-def run01sfa_plcclean (test_plc): return test_plc.sfa_plcclean()
-def run02sfa_dbclean (test_plc): return test_plc.sfa_dbclean()
-def run03sfa_import (test_plc): return test_plc.sfa_import()
-def run04sfi_configure (test_plc): return test_plc.sfi_configure()
-def run05sfa_add_user (test_plc): return test_plc.sfa_add_user()
-def run06sfa_add_slice (test_plc): return test_plc.sfa_add_slice()
-def run07sfa_discover (test_plc): return test_plc.sfa_discover()
-def run08sfa_create_slice (test_plc): return test_plc.sfa_create_slice()
-def run09sfa_check_slice_plc (test_plc): return test_plc.sfa_check_slice_plc()
-def run10sfa_update_user (test_plc): return test_plc.sfa_update_user()
-def run11sfa_update_slice (test_plc): return test_plc.sfa_update_slice()
-def run12sfa_view (test_plc): return test_plc.sfa_view()
-def run13sfa_utest (test_plc): return test_plc.sfa_utest()
-def run14sfa_delete_slice (test_plc): return test_plc.sfa_delete_slice()
-def run15sfa_delete_user (test_plc): return test_plc.sfa_delete_user()
+++ /dev/null
-# Thierry Parmentelat <thierry.parmentelat@inria.fr>
-# Copyright (C) 2010 INRIA
-#
-from TestPlc import TestPlc
-
-def run01_pcleean (test_plc):
- return test_plc.sfa_plcclean()
-def run02_dclean (test_plc):
- return test_plc.sfa_dbclean()
-def run03_lclean (test_plc):
- return test_plc.logclean_sfa()
-def run04_stop (test_plc):
- return test_plc.sfa_stop()
-def run11_iclean (test_plc):
- return test_plc.sfi_clean()
-def run21_conf (test_plc):
- return test_plc.sfa_configure()
-def run22_import (test_plc):
- return test_plc.sfa_import()
-def run23_start (test_plc):
- return test_plc.sfa_start()
-def run31_iconf (test_plc):
- return test_plc.sfi_configure()