cleanup slice-fs-* steps, nicer output, and shows contents when it's wrong
Thierry Parmentelat [Wed, 21 May 2014 08:05:26 +0000 (10:05 +0200)]
next step is to unify failure_message and failure_epilogue

system/Completer.py
system/TestNode.py
system/TestPlc.py
system/TestSlice.py

index 0ebf6e6..155397e 100755 (executable)
@@ -32,6 +32,7 @@ class Completer:
             if datetime.now() > timeout:
                 for task in tasks: 
                     print task.failure_message()
+                    task.failure_epilogue()
                 return False
             if self.verbose:
                 print '%ds..'%period_seconds,
@@ -64,6 +65,7 @@ class CompleterTask:
         return result
     def message (self): return "you-need-to-redefine-message"
     def failure_message (self): return "you-need-to-redefine-failure_message"
+    def failure_epilogue (self): pass
 
 # random result
 class TaskTest (CompleterTask):
index dcab9dd..28b013a 100644 (file)
@@ -10,7 +10,7 @@ from TestSsh import TestSsh
 from Completer import CompleterTask
 
 class CompleterTaskNodeSsh (CompleterTask):
-    def __init__ (self, hostname, qemuname, local_key, command=None,boot_state="boot", expected=True, dry_run=False):
+    def __init__ (self, hostname, qemuname, local_key, command=None, message=None, boot_state="boot", expected=True, dry_run=False):
         self.hostname=hostname
         self.qemuname=qemuname
         self.boot_state=boot_state
@@ -18,13 +18,15 @@ class CompleterTaskNodeSsh (CompleterTask):
         self.command=command if command is not None else "hostname;uname -a"
         self.expected=expected
         self.dry_run = dry_run
+        self.message = message if message else "cannot reach %s in %s mode"%(self.hostname, self.boot_state)
+        self.test_ssh =  TestSsh (self.hostname,key=self.local_key)
     def run (self, silent):
-        command = TestSsh (self.hostname,key=self.local_key).actual_command(self.command)
+        command = self.test_ssh.actual_command(self.command)
         retcod=utils.system (command, silent=silent, dry_run=self.dry_run)
         if self.expected:       return retcod==0
         else:                   return retcod !=0
     def failure_message (self):
-        return "Cannot reach %s @ %s in %s mode"%(self.hostname, self.qemuname, self.boot_state)
+        return self.message
 
 class TestNode:
 
index 16ae3eb..d0d04d2 100644 (file)
@@ -1213,9 +1213,9 @@ class TestPlc:
     def ssh_slice(self): pass
     @slice_mapper__tasks(20,19,15)
     def ssh_slice_off (self): pass
-    @slice_mapper__tasks(2,1,15)
+    @slice_mapper__tasks(1,1,15)
     def slice_fs_present(self): pass
-    @slice_mapper__tasks(2,1,15)
+    @slice_mapper__tasks(1,1,15)
     def slice_fs_deleted(self): pass
 
     # use another name so we can exclude/ignore it from the tests on the nightly command line
index 4b40bf0..f5049d3 100644 (file)
@@ -235,21 +235,15 @@ class TestSlice:
         # use constant admin key
         local_key = "keys/key_admin.rsa"
         node_infos = self.test_plc.all_node_infos()
-        return [ CompleterTaskNodeSsh (nodename, qemuname, local_key, expected=expected,
-                                       command="ls -d /vservers/%s"%self.name()) \
-                 for (nodename,qemuname) in node_infos ]
-        
-        overall=True
-        for nodename in self.slice_spec['nodenames']:
-            node_spec=self.test_site.locate_node(nodename)
-            test_node=TestNode(self.test_plc,self.test_site,node_spec)
-            test_node_ssh=test_node.create_test_ssh()
-            command="ls /vservers/%s"%self.name()
-            full_command = test_node_ssh.actual_command(command)
-            retcod=utils.system(full_command,silent=True)
-            # we expect the fs to be present, retcod should be 0
-            if expected:        fine=(retcod==0)
-            else:               fine=(retcod!=0)
-            if not fine: overall=False
-        return overall
-
+        rootfs="/vservers/%s"%self.name()
+        if expected:
+            failure_message = "Could not stat %s"%rootfs
+        else:
+            failure_message = "Sliver rootfs still present in %s"%rootfs
+        class CompleterTaskRootfs (CompleterTaskNodeSsh):
+            def __init__ (self, nodename, qemuname):
+                CompleterTaskNodeSsh.__init__(self,nodename, qemuname, local_key, expected=expected,
+                                              message=failure_message, command="ls -d %s"%rootfs)
+            def failure_epilogue (self):
+                utils.system(self.test_ssh.actual_command("ls -l %s; du -hs %s"%(rootfs,rootfs),dry_run=self.dry_run))
+        return [ CompleterTaskRootfs (nodename, qemuname) for (nodename,qemuname) in node_infos ]