some cleanup - fix ssh+chroot commands
Thierry Parmentelat [Mon, 4 Feb 2008 13:53:53 +0000 (13:53 +0000)]
system/TestNode.py
system/TestPlc.py
system/TestSlice.py
system/config_onelab.py
system/config_onelab_qemu.py

index d95962b..6ce35f7 100644 (file)
@@ -14,6 +14,20 @@ class TestNode:
     def name(self):
         return self.node_spec['node_fields']['hostname']
         
+    def is_vmware (self):
+        model=self.node_spec['node_fields']['model']
+        return model.find("vmware") >= 0
+
+    def is_qemu (self):
+        model=self.node_spec['node_fields']['model']
+        return model.find("qemu") >= 0
+
+    def host_box (self):
+        try:
+            return self.node_spec['host_box']
+        except:
+            return 'localhost'
+
     def create_node (self):
         ownername = self.node_spec['owner']
         user_spec = self.test_site.locate_user(ownername)
@@ -60,7 +74,7 @@ class TestNode:
             auth=self.test_plc.auth_root()
         self.test_plc.server.DeleteNode(auth,self.name())
 
-    def get_node_status(self,hostname,host_box):
+    def get_node_status(self,hostname):
         filter=['boot_state']
         status=False
         node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),hostname, filter)
@@ -74,15 +88,15 @@ class TestNode:
 
     def conffile(self,image,hostname,path):
         model=self.node_spec['node_fields']['model']
-        if model.find("vmware") >= 0:
-            host_box=self.node_spec['node_fields']['host_box']    
+        if self.is_vmware():
+            host_box=self.host_box()
             template='%s/template-vmplayer/node.vmx'%(path)
             actual='%s/vmplayer-%s/node.vmx'%(path,hostname)
             sed_command="sed -e s,@BOOTCD@,%s,g %s > %s"%(image,template,actual)
             utils.header('Creating %s from %s'%(actual,template))
             utils.system(sed_command)
-        elif  model.find("qemu") >= 0:
-            host_box=self.node_spec['node_fields']['host_box']    
+        elif self.is_qemu():
+            host_box=self.host_box()
             mac=self.node_spec['network_fields']['mac']
             dest_dir="qemu-%s"%(hostname)
             utils.header('Storing the mac address for node %s'%hostname)
@@ -90,7 +104,7 @@ class TestNode:
             file.write('%s\n'%mac)
             file.write(dest_dir)
             file.close()
-            utils.header ('Transfert of configuration files for node %s into %s '%(hostname,host_box))
+            utils.header ('Transferring configuration files for node %s into %s '%(hostname,host_box))
             cleandir_command="ssh root@%s rm -rf %s"%(host_box, dest_dir)
             createdir_command = "ssh root@%s mkdir -p  %s"%(host_box, dest_dir)
             utils.system(cleandir_command)
@@ -153,7 +167,7 @@ class TestNode:
         utils.system('cd %s/vmplayer-%s ; DISPLAY=%s vmplayer node.vmx < /dev/null >/dev/null 2>/dev/null &'%(path,hostname,display))
         
     def start_qemu (self, options):
-        host_box=self.node_spec['node_fields']['host_box']
+        host_box=self.host_box()
         hostname=self.node_spec['node_fields']['hostname']
         path=options.path
         display=options.display
@@ -162,7 +176,13 @@ class TestNode:
         utils.system("ssh root@%s ~/%s/env-qemu start "%(host_box, dest_dir ))
         utils.system("ssh  root@%s DISPLAY=%s  ~/%s/start-qemu-node %s & "%( host_box, display, dest_dir, dest_dir))
         
-    def stop_qemu(self,host_box, hostname):
+    def stop_qemu(self):
+        if not self.is_qemu():
+            return True
+        hostname=self.node_spec['node_fields']['hostname']
+        host_box=self.host_box()
+        utils.system('ssh root@%s  killall qemu'%host_box)
         utils.header('Stoping qemu emulation of %s on the host machine %s and Restoring the initial network'
                      %(hostname,host_box))
         utils.system("ssh root@%s ~/qemu-%s/env-qemu stop "%(host_box, hostname ))
+        return True
index 7d48f4c..183d013 100644 (file)
@@ -53,7 +53,7 @@ class TestPlc:
         if self.vserver:
             return "vserver %s exec %s"%(self.vservername,command)
         else:
-            return "chroot /plc/root %s"%command
+            return "chroot /plc/root sh -c \\\"%s\\\""%command
 
     def ssh_command(self,command):
         if self.is_local():
@@ -104,15 +104,16 @@ class TestPlc:
         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)
-                model=node_spec['node_fields']['model']
-                host_box=node_spec['node_fields']['host_box']
-                hostname=node_spec['node_fields']['hostname']
-                print model
-                if model.find("qemu") >= 0:
-                    utils.system('ssh root@%s  killall qemu'%host_box)
-                    test_node.stop_qemu(host_box,hostname)
+                TestNode (self,test_site,node_spec).stop_qemu()
                     
+    def clear_ssh_config (self):
+        # using ssh -o "BatchMode yes" is too tricky due to quoting - let's use the config
+        utils.header("Setting BatchMode and StrictHostKeyChecking in ssh config")
+        self.run_in_guest("sed -i -e '/BatchMode/d' /root/.ssh/config 2> /dev/null")
+        self.run_in_guest_piped("echo BatchMode yes", "cat >> /root/.ssh/config")
+        self.run_in_guest("sed -i -e '/StrictHostKeyChecking/d' /root/.ssh/config 2> /dev/null")
+        self.run_in_guest_piped("echo StrictHostKeyChecking no", "cat >> /root/.ssh/config")
+            
     #################### step methods
 
     ### uninstall
@@ -327,8 +328,8 @@ class TestPlc:
                     hostname=node_spec['node_fields']['hostname']
                     if (hostname in notfullybooted_nodes): #to avoid requesting already booted node
                         test_node=TestNode (self,test_site,node_spec)
-                        host_box=node_spec['node_fields']['host_box']
-                        node_status=test_node.get_node_status(hostname,host_box)
+                        host_box=test_node.host_box()
+                        node_status=test_node.get_node_status(hostname)
                         if (node_status):
                             booted_nodes.append(hostname)
                             del notfullybooted_nodes[notfullybooted_nodes.index(hostname)]
index 5e8f3b9..762758f 100644 (file)
@@ -14,6 +14,9 @@ class TestSlice:
         self.test_site=test_site
        self.slice_spec=slice_spec
 
+    def name(self):
+        return self.slice_spec['slice_fields']['name']
+
     def delete_slice(self):
         owner_spec = self.test_site.locate_user(self.slice_spec['owner'])
         auth = TestUser(self,self.test_site,owner_spec).auth()
@@ -46,22 +49,25 @@ class TestSlice:
             isname=self.slice_spec['initscriptname']
             utils.header("Adding initscript %s in %s"%(isname,slice_name))
             self.test_plc.server.AddSliceAttribute(self.test_plc.auth_root(), slice_name,'initscript',isname)
-            
-        
-    def delete_known_hosts(self):
-        utils.header("Messing with known_hosts (cleaning hostnames starting with 'test[0-9]')")
-        sed_command="sed -i -e '/^test[0-9]/d' /root/.ssh/known_hosts"
-        self.test_plc.run_in_guest(sed_command)
         
+    def clear_known_hosts (self):
+        utils.header("Messing with known_hosts for slice %s"%self.name())
+        # scan nodenames
+        for nodename in self.slice_spec['nodenames']:
+            self.test_plc.run_in_guest("sed -i -e '/^%s/d' /root/.ssh/known_hosts"%nodename)
+
     ###the logic is quit wrong, must be rewritten
     def do_check_slices(self):
-        utils.header("waiting for the nodes to fully boot")
-        time.sleep(300)
+        # Do not wait here, as this step can be run directly in which case you don't want to wait
+        # just add the 5 minutes to the overall timeout
+        #utils.header("Waiting for the nodes to fully boot")
+        #time.sleep(300)
         bool=bool1=True
         secondes=15
-        self.delete_known_hosts()
+        self.test_plc.clear_ssh_config()
+        self.clear_known_hosts()
         start_time = datetime.datetime.now()
-        dead_time=start_time + datetime.timedelta(minutes=6)
+        dead_time=start_time + datetime.timedelta(minutes=11)
         for slice_spec in self.test_plc.plc_spec['slices']:
             for hostname in slice_spec['nodenames']:
                 slicename=slice_spec['slice_fields']['name']
index bf32fc2..a812572 100644 (file)
@@ -8,10 +8,11 @@
 onelab="one-lab.org"
 
 # use a model that contains "vmware" to get the node actually started
+# host_box is taken as 'localhost' if omitted (should be a direct field in the node spec)
 def nodes():
     nodes= [ {'node_fields': {'hostname': 'test1.one-lab.org',
-                              'model':'vmware/minhw',
-                              'host_box' : 'localhost'},
+                              'model':'vmware/minhw', },
+              'host_box' : 'test.one-lab.org',
               'owner' : 'pi',
               'network_fields': { 'method':'static',
                                   'type':'ipv4',
@@ -24,8 +25,8 @@ def nodes():
                                   },
               },
              { 'node_fields': {'hostname':'test2.one-lab.org',
-                               'model':'vmware/minhw',
-                               'host_box': 'localhost'},
+                               'model':'vmware/minhw', } ,
+               'host_box' : 'test.one-lab.org',
                'owner' : 'tech',
                'network_fields': {'method':'static',
                                   'type':'ipv4',
index 1f2039d..687c7ee 100644 (file)
@@ -10,8 +10,8 @@ onelab="one-lab.org"
 # we use only thw Qemu node for this config
 def nodes():
     nodes= [ {'node_fields': {'hostname': 'lysithea.inria.fr',
-                              'model':'qemu/minhw',
-                              'host_box': 'bellami.inria.fr'},
+                              'model':'qemu/minhw', } ,
+              'host_box': 'bellami.inria.fr',
               'owner' : 'pi',
               'network_fields': { 'method':'static',
                                   'type':'ipv4',