Convert master_info rpc to new style result
authorIustin Pop <iustin@google.com>
Wed, 10 Jun 2009 10:45:02 +0000 (12:45 +0200)
committerIustin Pop <iustin@google.com>
Mon, 15 Jun 2009 17:08:21 +0000 (19:08 +0200)
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 <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/backend.py
lib/bootstrap.py

index 20c0caa..10ddcf5 100644 (file)
@@ -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])
index 33fae1b..a3811a8 100644 (file)
@@ -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