Commit 2a52a064 authored by Iustin Pop's avatar Iustin Pop

Convert master_info rpc to new style result

This was more tricky as the backend function is used by other function
in backend.py. As such, it must be handled specially - it must raise
always an exception and not simply return False, err.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 10bfe6cb
......@@ -161,8 +161,8 @@ def GetMasterInfo():
for consumption here or from the node daemon.
@rtype: tuple
@return: (master_netdev, master_ip, master_name) if we have a good
configuration, otherwise (None, None, None)
@return: True, (master_netdev, master_ip, master_name) in case of success
@raise RPCFail: in case of errors
"""
try:
......@@ -171,9 +171,8 @@ def GetMasterInfo():
master_ip = cfg.GetMasterIP()
master_node = cfg.GetMasterNode()
except errors.ConfigurationError, err:
logging.exception("Cluster configuration incomplete")
return (None, None, None)
return (master_netdev, master_ip, master_node)
_Fail("Cluster configuration incomplete", exc=True)
return True, (master_netdev, master_ip, master_node)
def StartMaster(start_daemons):
......@@ -189,9 +188,8 @@ def StartMaster(start_daemons):
@rtype: None
"""
master_netdev, master_ip, _ = GetMasterInfo()
if not master_netdev:
return False, "Cluster configuration incomplete, cannot read ssconf files"
# GetMasterInfo will raise an exception if not able to return data
master_netdev, master_ip, _ = GetMasterInfo()[1]
payload = []
if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
......@@ -242,9 +240,9 @@ def StopMaster(stop_daemons):
"""
# TODO: log and report back to the caller the error failures; we
# need to decide in which case we fail the RPC for this
master_netdev, master_ip, _ = GetMasterInfo()
if not master_netdev:
return False, "Cluster configuration incomplete, cannot read ssconf files"
# GetMasterInfo will raise an exception if not able to return data
master_netdev, master_ip, _ = GetMasterInfo()[1]
result = utils.RunCmd(["ip", "address", "del", "%s/32" % master_ip,
"dev", master_netdev])
......
......@@ -511,9 +511,16 @@ def GatherMasterVotes(node_list):
votes = {}
for node in results:
nres = results[node]
data = nres.data
if nres.failed or not isinstance(data, (tuple, list)) or len(data) < 3:
# here the rpc layer should have already logged errors
data = nres.payload
msg = nres.RemoteFailMsg()
fail = False
if msg:
logging.warning("Error contacting node %s: %s", node, msg)
fail = True
elif not isinstance(data, (tuple, list)) or len(data) < 3:
logging.warning("Invalid data received from node %s: %s", node, data)
fail = True
if fail:
if None not in votes:
votes[None] = 0
votes[None] += 1
......
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