From 2c4042172ad59f0ca338906b47ea740e8c938530 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 6 Apr 2009 08:21:13 +0000
Subject: [PATCH] Fix the output of watcher on non-master nodes

Currently the watcher spews errors message on non-master nodes. This
cleans it up.

Reviewed-by: imsnah
---
 daemons/ganeti-watcher | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher
index 37571a5b7..8745f2dd7 100755
--- a/daemons/ganeti-watcher
+++ b/daemons/ganeti-watcher
@@ -88,11 +88,15 @@ class WatcherState(object):
     utils.LockFile(self.statefile.fileno())
 
     try:
-      self._data = serializer.Load(self.statefile.read())
+      state_data = self.statefile.read()
+      if not state_data:
+        self._data = {}
+      else:
+        self._data = serializer.Load(state_data)
     except Exception, msg:
       # Ignore errors while loading the file and treat it as empty
       self._data = {}
-      logging.warning(("Empty or invalid state file. Using defaults."
+      logging.warning(("Invalid state file. Using defaults."
                        " Error message: %s"), msg)
 
     if "instance" not in self._data:
@@ -440,7 +444,11 @@ def main():
   try:
     notepad = WatcherState()
     try:
-      client = cli.GetClient()
+      try:
+        client = cli.GetClient()
+      except errors.OpPrereqError:
+        # this is, from cli.GetClient, a not-master case
+        sys.exit(constants.EXIT_SUCCESS)
 
       try:
         watcher = Watcher(options, notepad)
-- 
GitLab