Commit 738436bf authored by Thomas Thrainer's avatar Thomas Thrainer

Always return tuples in Expand*Name

ExpandNodeName and ExpandInstanceName now always return a tuple. If the
node/instance was not found, (None, None) is returned. This fixes bugs
where callers blindly assign the return value of those methods to
multiple variables without checking if it was None.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent f9b76ed4
......@@ -58,11 +58,11 @@ def _ExpandItemName(expand_fn, name, kind):
@raise errors.OpPrereqError: if the item is not found
"""
full_name = expand_fn(name)
if full_name is None:
(uuid, full_name) = expand_fn(name)
if uuid is None or full_name is None:
raise errors.OpPrereqError("%s '%s' not known" % (kind, name),
errors.ECODE_NOENT)
return full_name
return (uuid, full_name)
def ExpandInstanceUuidAndName(cfg, expected_uuid, name):
......
......@@ -1617,7 +1617,7 @@ class ConfigWriter:
inst = (filter(lambda n: n.name == expanded_name, all_insts)[0])
return (inst.uuid, inst.name)
else:
return None
return (None, None)
def _UnlockedGetInstanceInfo(self, inst_uuid):
"""Returns information about an instance.
......@@ -1843,7 +1843,7 @@ class ConfigWriter:
node = (filter(lambda n: n.name == expanded_name, all_nodes)[0])
return (node.uuid, node.name)
else:
return None
return (None, None)
def _UnlockedGetNodeInfo(self, node_uuid):
"""Get the configuration of a node, as stored in the config.
......
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