separate step for stopping all vservers
[tests.git] / system / TestPlc.py
index cb3a11b..d76aff3 100644 (file)
@@ -14,6 +14,7 @@ from TestNode import TestNode
 from TestUser import TestUser
 from TestKey import TestKey
 from TestSlice import TestSlice
+from TestSliver import TestSliver
 from TestBox import TestBox
 
 # step methods must take (self, options) and return a boolean
@@ -52,8 +53,11 @@ class TestPlc:
         else:
             return name+"[chroot]"
 
+    def hostname(self):
+        return self.plc_spec['hostname']
+
     def is_local (self):
-        return self.plc_spec['hostname'] == 'localhost'
+        return utils.is_local(self.hostname())
 
     # define the API methods on this object through xmlrpc
     # would help, but not strictly necessary
@@ -72,7 +76,7 @@ class TestPlc:
         if self.is_local():
             return command
         else:
-            return "ssh %s %s"%(self.plc_spec['hostname'],utils.backslash_shell_specials(command))
+            return "ssh %s %s"%(self.hostname(),utils.backslash_shell_specials(command))
 
     def full_command(self,command):
         return self.to_host(self.host_to_guest(command))
@@ -99,9 +103,9 @@ class TestPlc:
                 utils.system("cp %s /vservers/%s/%s"%(localfile,self.vservername,remotefile))
         else:
             if not self.vserver:
-                utils.system("scp %s %s:%s/%s"%(localfile,self.plc_spec['hostname'],chroot_dest,remotefile))
+                utils.system("scp %s %s:%s/%s"%(localfile,self.hostname(),chroot_dest,remotefile))
             else:
-                utils.system("scp %s %s@/vservers/%s/%s"%(localfile,self.plc_spec['hostname'],self.vservername,remotefile))
+                utils.system("scp %s %s@/vservers/%s/%s"%(localfile,self.hostname(),self.vservername,remotefile))
 
     def auth_root (self):
        return {'Username':self.plc_spec['PLC_ROOT_USER'],
@@ -160,12 +164,23 @@ class TestPlc:
     def kill_all_qemus(self,options):
         for (box,nodes) in self.gather_hostBoxes().iteritems():
             # this is the brute force version, kill all qemus on that host box
-            TestBox(box).kill_all_qemus()
+            TestBox(box,options.buildname).kill_all_qemus()
+        return True
+
+    # make this a valid step
+    def list_all_qemus(self,options):
+        for (box,nodes) in self.gather_hostBoxes().iteritems():
+           # push the script
+           TestBox(box,options.buildname).copy("qemu_kill.sh") 
+            # this is the brute force version, kill all qemus on that host box
+            TestBox(box,options.buildname).run_in_buildname("qemu_kill.sh -l")
         return True
 
     # kill only the right qemus
     def kill_qemus(self,options):
         for (box,nodes) in self.gather_hostBoxes().iteritems():
+           # push the script
+           TestBox(box,options.buildname).copy("qemu_kill.sh") 
             # the fine-grain version
             for node in nodes:
                 node.kill_qemu()
@@ -190,14 +205,17 @@ class TestPlc:
         self.run_in_host('rpm -e myplc')
         ##### Clean up the /plc directory
         self.run_in_host('rm -rf  /plc/data')
-        ##### stop any running vservers
-        self.run_in_host('for vserver in $(ls /vservers/* | sed -e s,/vservers/,,) ; do vserver $vserver stop ; done')
         return True
 
     def uninstall_vserver(self,options):
         self.run_in_host("vserver --silent %s delete"%self.vservername)
         return True
 
+    def stop_all_vservers (self,options):
+        ##### stop any running vservers
+        self.run_in_host('for vserver in $(ls /vservers/* | sed -e s,/vservers/,,) ; do vserver $vserver stop ; done')
+       return True
+
     def uninstall(self,options):
         # if there's a chroot-based myplc running, and then a native-based myplc is being deployed
         # it sounds safer to have the former uninstalled too
@@ -207,6 +225,7 @@ class TestPlc:
             self.uninstall_chroot(options)
         else:
             self.uninstall_chroot(options)
+           self.stop_all_vservers(options)
         return True
 
     ### install
@@ -242,12 +261,23 @@ class TestPlc:
             return self.install_vserver(options)
         else:
             return self.install_chroot(options)
-
+    
     ### install_rpm
+    def cache_rpm(self,url):
+        self.run_in_host('rm -rf *.rpm')
+       utils.header('Curling rpm from %s'%url)
+       id= self.run_in_host('curl -O '+url)
+       if (id != 0):
+               raise Exception,"Could not get rpm from  %s"%url
+               return False
+       return True
+
     def install_rpm_chroot(self,options):
-        utils.header('Installing from %s'%options.myplc_url)
-        url=options.myplc_url
-        self.run_in_host('rpm -Uvh '+url)
+        rpm = os.path.basename(options.myplc_url)
+       if (not os.path.isfile(rpm)):
+               self.cache_rpm(options.myplc_url)
+       utils.header('Installing the :  %s'%rpm)
+        self.run_in_host('rpm -Uvh '+rpm)
         self.run_in_host('service plc mount')
         return True
 
@@ -263,7 +293,7 @@ class TestPlc:
 
     ### 
     def configure(self,options):
-        tmpname='%s/%s.plc-config-tty'%(options.path,self.name())
+        tmpname='%s.plc-config-tty'%(self.name())
         fileconf=open(tmpname,'w')
         for var in [ 'PLC_NAME',
                      'PLC_ROOT_PASSWORD',
@@ -347,7 +377,7 @@ class TestPlc:
             else:
                 utils.header("Creating nodes for site %s in %s"%(test_site.name(),self.name()))
                 for node_spec in site_spec['nodes']:
-                    utils.show_spec('Creating node %s'%node_spec,node_spec)
+                    utils.pprint('Creating node %s'%node_spec,node_spec)
                     test_node = TestNode (self,test_site,node_spec)
                     test_node.create_node ()
         return True
@@ -451,7 +481,6 @@ class TestPlc:
     def do_check_nodesSsh(self,minutes):
         # compute timeout
         timeout = datetime.datetime.now()+datetime.timedelta(minutes=minutes)
-        #graceout = datetime.datetime.now()+datetime.timedelta(minutes=gracetime)
         tocheck = self.all_hostnames()
         self.scan_publicKeys(tocheck)
         utils.header("checking Connectivity on nodes %r"%tocheck)
@@ -467,8 +496,8 @@ class TestPlc:
                     (site_spec,node_spec)=self.locate_node(hostname)
                     if TestNode.is_real_model(node_spec['node_fields']['model']):
                         utils.header ("WARNING : check ssh access into real node %s - skipped"%hostname)
-                    tocheck.remove(hostname)
-            if not tocheck:
+                       tocheck.remove(hostname)
+            if  not tocheck:
                 return True
             if datetime.datetime.now() > timeout:
                 for hostname in tocheck:
@@ -481,18 +510,35 @@ class TestPlc:
         
     def nodes_ssh(self, options):
         return  self.do_check_nodesSsh(minutes=2)
-            
+    
     def bootcd (self, options):
         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)
-                test_node.create_boot_cd(options.path)
+                test_node.prepare_area()
+                test_node.create_boot_cd()
+               test_node.configure_qemu()
         return True
-                
+
+    def do_check_intiscripts(self):
+       for site_spec in self.plc_spec['sites']:
+               test_site = TestSite (self,site_spec)
+               test_node = TestNode (self,test_site,site_spec['nodes'])
+               for slice_spec in self.plc_spec['slices']:
+                       test_slice=TestSlice (self,test_site,slice_spec)
+                       test_sliver=TestSliver(self,test_node,test_slice)
+                       init_status=test_sliver.get_initscript(slice_spec)
+                       if (not init_status):
+                               return False
+               return init_status
+           
+    def check_initscripts(self, options):
+           return self.do_check_intiscripts()
+                   
     def initscripts (self, options):
         for initscript in self.plc_spec['initscripts']:
-            utils.show_spec('Adding Initscript in plc %s'%self.plc_spec['name'],initscript)
+            utils.pprint('Adding Initscript in plc %s'%self.plc_spec['name'],initscript)
             self.server.AddInitScript(self.auth_root(),initscript['initscript_fields'])
         return True
 
@@ -511,7 +557,7 @@ class TestPlc:
                 utils.header("Deleting slices in site %s"%test_site.name())
                 test_slice.delete_slice()
             else:    
-                utils.show_spec("Creating slice",slice)
+                utils.pprint("Creating slice",slice)
                 test_slice.create_slice()
                 utils.header('Created Slice %s'%slice['slice_fields']['name'])
         return True
@@ -533,12 +579,17 @@ class TestPlc:
         return True
 
     def stop_nodes (self, options):
-        self.kill_all_qemus()
+        self.kill_all_qemus(options)
         return True
 
     def check_tcp (self, options):
-        print 'check_tcp not yet implemented'
-        return True
+           #we just need to create a sliver object nothing else
+           test_sliver=TestSliver(self,
+                                  TestNode(self, TestSite(self,self.plc_spec['sites'][0]),
+                                           self.plc_spec['sites'][0]['nodes'][0]),
+                                  TestSlice(self,TestSite(self,self.plc_spec['sites'][0]),
+                                            self.plc_spec['slices']))
+           return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options)
 
     # returns the filename to use for sql dump/restore, using options.dbname if set
     def dbfile (self, database, options):