diff --git a/lib/client/gnt_node.py b/lib/client/gnt_node.py index 270aff55eb63016d8c5531e0eba5f889ee0e41ea..0fe37c7ad2b3b5264390ebeed6c155f14f0c14db 100644 --- a/lib/client/gnt_node.py +++ b/lib/client/gnt_node.py @@ -276,11 +276,11 @@ def EvacuateNode(opts, args): " --secondary-only options can be passed", errors.ECODE_INVAL) elif opts.primary_only: - mode = constants.IALLOCATOR_NEVAC_PRI + mode = constants.NODE_EVAC_PRI elif opts.secondary_only: - mode = constants.IALLOCATOR_NEVAC_SEC + mode = constants.NODE_EVAC_SEC else: - mode = constants.IALLOCATOR_NEVAC_ALL + mode = constants.NODE_EVAC_ALL # Determine affected instances fields = [] diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 4297b8a0dc48c4ad127994805196833846c1c690..3208ebf52aef7bf3f88b470824c544e01c645979 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -10145,6 +10145,15 @@ class LUNodeEvacuate(NoHooksLU): """ REQ_BGL = False + _MODE2IALLOCATOR = { + constants.NODE_EVAC_PRI: constants.IALLOCATOR_NEVAC_PRI, + constants.NODE_EVAC_SEC: constants.IALLOCATOR_NEVAC_SEC, + constants.NODE_EVAC_ALL: constants.IALLOCATOR_NEVAC_ALL, + } + assert frozenset(_MODE2IALLOCATOR.keys()) == constants.NODE_EVAC_MODES + assert (frozenset(_MODE2IALLOCATOR.values()) == + constants.IALLOCATOR_NEVAC_MODES) + def CheckArguments(self): _CheckIAllocatorOrNode(self, "iallocator", "remote_node") @@ -10159,7 +10168,7 @@ class LUNodeEvacuate(NoHooksLU): raise errors.OpPrereqError("Can not use evacuated node as a new" " secondary node", errors.ECODE_INVAL) - if self.op.mode != constants.IALLOCATOR_NEVAC_SEC: + if self.op.mode != constants.NODE_EVAC_SEC: raise errors.OpPrereqError("Without the use of an iallocator only" " secondary instances can be evacuated", errors.ECODE_INVAL) @@ -10185,19 +10194,19 @@ class LUNodeEvacuate(NoHooksLU): """Builds list of instances to operate on. """ - assert self.op.mode in constants.IALLOCATOR_NEVAC_MODES + assert self.op.mode in constants.NODE_EVAC_MODES - if self.op.mode == constants.IALLOCATOR_NEVAC_PRI: + if self.op.mode == constants.NODE_EVAC_PRI: # Primary instances only inst_fn = _GetNodePrimaryInstances assert self.op.remote_node is None, \ "Evacuating primary instances requires iallocator" - elif self.op.mode == constants.IALLOCATOR_NEVAC_SEC: + elif self.op.mode == constants.NODE_EVAC_SEC: # Secondary instances only inst_fn = _GetNodeSecondaryInstances else: # All instances - assert self.op.mode == constants.IALLOCATOR_NEVAC_ALL + assert self.op.mode == constants.NODE_EVAC_ALL inst_fn = _GetNodeInstances return inst_fn(self.cfg, self.op.node_name) @@ -10272,7 +10281,7 @@ class LUNodeEvacuate(NoHooksLU): elif self.op.iallocator is not None: # TODO: Implement relocation to other group ial = IAllocator(self.cfg, self.rpc, constants.IALLOCATOR_MODE_NODE_EVAC, - evac_mode=self.op.mode, + evac_mode=self._MODE2IALLOCATOR[self.op.mode], instances=list(self.instance_names)) ial.Run(self.op.iallocator) @@ -10286,7 +10295,7 @@ class LUNodeEvacuate(NoHooksLU): jobs = _LoadNodeEvacResult(self, ial.result, self.op.early_release, True) elif self.op.remote_node is not None: - assert self.op.mode == constants.IALLOCATOR_NEVAC_SEC + assert self.op.mode == constants.NODE_EVAC_SEC jobs = [ [opcodes.OpInstanceReplaceDisks(instance_name=instance_name, remote_node=self.op.remote_node, diff --git a/lib/constants.py b/lib/constants.py index e04e9b3b4252805607b4a2df707056c898752602..f401781955dc61783e82a233cd642d3286a4c41a 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -1116,6 +1116,16 @@ IALLOCATOR_NEVAC_MODES = frozenset([ IALLOCATOR_NEVAC_ALL, ]) +# Node evacuation +NODE_EVAC_PRI = "primary-only" +NODE_EVAC_SEC = "secondary-only" +NODE_EVAC_ALL = "all" +NODE_EVAC_MODES = frozenset([ + NODE_EVAC_PRI, + NODE_EVAC_SEC, + NODE_EVAC_ALL, + ]) + # Job queue JOB_QUEUE_VERSION = 1 JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock" diff --git a/lib/opcodes.py b/lib/opcodes.py index ed017cc1674b9d8f3b97d7911cfe28b919ae1582..6a922c9467e51b266cbc356f840fce1083363085 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -1014,7 +1014,7 @@ class OpNodeEvacuate(OpCode): _PNodeName, ("remote_node", None, ht.TMaybeString, "New secondary node"), ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), - ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES), + ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES), "Node evacuation mode"), ] OP_RESULT = TJobIdListOnly diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py index 1067656d3c1fd3ea2a65df3ea976ba2fac3d49c2..d5ab404b2490d2bdf94a0ff8580b03be62b175f2 100755 --- a/test/ganeti.rapi.client_unittest.py +++ b/test/ganeti.rapi.client_unittest.py @@ -166,9 +166,9 @@ class TestConstants(unittest.TestCase): self.assertEqual(client.JOB_STATUS_ALL, constants.JOB_STATUS_ALL) # Node evacuation - self.assertEqual(client.NODE_EVAC_PRI, constants.IALLOCATOR_NEVAC_PRI) - self.assertEqual(client.NODE_EVAC_SEC, constants.IALLOCATOR_NEVAC_SEC) - self.assertEqual(client.NODE_EVAC_ALL, constants.IALLOCATOR_NEVAC_ALL) + self.assertEqual(client.NODE_EVAC_PRI, constants.NODE_EVAC_PRI) + self.assertEqual(client.NODE_EVAC_SEC, constants.NODE_EVAC_SEC) + self.assertEqual(client.NODE_EVAC_ALL, constants.NODE_EVAC_ALL) # Legacy name self.assertEqual(client.JOB_STATUS_WAITLOCK, constants.JOB_STATUS_WAITING) @@ -866,7 +866,7 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): self.rapi.AddResponse(serializer.DumpJson([rlib2._NODE_EVAC_RES1])) self.rapi.AddResponse("8888") job_id = self.client.EvacuateNode("node-3", iallocator="hail", dry_run=True, - mode=constants.IALLOCATOR_NEVAC_ALL, + mode=constants.NODE_EVAC_ALL, early_release=True) self.assertEqual(8888, job_id) self.assertItems(["node-3"])