def EvacuateGroup(opts, args): """Evacuate a node group. """ (group_name, ) = args cl = GetClient() op = opcodes.OpGroupEvacuate(group_name=group_name, iallocator=opts.iallocator, target_groups=opts.to, early_release=opts.early_release) result = SubmitOrSend(op, opts, cl=cl) # Keep track of submitted jobs jex = JobExecutor(cl=cl, opts=opts) for (status, job_id) in result[constants.JOB_IDS_KEY]: jex.AddJobId(None, status, job_id) results = jex.GetResults() bad_cnt = len([row for row in results if not row[0]]) if bad_cnt == 0: ToStdout("All instances evacuated successfully.") rcode = constants.EXIT_SUCCESS else: ToStdout("There were %s errors during the evacuation.", bad_cnt) rcode = constants.EXIT_FAILURE return rcode
def testEvacuateEmptyGroup(self): group = self.cfg.AddNewNodeGroup() op = opcodes.OpGroupEvacuate(group_name=group.name) self.iallocator_cls.return_value.result = ([], [], []) self.ExecOpCode(op)
def testFailingIAllocator(self): group = self.cfg.AddNewNodeGroup() op = opcodes.OpGroupEvacuate(group_name=group.name) self.iallocator_cls.return_value.success = False self.ExecOpCodeExpectOpPrereqError( op, "Can't compute group evacuation using iallocator")
def testEvacuateWithTargetGroups(self): group = self.cfg.AddNewNodeGroup() self.cfg.AddNewNode(group=group) self.cfg.AddNewNode(group=group) target_group1 = self.cfg.AddNewNodeGroup() target_group2 = self.cfg.AddNewNodeGroup() op = opcodes.OpGroupEvacuate( group_name=group.name, target_groups=[target_group1.name, target_group2.name]) self.iallocator_cls.return_value.result = ([], [], []) self.ExecOpCode(op)
def testEvacuateOnlyGroup(self): op = opcodes.OpGroupEvacuate(group_name=self.group.name) self.ExecOpCodeExpectOpPrereqError( op, "There are no possible target groups")