clears known_hosts for test nodes
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 7 Apr 2008 08:52:17 +0000 (08:52 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 7 Apr 2008 08:52:17 +0000 (08:52 +0000)
system/TestMain.py
system/TestNode.py
system/TestPlc.py
system/TestSlice.py
system/TestSsh.py

index 9450c19..4e9b1fb 100755 (executable)
@@ -20,7 +20,7 @@ class TestMain:
 
     default_steps = ['uninstall','install','install_rpm', 
                      'configure', 'start', SEP,
-                     'store_keys', 'initscripts', 
+                     'store_keys', 'clear_known_hosts', 'initscripts', SEP,
                      'sites', 'nodes', 'slices', 'nodegroups', SEP,
                      'init_node','bootcd', 'configure_qemu', SEP,
                      'kill_all_qemus', 'start_nodes', SEP,
index 2c94b78..6ac9316 100644 (file)
@@ -4,6 +4,7 @@ import xmlrpclib
 import utils
 from TestUser import TestUser
 from TestBox import TestBox
+from TestSsh import TestSsh
 
 class TestNode:
 
@@ -189,3 +190,7 @@ class TestNode:
         remote_log="%s/qemu.log"%self.nodedir()
         local_log="logs/%s-qemu.log"%self.name()
         self.test_box().test_ssh.fetch(remote_log,local_log)
+
+    def clear_known_hosts (self):
+        TestSsh(self.name()).clear_known_hosts()
+        return True
index fb259f5..112b993 100644 (file)
@@ -37,15 +37,27 @@ def standby_generic (func):
 def node_mapper (method):
     def actual(self):
         overall=True
+        node_method = TestNode.__dict__[method.__name__]
         for site_spec in self.plc_spec['sites']:
             test_site = TestSite (self,site_spec)
             for node_spec in site_spec['nodes']:
                 test_node = TestNode (self,test_site,node_spec)
-                node_method = TestNode.__dict__[method.__name__]
                 if not node_method(test_node): overall=False
         return overall
     return actual
 
+def slice_mapper_options (method):
+    def actual(self):
+        overall=True
+        slice_method = TestSlice.__dict__[method.__name__]
+        for slice_spec in self.plc_spec['slices']:
+            site_spec = self.locate_site (slice_spec['sitename'])
+            test_site = TestSite(self,site_spec)
+            test_slice=TestSlice(self,test_site,slice_spec)
+            if not slice_method(test_slice,self.options): overall=False
+        return overall
+    return actual
+
 class TestPlc:
 
     def __init__ (self,plc_spec,options):
@@ -561,15 +573,11 @@ class TestPlc:
                 utils.header('Created Slice %s'%slice['slice_fields']['name'])
         return True
         
-    def check_slices(self):
-        for slice_spec in self.plc_spec['slices']:
-            site_spec = self.locate_site (slice_spec['sitename'])
-            test_site = TestSite(self,site_spec)
-            test_slice=TestSlice(self,test_site,slice_spec)
-            status=test_slice.do_check_slice(self.options)
-            if (not status):
-                return False
-        return status
+    @slice_mapper_options
+    def check_slice(self): pass
+
+    @node_mapper
+    def clear_known_hosts (self): pass
     
     def start_nodes (self):
         utils.header("Starting  nodes")
@@ -577,7 +585,6 @@ class TestPlc:
             TestSite(self,site_spec).start_nodes (self.options)
         return True
 
-
     def locate_first_sliver (self):
         slice_spec = self.plc_spec['slices'][0]
         slicename = slice_spec['slice_fields']['name']
index dc822cc..a71dbd7 100644 (file)
@@ -57,17 +57,6 @@ class TestSlice:
             utils.header("Adding initscript %s in %s"%(isname,slice_name))
             self.test_plc.apiserver.AddSliceAttribute(self.test_plc.auth_root(), slice_name,'initscript',isname)
         
-#    def clear_known_hosts (self):
-#        utils.header("Messing with known_hosts for slice %s"%self.name())
-#        hostnames=[]
-#        # scan nodenames
-#        for nodename in self.slice_spec['nodenames']:
-#            (site_spec,node_spec) = self.test_plc.locate_node(nodename)
-#            hostnames.append(node_spec['node_fields']['hostname'])
-#            self.test_plc.run_in_guest("sed -i -e /^%s/d /root/.ssh/known_hosts"%node_spec['node_fields']['hostname'])
-#        #scan public key and update the known_host file in the root image
-#        self.test_plc.scan_publicKeys(hostnames)
-        
     def locate_key(self):
         # locate the first avail. key
         found=False
@@ -83,8 +72,7 @@ class TestSlice:
                     found=True
         return (found,privatekey)
 
-    def do_check_slice(self,options,minutes=3):
-#        self.clear_known_hosts()
+    def check_slice(self,options,minutes=3):
         timeout = datetime.datetime.now()+datetime.timedelta(minutes=minutes)
 
         # locate a key
index 81956b0..3c61a4b 100644 (file)
@@ -140,3 +140,13 @@ class TestSsh:
             command += self.key_part()
             command += "%s:%s/%s %s"%(self.hostname_part(),self.buildname,remote_file,local_file)
         utils.system(command)
+
+    # this is only to avoid harmless message when host cannot be identified
+    # convenience only
+    # the only place where this is needed is when tring to reach a slice in a node,
+    # which is done from the test master box
+    def clear_known_hosts (self):
+        known_hosts = "%s/.ssh/known_hosts"%os.getenv("HOME")
+        utils.header("Clearing entry for %s in %s"%(self.hostname,known_hosts))
+        utils.system("sed -i -e /^%s/d %s"%(self.hostname,known_hosts))
+