new steps slice-fs-present and slice-fs-deleted - call slice-fs-deleted before re...
[tests.git] / system / TestSlice.py
index 25912cc..0b61e7e 100644 (file)
@@ -30,8 +30,11 @@ class CompleterTaskSshSlice (CompleterTask):
         if self.dry_run: return True
         if self.expected:       return retcod==0
         else:                   return retcod!=0
-    def failure_message (self): 
-        return "Could not ssh into slice %s @ %s"%(self.slicename,self.hostname)
+    def failure_message (self):
+        if self.expected:
+            return "Could not ssh into sliver %s@%s"%(self.slicename,self.hostname)
+        else:
+            return "Could still ssh into sliver%s@%s (that was expected to be down)"%(self.slicename,self.hostname)
 
 class TestSlice:
 
@@ -76,10 +79,16 @@ class TestSlice:
             isname=self.slice_spec['initscriptname']
             utils.header("Adding initscript name %s in %s"%(isname,slice_name))
             self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'initscript',isname)
-        if self.slice_spec.has_key ('vref'):
-            vref_value=self.slice_spec['vref']
-            self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'vref',vref_value)
-
+        if 'omf-friendly' in self.slice_spec:
+            utils.header("Making slice %s OMF-friendly"%slice_name)
+            self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'vref','omf')
+            self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'omf_control','yes')
+# setting vref directly like this was useful for multi-arch tests long ago - see wifilab
+# however this should rather use other tags by now, so we drop this for now
+#        if self.slice_spec.has_key ('vref'):
+#            vref_value=self.slice_spec['vref']
+#            self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'vref',vref_value)
+        # epilogue
         self.add_nodes()
 
     def check_vsys_defaults (self, options, *args, **kwds):
@@ -104,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)
@@ -134,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):
-        "tries to ssh-enter the slice with the user key, to ensure slice creation"
-        return self.do_ssh_slice(options, expected=True, *args, **kwds)
+    # to be used through 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.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)
-
-    def do_ssh_slice(self,options,expected=True,
-                     timeout_minutes=20,silent_minutes=10,period_seconds=15,command=None):
-        "tries to enter a slice"
+        return self.ssh_tasks(options, expected=False, *args, **kwds)
 
-        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
@@ -171,7 +181,8 @@ class TestSlice:
             (site_spec,node_spec) = self.test_plc.locate_node(nodename)
             tasks.append( CompleterTaskSshSlice(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"
@@ -180,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
@@ -209,3 +221,25 @@ class TestSlice:
         else:           success = retcod!=0
         if not success: utils.header ("WRONG RESULT for %s"%msg)
         return success
+
+    def check_rootfs (self, expected):
+        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
+
+    def slice_fs_present (self, options): 
+        "check that /vservers/<slicename> can be found"
+        return self.check_rootfs (expected=True)
+    def slice_fs_deleted (self, options): 
+        "check that /vservers/<slicename> has been properly wiped off on all nodes"
+        return self.check_rootfs (expected=False)