+ if action == "add":
+ print 'nodegroups:','dealing with nodegroup',nodegroupname,'on nodes',group_nodes
+ # first, check if the nodetagtype is here
+ tag_types = self.apiserver.GetTagTypes(auth,{'tagname':nodegroupname})
+ if tag_types:
+ tag_type_id = tag_types[0]['tag_type_id']
+ else:
+ tag_type_id = self.apiserver.AddTagType(auth,
+ {'tagname':nodegroupname,
+ 'description': 'for nodegroup %s'%nodegroupname,
+ 'category':'test',
+ 'min_role_id':10})
+ print 'located tag (type)',nodegroupname,'as',tag_type_id
+ # create nodegroup
+ nodegroups = self.apiserver.GetNodeGroups (auth, {'groupname':nodegroupname})
+ if not nodegroups:
+ self.apiserver.AddNodeGroup(auth, nodegroupname, tag_type_id, 'yes')
+ print 'created nodegroup',nodegroupname,'from tagname',nodegroupname,'and value','yes'
+ # set node tag on all nodes, value='yes'
+ for nodename in group_nodes:
+ try:
+ self.apiserver.AddNodeTag(auth, nodename, nodegroupname, "yes")
+ except:
+ traceback.print_exc()
+ print 'node',nodename,'seems to already have tag',nodegroupname
+ # check anyway
+ try:
+ expect_yes = self.apiserver.GetNodeTags(auth,
+ {'hostname':nodename,
+ 'tagname':nodegroupname},
+ ['tagvalue'])[0]['tagvalue']
+ if expect_yes != "yes":
+ print 'Mismatch node tag on node',nodename,'got',expect_yes
+ overall=False
+ except:
+ if not self.options.dry_run:
+ print 'Cannot find tag',nodegroupname,'on node',nodename
+ overall = False
+ else:
+ try:
+ print 'cleaning nodegroup',nodegroupname
+ self.apiserver.DeleteNodeGroup(auth,nodegroupname)
+ except:
+ traceback.print_exc()
+ overall=False
+ return overall
+
+ def all_hostnames (self) :
+ hostnames = []
+ for site_spec in self.plc_spec['sites']:
+ 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_nodes_booted (self, minutes, gracetime,period=15):
+ if self.options.dry_run:
+ print 'dry_run'
+ return True
+ # 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.apiserver.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 it's a real node, never mind
+ (site_spec,node_spec)=self.locate_hostname(hostname)
+ if TestNode.is_real_model(node_spec['node_fields']['model']):
+ utils.header("WARNING - Real node %s in %s - ignored"%(hostname,boot_state))
+ # let's cheat
+ boot_state = 'boot'
+ elif datetime.datetime.now() > graceout:
+ utils.header ("%s still in '%s' state"%(hostname,boot_state))
+ graceout=datetime.datetime.now()+datetime.timedelta(1)
+ 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(period)
+ # only useful in empty plcs