From 7bca53e408c8be1227dbec1d5aac41548a7d22bf Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 18 Jun 2008 12:32:23 +0000
Subject: [PATCH] ganeti-watcher: Replace custom exceptions with ganeti.error.*

Reviewed-by: iustinp
---
 daemons/ganeti-watcher | 21 +++++++++------------
 lib/errors.py          |  6 ++++++
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher
index a6f113fa6..2e5b98f0f 100755
--- a/daemons/ganeti-watcher
+++ b/daemons/ganeti-watcher
@@ -53,11 +53,7 @@ KEY_RESTART_WHEN = "restart_when"
 KEY_BOOT_ID = "bootid"
 
 
-class Error(Exception):
-  """Generic custom error class."""
-
-
-class NotMasterError(Error):
+class NotMasterError(errors.GenericError):
   """Exception raised when this host is not the master."""
 
 
@@ -84,11 +80,12 @@ def DoCmd(cmd):
   res = utils.RunCmd(cmd)
 
   if res.failed:
-    raise Error("Command %s failed:\n%s\nstdout:\n%sstderr:\n%s" %
-                (repr(cmd),
-                 Indent(res.fail_reason),
-                 Indent(res.stdout),
-                 Indent(res.stderr)))
+    msg = ("Command %s failed:\n%s\nstdout:\n%sstderr:\n%s" %
+           (repr(cmd),
+            Indent(res.fail_reason),
+            Indent(res.stdout),
+            Indent(res.stderr)))
+    raise errors.CommandError(msg)
 
   return res
 
@@ -101,7 +98,7 @@ def LockFile(fd):
     fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
   except IOError, err:
     if err.errno == errno.EAGAIN:
-      raise StandardError("File already locked")
+      raise errors.LockError("File already locked")
     raise
 
 
@@ -112,7 +109,7 @@ class WatcherState(object):
   def __init__(self):
     """Open, lock, read and parse the file.
 
-    Raises StandardError on lock contention.
+    Raises exception on lock contention.
 
     """
     # The two-step dance below is necessary to allow both opening existing
diff --git a/lib/errors.py b/lib/errors.py
index 6276ac0d0..04f28eb11 100644
--- a/lib/errors.py
+++ b/lib/errors.py
@@ -210,3 +210,9 @@ class TagError(GenericError):
   The argument to this exception will show the exact error.
 
   """
+
+
+class CommandError(GenericError):
+  """External command error.
+
+  """
-- 
GitLab