- 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_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)]
- 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"%nodeup)
- for nodedown in notfullybooted_nodes : utils.header("Node %s not fully booted"%nodedown)
- return status
-
+ hostnames += [ node_spec['node_fields']['hostname'] \
+ for node_spec in site_spec['nodes'] ]
+ return hostnames
+
+ # gracetime : during the first <gracetime> minutes nothing gets printed
+ def do_check_nodes (self, minutes, gracetime=2):
+
+ # compute timeout
+ timeout = datetime.datetime.now()+datetime.timedelta(minutes=minutes)
+ graceout = datetime.datetime.now()+datetime.timedelta(minutes=gracetime)
+
+ # the nodes that haven't checked yet - start with a full list and shrink over time
+ tocheck = self.all_hostnames()
+ utils.header("checking nodes %r"%tocheck)
+ # create a dict hostname -> status
+ status = dict ( [ (hostname,'undef') for hostname in tocheck ] )
+
+ while tocheck:
+ # get their status
+ tocheck_status=self.server.GetNodes(self.auth_root(), tocheck, ['hostname','boot_state' ] )
+ # update status
+ for array in tocheck_status:
+ hostname=array['hostname']
+ boot_state=array['boot_state']
+ if boot_state == 'boot':
+ utils.header ("%s has reached the 'boot' state"%hostname)
+ else:
+ if datetime.datetime.now() > graceout:
+ utils.header ("%s still in '%s' state"%(hostname,boot_state))
+ status[hostname] = boot_state
+ # refresh tocheck
+ tocheck = [ hostname for (hostname,boot_state) in status.iteritems() if boot_state != 'boot' ]
+
+ if not tocheck:
+ return True
+ if datetime.datetime.now() > timeout:
+ for hostname in tocheck:
+ utils.header("FAILURE due to %s in '%s' state"%(hostname,status[hostname]))
+ return False
+ # otherwise, sleep for a while
+ time.sleep(15)
+ # only useful in empty plcs
+ return True
+
+ def check_nodes(self,options):
+ return self.do_check_nodes(minutes=5)
+