Commit 1ec34e26 authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Klaus Aehlig

query: fix detection of master in _GetNodeRole()

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: default avatarApollon Oikonomopoulos <apoikos@gmail.com>
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 47387ccb
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment