Commit 9ba38706 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Replace errors re-export in luxi.py with proper imports



Instead of re-exporting errors in luxi.py, import rpc/errors.py in the
modules that use them.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent edd09726
......@@ -36,7 +36,7 @@ from ganeti import utils
from ganeti import errors
from ganeti import constants
from ganeti import opcodes
from ganeti import luxi
import ganeti.rpc.errors as rpcerr
import ganeti.rpc.node as rpc
from ganeti import ssh
from ganeti import compat
......@@ -2440,7 +2440,7 @@ def FormatError(err):
obuf.write("Parameter Error: %s" % msg)
elif isinstance(err, errors.ParameterError):
obuf.write("Failure: unknown/wrong parameter name '%s'" % msg)
elif isinstance(err, luxi.NoMasterError):
elif isinstance(err, rpcerr.NoMasterError):
if err.args[0] == pathutils.MASTER_SOCKET:
daemon = "the master daemon"
elif err.args[0] == pathutils.QUERY_SOCKET:
......@@ -2449,16 +2449,16 @@ def FormatError(err):
daemon = "socket '%s'" % str(err.args[0])
obuf.write("Cannot communicate with %s.\nIs the process running"
" and listening for connections?" % daemon)
elif isinstance(err, luxi.TimeoutError):
elif isinstance(err, rpcerr.TimeoutError):
obuf.write("Timeout while talking to the master daemon. Jobs might have"
" been submitted and will continue to run even if the call"
" timed out. Useful commands in this situation are \"gnt-job"
" list\", \"gnt-job cancel\" and \"gnt-job watch\". Error:\n")
obuf.write(msg)
elif isinstance(err, luxi.PermissionError):
elif isinstance(err, rpcerr.PermissionError):
obuf.write("It seems you don't have permissions to connect to the"
" master daemon.\nPlease retry as a different user.")
elif isinstance(err, luxi.ProtocolError):
elif isinstance(err, rpcerr.ProtocolError):
obuf.write("Unhandled protocol error while talking to the master daemon:\n"
"%s" % msg)
elif isinstance(err, errors.JobLost):
......@@ -2543,7 +2543,7 @@ def GenericMain(commands, override=None, aliases=None,
try:
result = func(options, args)
except (errors.GenericError, luxi.ProtocolError,
except (errors.GenericError, rpcerr.ProtocolError,
JobSubmittedException), err:
result, err_msg = FormatError(err)
logging.exception("Error during command processing")
......@@ -3706,7 +3706,7 @@ class JobExecutor(object):
ToStderr("Job %s%s has been archived, cannot check its result",
jid, self._IfName(name, " for %s"))
success = False
except (errors.GenericError, luxi.ProtocolError), err:
except (errors.GenericError, rpcerr.ProtocolError), err:
_, job_result = FormatError(err)
success = False
# the error message will always be shown, verbose or not
......
......@@ -33,16 +33,8 @@ from ganeti import constants
from ganeti import objects
import ganeti.rpc.client as cl
from ganeti.rpc.transport import Transport
import ganeti.rpc.errors
__all__ = [
# functions:
"ProtocolError",
"ConnectionClosedError",
"TimeoutError",
"RequestError",
"NoMasterError",
"PermissionError",
# classes:
"Client"
]
......@@ -74,14 +66,6 @@ REQ_ALL = constants.LUXI_REQ_ALL
DEF_RWTO = constants.LUXI_DEF_RWTO
WFJC_TIMEOUT = constants.LUXI_WFJC_TIMEOUT
# "Legacy" re-exports.
ProtocolError = ganeti.rpc.errors.ProtocolError
ConnectionClosedError = ganeti.rpc.errors.ConnectionClosedError
TimeoutError = ganeti.rpc.errors.TimeoutError
RequestError = ganeti.rpc.errors.RequestError
NoMasterError = ganeti.rpc.errors.NoMasterError
PermissionError = ganeti.rpc.errors.PermissionError
class Client(cl.AbstractClient):
"""High-level client implementation.
......
......@@ -30,6 +30,7 @@
import logging
from ganeti import luxi
import ganeti.rpc.errors as rpcerr
from ganeti import rapi
from ganeti import http
from ganeti import errors
......@@ -366,9 +367,9 @@ class ResourceBase(object):
# Could be a function, pylint: disable=R0201
try:
return self._client_cls(address=address)
except luxi.NoMasterError, err:
except rpcerr.NoMasterError, err:
raise http.HttpBadGateway("Can't connect to master daemon: %s" % err)
except luxi.PermissionError:
except rpcerr.PermissionError:
raise http.HttpInternalServerError("Internal error: no permission to"
" connect to the master daemon")
......@@ -391,12 +392,12 @@ class ResourceBase(object):
raise http.HttpServiceUnavailable("Job queue is full, needs archiving")
except errors.JobQueueDrainError:
raise http.HttpServiceUnavailable("Job queue is drained, cannot submit")
except luxi.NoMasterError, err:
except rpcerr.NoMasterError, err:
raise http.HttpBadGateway("Master seems to be unreachable: %s" % err)
except luxi.PermissionError:
except rpcerr.PermissionError:
raise http.HttpInternalServerError("Internal error: no permission to"
" connect to the master daemon")
except luxi.TimeoutError, err:
except rpcerr.TimeoutError, err:
raise http.HttpGatewayTimeout("Timeout while talking to the master"
" daemon: %s" % err)
......
......@@ -48,6 +48,7 @@ from ganeti import opcodes
from ganeti import jqueue
from ganeti import locking
from ganeti import luxi
import ganeti.rpc.errors as rpcerr
from ganeti import utils
from ganeti import errors
from ganeti import ssconf
......@@ -94,7 +95,7 @@ class ClientRequestWorker(workerpool.BaseWorker):
try:
(method, args, ver) = rpccl.ParseRequest(message)
except luxi.ProtocolError, err:
except rpcerr.ProtocolError, err:
logging.error("Protocol Error: %s", err)
client.close_log()
return
......
......@@ -43,7 +43,7 @@ from ganeti import constants
from ganeti import http
from ganeti import daemon
from ganeti import ssconf
from ganeti import luxi
import ganeti.rpc.errors as rpcerr
from ganeti import serializer
from ganeti import compat
from ganeti import utils
......@@ -195,9 +195,9 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication,
try:
result = ctx.handler_fn()
except luxi.TimeoutError:
except rpcerr.TimeoutError:
raise http.HttpGatewayTimeout()
except luxi.ProtocolError, err:
except rpcerr.ProtocolError, err:
raise http.HttpBadGateway(str(err))
req.resp_headers[http.HTTP_CONTENT_TYPE] = http.HTTP_APP_JSON
......
......@@ -42,7 +42,8 @@ from ganeti import compat
from ganeti import errors
from ganeti import opcodes
from ganeti import cli
from ganeti import luxi
import ganeti.rpc.node as rpc
import ganeti.rpc.errors as rpcerr
from ganeti import rapi
from ganeti import netutils
from ganeti import qlang
......@@ -524,7 +525,7 @@ def GetLuxiClient(try_restart, query=False):
# this is, from cli.GetClient, a not-master case
raise NotMasterError("Not on master node (%s)" % err)
except luxi.NoMasterError, err:
except rpcerr.NoMasterError, err:
if not try_restart:
raise
......
......@@ -33,7 +33,7 @@ from ganeti import opcodes
from ganeti import compat
from ganeti import http
from ganeti import query
from ganeti import luxi
import ganeti.rpc.errors as rpcerr
from ganeti import errors
from ganeti import rapi
......@@ -107,7 +107,7 @@ class TestConstants(unittest.TestCase):
class TestClientConnectError(unittest.TestCase):
@staticmethod
def _FailingClient(address=None):
raise luxi.NoMasterError("test")
raise rpcerr.NoMasterError("test")
def test(self):
resources = [
......
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