cleanup slice-fs-* steps, nicer output, and shows contents when it's wrong
[tests.git] / system / TestSlice.py
index 8082749..f5049d3 100644 (file)
@@ -8,11 +8,11 @@ import time
 
 from TestKey import TestKey
 from TestUser import TestUser
-from TestNode import TestNode
+from TestNode import TestNode, CompleterTaskNodeSsh
 from TestSsh import TestSsh
 from Completer import Completer, CompleterTask
 
-class CompleterTaskSshSlice (CompleterTask):
+class CompleterTaskSliceSsh (CompleterTask):
 
     def __init__ (self, test_plc, hostname, slicename, private_key,command, expected, dry_run):
         self.test_plc=test_plc
@@ -113,7 +113,7 @@ class TestSlice:
         hostnames=[]
         for nodename in self.slice_spec['nodenames']:
             node_spec=self.test_site.locate_node(nodename)
-            test_node=TestNode(self,self.test_site,node_spec)
+            test_node=TestNode(self.test_plc,self.test_site,node_spec)
             hostnames += [test_node.name()]
         utils.header("Adding %r in %s"%(hostnames,slice_name))
         self.test_plc.apiserver.AddSliceToNodes(auth, slice_name, hostnames)
@@ -143,23 +143,24 @@ class TestSlice:
             key_names += user_spec['key_names']
         return self.test_plc.locate_private_key_from_key_names (key_names)
 
-    # trying to reach the slice through ssh - expected to answer
-    def ssh_slice (self, options, *args, **kwds):
+    # for TestPlc.slice_mapper__tasks
+    # i.e. returns a list of CompleterTasks that are merged into the same Completer run
+    # to avoid waiting for as many slices as the Plc has
+    # also the __doc__ lines are used for the TestPlc methods, e.g. just 'ssh_slice'
+    def ssh_slice__tasks (self, options, *args, **kwds):
         "tries to ssh-enter the slice with the user key, to check for slice creation"
-        return self.do_ssh_slice(options, expected=True, *args, **kwds)
+        return self.ssh_tasks(options, expected=True, *args, **kwds)
 
     # when we expect the slice is not reachable
-    def ssh_slice_off (self, options, *args, **kwds):
+    def ssh_slice_off__tasks (self, options, *args, **kwds):
         "tries to ssh-enter the slice with the user key, expecting it to be unreachable"
-        return self.do_ssh_slice(options, expected=False, *args, **kwds)
+        return self.ssh_tasks(options, expected=False, *args, **kwds)
 
-    def do_ssh_slice(self,options,expected=True,
-                     timeout_minutes=20,silent_minutes=10,period_seconds=15,command=None):
-        "tries to enter a slice"
-
-        timeout  = timedelta(minutes=timeout_minutes)
-        graceout = timedelta(minutes=silent_minutes)
-        period   = timedelta(seconds=period_seconds)
+    def ssh_tasks(self,options, expected=True, command=None):
+#                     timeout_minutes=20,silent_minutes=10,period_seconds=15):
+#        timeout  = timedelta(minutes=timeout_minutes)
+#        graceout = timedelta(minutes=silent_minutes)
+#        period   = timedelta(seconds=period_seconds)
         if not command:
             command="echo hostname ; hostname; echo id; id; echo uname -a ; uname -a"
         # locate a key
@@ -178,9 +179,10 @@ class TestSlice:
         dry_run = getattr(options,'dry_run',False)
         for nodename in self.slice_spec['nodenames']:
             (site_spec,node_spec) = self.test_plc.locate_node(nodename)
-            tasks.append( CompleterTaskSshSlice(self.test_plc,node_spec['node_fields']['hostname'],
+            tasks.append( CompleterTaskSliceSsh(self.test_plc,node_spec['node_fields']['hostname'],
                                                 slicename,private_key,command,expected,dry_run))
-        return Completer (tasks).run (timeout, graceout, period)
+        return tasks
+#        return Completer (tasks).run (timeout, graceout, period)
 
     def ssh_slice_basics (self, options, *args, **kwds):
         "the slice is expected to be UP and we just check a few simple sanity commands, including 'ps' to check for /proc"
@@ -189,6 +191,7 @@ class TestSlice:
         if not self.do_ssh_slice_once(options,expected=False, command='false'): overall=False
         if not self.do_ssh_slice_once(options,expected=False, command='someimprobablecommandname'): overall=False
         if not self.do_ssh_slice_once(options,expected=True,  command='ps'): overall=False
+        if not self.do_ssh_slice_once(options,expected=False, command='ls /vservers'): overall=False
         return overall
 
     # pick just one nodename and runs the ssh command once
@@ -218,3 +221,29 @@ class TestSlice:
         else:           success = retcod!=0
         if not success: utils.header ("WRONG RESULT for %s"%msg)
         return success
+
+    # for TestPlc.slice_mapper__tasks
+    # check that /vservers/<> is present/deleted
+    def slice_fs_present__tasks (self, options): 
+        "checks that /vservers/<slicename> exists on the filesystem"
+        return self.check_rootfs_tasks(options,expected=True)
+    def slice_fs_deleted__tasks (self, options): 
+        "checks that /vservers/<slicename> has been properly wiped off"
+        return self.check_rootfs_tasks (options,expected=False)
+
+    def check_rootfs_tasks (self, options, expected):
+        # use constant admin key
+        local_key = "keys/key_admin.rsa"
+        node_infos = self.test_plc.all_node_infos()
+        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 ]