From: Iustin Pop Date: Wed, 10 Jun 2009 10:45:02 +0000 (+0200) Subject: Convert master_info rpc to new style result X-Git-Tag: v2.1.0beta0~431^2~65 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/2a52a064ad9411c5f5b45d69955a6a861a767d4b 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: Iustin Pop Reviewed-by: Guido Trotter --- diff --git a/lib/backend.py b/lib/backend.py index 20c0caa..10ddcf5 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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]) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 33fae1b..a3811a8 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -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