Commit 03a8dbdc authored by Iustin Pop's avatar Iustin Pop

Implement handling of luxi errors in cli.py

Currently the generic handling of ganeti errors in cli.py (GenericMain
and FormatError) only handles the core ganeti errors, and not the client
protocol errors (which live in a separate hierarchy).

This patch adds handling of luxi errors too, and also adds another luxi
error for the case when the master is not running. This gives us a nice:

  gnta1:~# gnt-node list
  Cannot communicate with the master daemon.
  Is it running and listening on '/var/run/ganeti-master.sock'?

error message instead of a traceback.

Reviewed-by: amishchenko
parent 11fb401c
......@@ -466,6 +466,15 @@ def FormatError(err):
obuf.write("Failure: invalid tag(s) given:\n%s" % msg)
elif isinstance(err, errors.GenericError):
obuf.write("Unhandled Ganeti error: %s" % msg)
elif isinstance(err, luxi.NoMasterError):
obuf.write("Cannot communicate with the master daemon.\nIs it running"
" and listening on '%s'?" % err.args[0])
elif isinstance(err, luxi.TimeoutError):
obuf.write("Timeout while talking to the master daemon. Error:\n"
"%s" % msg)
elif isinstance(err, luxi.ProtocolError):
obuf.write("Unhandled protocol error while talking to the master daemon:\n"
"%s" % msg)
else:
obuf.write("Unhandled exception: %s" % msg)
return retcode, obuf.getvalue().rstrip('\n')
......@@ -517,7 +526,7 @@ def GenericMain(commands, override=None, aliases=None):
try:
result = func(options, args)
except errors.GenericError, err:
except (errors.GenericError, luxi.ProtocolError), err:
result, err_msg = FormatError(err)
logger.ToStderr(err_msg)
......
......@@ -33,6 +33,7 @@ import socket
import collections
import simplejson
import time
import errno
from ganeti import opcodes
from ganeti import constants
......@@ -80,6 +81,14 @@ class RequestError(ProtocolError):
"""
class NoMasterError(ProtocolError):
"""The master cannot be reached
This means that the master daemon is not running or the socket has
been removed.
"""
def SerializeJob(job):
"""Convert a job description to a string format.
......@@ -153,9 +162,13 @@ class Transport:
try:
self.socket.connect(address)
except socket.timeout, err:
raise TimeoutError("Connection timed out: %s" % str(err))
raise TimeoutError("Connect timed out: %s" % str(err))
except socket.error, err:
if err.args[0] == errno.ENOENT:
raise NoMasterError((address,))
raise
self.socket.settimeout(self._rwtimeout)
except socket.error:
except (socket.error, NoMasterError):
if self.socket is not None:
self.socket.close()
self.socket = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment