Improve RAPI detection of the watcher
authorMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 13:59:49 +0000 (13:59 +0000)
committerMichele Tartara <mtartara@google.com>
Fri, 7 Mar 2014 15:15:08 +0000 (15:15 +0000)
If the watcher is not allowed to access RAPI, it doesn't mean that it is dead
and needs to be restarted.

Fixes Issue 752.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>

lib/watcher/__init__.py

index 1f7ec65..4c2d019 100644 (file)
@@ -329,6 +329,10 @@ def IsRapiResponding(hostname):
   Connects to RAPI port of hostname and does a simple test. At this time, the
   test is GetVersion.
 
+  If RAPI responds with error code "401 Unauthorized", the test is successful,
+  because the aim of this function is to assess whether RAPI is responding, not
+  if it is accessible.
+
   @type hostname: string
   @param hostname: hostname of the node to connect to.
   @rtype: bool
@@ -344,8 +348,12 @@ def IsRapiResponding(hostname):
     logging.warning("RAPI certificate error: %s", err)
     return False
   except rapi.client.GanetiApiError, err:
-    logging.warning("RAPI error: %s", err)
-    return False
+    if err.code == 401:
+      # Unauthorized, but RAPI is alive and responding
+      return True
+    else:
+      logging.warning("RAPI error: %s", err)
+      return False
   else:
     logging.debug("Reported RAPI version %s", master_version)
     return master_version == constants.RAPI_VERSION