diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher index a6f113fa6acffa36b59dd849e786348dd6e2a865..2e5b98f0fb4f6de0905954f32857827e2b606dd4 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 6276ac0d0af187ff15b2452c90fa5c904cc41eac..04f28eb114e016cef039ab279743f649686cdec3 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. + + """