*No need anymore to check nodes from the TestSite class.
Marc Fiuczynski [Thu, 24 Jan 2008 19:21:16 +0000 (19:21 +0000)]
*Add new Methods to check correctly nodes status from  both TestPLc and  TestNode classes

system/TestNode.py
system/TestPlc.py
system/TestSite.py

index 248f6c9..7a3af8c 100644 (file)
@@ -60,6 +60,18 @@ class TestNode:
             auth=self.test_plc.auth_root()
         self.test_plc.server.DeleteNode(auth,self.name())
 
+    def get_node_status(self,hostname,host_machine):
+        filter=['boot_state']
+        status=False
+        node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),hostname, filter)
+        utils.header('Actual status for node %s is [%s]'%(hostname,node_status))
+        if (node_status[0]['boot_state'] == 'boot'):
+            utils.header('%s has reached boot state'%hostname)
+            status=True 
+        elif (node_status[0]['boot_state'] == 'dbg' ):
+            utils.header('%s has reached debug state'%hostname)
+        return status
+
     def conffile(self,image,hostname,path):
         model=self.node_spec['node_fields']['model']
         host_machine=self.node_spec['node_fields']['host_machine']    
index f586694..115d926 100644 (file)
@@ -1,5 +1,7 @@
 # $Id$
 import os, os.path
+import datetime
+import time
 import sys
 import xmlrpclib
 import datetime
@@ -301,6 +303,35 @@ class TestPlc:
                 self.server.AddNodeToNodeGroup(auth,node,nodegroupname)
         return True
 
+    def check_nodes(self,options):
+        status=True
+        start_time = datetime.datetime.now()
+        dead_time=datetime.datetime.now()+ datetime.timedelta(minutes=5)
+        booted_nodes=[]
+        for site_spec in self.plc_spec['sites']:
+            test_site = TestSite (self,site_spec)
+            utils.header("Starting checking for nodes in site %s"%self.name())
+            notfullybooted_nodes=[ node_spec['node_fields']['hostname'] for node_spec in site_spec['nodes'] ]
+            nbr_nodes= len(notfullybooted_nodes)
+            while (status):
+                for node_spec in site_spec['nodes']:
+                    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_machine=node_spec['node_fields']['host_machine']
+                        node_status=test_node.get_node_status(hostname,host_machine)
+                        if (node_status):
+                            booted_nodes.append(hostname)
+                            del notfullybooted_nodes[notfullybooted_nodes.index(hostname)]
+                if ( not notfullybooted_nodes): break
+                elif ( start_time  <= dead_time ) :
+                    start_time=datetime.datetime.now()+ datetime.timedelta(minutes=2)
+                    time.sleep(15)
+                else: status=False
+            for nodeup in booted_nodes : utils.header("Node %s correctly installed and booted"%node)
+            for nodedown  in notfullybooted_nodes : utils.header("Node %s not fully booted"%node)
+            return status
+    
     def bootcd (self, options):
         for site_spec in self.plc_spec['sites']:
             test_site = TestSite (self,site_spec)
index d01e349..f52a28e 100644 (file)
@@ -54,56 +54,6 @@ class TestSite:
                 return node
         raise Exception,"Cannot locate node %s"%nodename
         
-    # left as-is, i.e. crappy
-    def check_nodes(self):
-        # should filter out nodes not under vmware not qemu
-        node_specs=self.site_spec['nodes']
-        bool=True
-        try:
-            ret_value=True    
-            filter=['boot_state']
-            bt={'boot_state':'boot'}
-            dbg={'boot_state':'dbg'}
-            secondes=15
-            start_time = datetime.datetime.now() ##geting the current time
-            dead_time=datetime.datetime.now()+ datetime.timedelta(minutes=5)
-            utils.header("Starting checking for nodes in site %s"%self.name())
-            
-            for node_spec in node_specs :
-                hostname=node_spec['node_fields']['hostname']
-                while (bool):
-                    node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),hostname, filter)
-                    utils.header('Actual status for node %s is [%s]'%(hostname,node_status))
-                    try:
-                        if (node_status[0] == bt):
-                            utils.header('%s has reached boot state'%hostname)
-                            break 
-                        elif (node_status[0] ==dbg):
-                            utils.header('%s has reached debug state'%hostname)
-                            bool=False
-                            break 
-                        elif ( start_time  <= dead_time ) :
-                            start_time=datetime.datetime.now()+ datetime.timedelta(minutes=2)
-                            time.sleep(secondes)
-                        else: bool=False
-                    except OSError ,e :
-                        bool=False
-                        str(e)
-                if (bool):
-                    utils.header("Node %s correctly installed and booted"%hostname)
-                else :
-                    utils.header("Node %s not fully booted"%hostname)
-                    ret_value=False
-            
-            utils.header("End checking for nodes in site %s"%self.name())
-            return ret_value
-        except Exception, e:
-            traceback.print_exc()
-            utils.header("will kill vmware in 10 seconds")
-            time.sleep(5)
-            self.tst_plc.kill_all_vmwares()
-            raise 
-            
     def start_nodes (self,options):
         for node_spec in self.site_spec['nodes']:
             TestNode(self.test_plc, self, node_spec).start_node(options)