task-ified version of slice-fs-{present,deleted}
Thierry Parmentelat [Mon, 19 May 2014 09:48:00 +0000 (11:48 +0200)]
of course deleting the filesystem takes some time, and so checking for deletion right after we get ssh denied is not reliable, we need to give the node some time (2 mn) to complete this

system/TestNode.py
system/TestPlc.py
system/TestSlice.py
system/TestSliceSfa.py
system/utils.py

index 7134cc2..35db0fd 100644 (file)
@@ -7,6 +7,24 @@ import utils
 from TestUser import TestUser
 from TestBoxQemu import TestBoxQemu
 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):
+        self.hostname=hostname
+        self.qemuname=qemuname
+        self.boot_state=boot_state
+        self.local_key=local_key
+        self.command=command if command is not None else "hostname;uname -a"
+        self.expected=expected
+        self.dry_run = dry_run
+    def run (self, silent):
+        command = TestSsh (self.hostname,key=self.local_key).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)
 
 class TestNode:
 
index 0121c55..9bb5f36 100644 (file)
@@ -10,8 +10,9 @@ from datetime import datetime, timedelta
 from types import StringTypes
 
 import utils
+from Completer import Completer, CompleterTask
 from TestSite import TestSite
-from TestNode import TestNode
+from TestNode import TestNode, CompleterTaskNodeSsh
 from TestUser import TestUser
 from TestKey import TestKey
 from TestSlice import TestSlice
@@ -21,7 +22,6 @@ from TestSsh import TestSsh
 from TestApiserver import TestApiserver
 from TestAuthSfa import TestAuthSfa
 from PlcapiUrlScanner import PlcapiUrlScanner
-from Completer import Completer, CompleterTask
 
 has_sfa_cache_filename="sfa-cache"
 
@@ -1081,18 +1081,6 @@ class TestPlc:
         return self.check_nodes_ping ()
 
     def check_nodes_ssh(self,debug,timeout_minutes,silent_minutes,period_seconds=15):
-        class CompleterTaskNodeSsh (CompleterTask):
-            def __init__ (self, hostname, qemuname, boot_state, local_key):
-                self.hostname=hostname
-                self.qemuname=qemuname
-                self.boot_state=boot_state
-                self.local_key=local_key
-            def run (self, silent):
-                command = TestSsh (self.hostname,key=self.local_key).actual_command("hostname;uname -a")
-                return utils.system (command, silent=silent)==0
-            def failure_message (self):
-                return "Cannot reach %s @ %s in %s mode"%(self.hostname, self.qemuname, self.boot_state)
-
         # various delays 
         timeout  = timedelta(minutes=timeout_minutes)
         graceout = timedelta(minutes=silent_minutes)
@@ -1106,7 +1094,7 @@ class TestPlc:
            local_key = "keys/key_admin.rsa"
         utils.header("checking ssh access to nodes (expected in %s mode)"%message)
         node_infos = self.all_node_infos()
-        tasks = [ CompleterTaskNodeSsh (nodename, qemuname, message, local_key) \
+        tasks = [ CompleterTaskNodeSsh (nodename, qemuname, local_key, boot_state=message) \
                       for (nodename,qemuname) in node_infos ]
         return Completer (tasks).run (timeout, graceout, period)
         
@@ -1242,6 +1230,10 @@ 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)
+    def slice_fs_present(self): pass
+    @slice_mapper__tasks(2,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
     def ssh_slice_again(self): return self.ssh_slice()
@@ -1251,10 +1243,6 @@ class TestPlc:
     @slice_mapper
     def ssh_slice_basics(self): pass
     @slice_mapper
-    def slice_fs_present(self): pass
-    @slice_mapper
-    def slice_fs_deleted(self): pass
-    @slice_mapper
     def check_vsys_defaults(self): pass
 
     @node_mapper
index 0b61e7e..4b40bf0 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
@@ -143,7 +143,7 @@ class TestSlice:
             key_names += user_spec['key_names']
         return self.test_plc.locate_private_key_from_key_names (key_names)
 
-    # to be used through TestPlc.slice_mapper_tasks
+    # 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'
@@ -179,7 +179,7 @@ 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 tasks
 #        return Completer (tasks).run (timeout, graceout, period)
@@ -222,7 +222,23 @@ class TestSlice:
         if not success: utils.header ("WRONG RESULT for %s"%msg)
         return success
 
-    def check_rootfs (self, expected):
+    # 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()
+        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)
@@ -237,9 +253,3 @@ class TestSlice:
             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)
index 5de9f78..a652d3c 100644 (file)
@@ -12,7 +12,7 @@ from TestBoxQemu import TestBoxQemu
 from TestSsh import TestSsh
 
 from Completer import Completer, CompleterTask
-from TestSlice import CompleterTaskSshSlice
+from TestSlice import CompleterTaskSliceSsh
 
 class TestSliceSfa:
 
@@ -143,6 +143,6 @@ class TestSliceSfa:
         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=True,dry_run=dry_run))
         return Completer (tasks).run (timeout, graceout, period)
index fbdd3f6..5a869d1 100644 (file)
@@ -22,8 +22,9 @@ def pprint(message,spec,depth=2):
 
 
 
-def system(command,background=False,silent=False):
-    if getattr(options,'dry_run',None):
+def system(command,background=False,silent=False, dry_run=None):
+    dry_run = dry_run if dry_run is not None else getattr(options,'dry_run',False)
+    if dry_run:
         print 'dry_run:',command
         return 0