Hi, The following patch should fix the issue, but I didn't have the time to test it.
Regards, Apollon ------------------------------8<---------------------------------------- Commit 1c3231aa changed the invocation of _GetNodeRole() to pass the master node by UUID and not by name, but didn't change the implementation to compare the nodes by name. As a result, the master node (which is also a master candidate) would always fall through to the second option and be marked as 'C' instead as 'M'. We fix this by modifying the implementation of _GetNodeRole() to perform the comparison by UUID and also change the respective tests to test the new API. Signed-off-by: Apollon Oikonomopoulos <[email protected]> --- lib/query.py | 8 ++++---- test/py/ganeti.query_unittest.py | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/query.py b/lib/query.py index 58278d5..1c2759b 100644 --- a/lib/query.py +++ b/lib/query.py @@ -946,16 +946,16 @@ def _StaticValue(value): return compat.partial(_StaticValueInner, value) -def _GetNodeRole(node, master_name): +def _GetNodeRole(node, master_uuid): """Determine node role. @type node: L{objects.Node} @param node: Node object - @type master_name: string - @param master_name: Master node name + @type master_uuid: string + @param master_uuid: Master node UUID """ - if node.name == master_name: + if node.uuid == master_uuid: return constants.NR_MASTER elif node.master_candidate: return constants.NR_MCANDIDATE diff --git a/test/py/ganeti.query_unittest.py b/test/py/ganeti.query_unittest.py index 04a7708..0d6e4a4 100755 --- a/test/py/ganeti.query_unittest.py +++ b/test/py/ganeti.query_unittest.py @@ -299,20 +299,23 @@ class TestQuery(unittest.TestCase): class TestGetNodeRole(unittest.TestCase): def test(self): tested_role = set() - + master_uuid = "969502b9-f632-4d3d-83a5-a78b0ca8cdf6" + node_uuid = "d75499b5-83e3-4b80-b6fe-3e1aee7e5a35" checks = [ - (constants.NR_MASTER, "node1", objects.Node(name="node1")), - (constants.NR_MCANDIDATE, "master", - objects.Node(name="node1", master_candidate=True)), - (constants.NR_REGULAR, "master", objects.Node(name="node1")), - (constants.NR_DRAINED, "master", - objects.Node(name="node1", drained=True)), + (constants.NR_MASTER, + objects.Node(name="node1", uuid=master_uuid)), + (constants.NR_MCANDIDATE, + objects.Node(name="node1", uuid=node_uuid, master_candidate=True)), + (constants.NR_REGULAR, + objects.Node(name="node1", uuid=node_uuid)), + (constants.NR_DRAINED, + objects.Node(name="node1", uuid=node_uuid, drained=True)), (constants.NR_OFFLINE, - "master", objects.Node(name="node1", offline=True)), + objects.Node(name="node1", uuid=node_uuid, offline=True)), ] - for (role, master_name, node) in checks: - result = query._GetNodeRole(node, master_name) + for (role, node) in checks: + result = query._GetNodeRole(node, master_uuid) self.assertEqual(result, role) tested_role.add(result) -- 1.8.5.2
