From 99b30c3737ed9490720b054c7340ea2f05ff3eea Mon Sep 17 00:00:00 2001 From: Marcin Piwowarczyk Date: Mon, 1 Apr 2019 16:46:26 +0200 Subject: [PATCH] Add error handling when Swift is not installed So far, when Swift wasn't installed, there was no error handlig in trove API. This change adds LogsNotAvailable exception which is raised when swift endpoints are not available. Change-Id: I9a8a75b40bde90163560cdd758f17f9a98a41f0a Story: #2005378 Task: #30360 Signed-off-by: Kasper Hasior --- trove/common/exception.py | 5 +++++ trove/common/wsgi.py | 3 ++- trove/instance/service.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/trove/common/exception.py b/trove/common/exception.py index e0e0feea96..00d70f1cd0 100644 --- a/trove/common/exception.py +++ b/trove/common/exception.py @@ -684,6 +684,11 @@ class LogAccessForbidden(Forbidden): message = _("You must be admin to %(action)s log '%(log)s'.") +class LogsNotAvailable(Forbidden): + + message = _("Log actions are not supported.") + + class SlaveOperationNotSupported(TroveError): message = _("The '%(operation)s' operation is not supported for slaves in " diff --git a/trove/common/wsgi.py b/trove/common/wsgi.py index 3be631f7eb..4c8673d5b2 100644 --- a/trove/common/wsgi.py +++ b/trove/common/wsgi.py @@ -368,7 +368,8 @@ class Controller(object): exception.LocalStorageNotSupported, exception.DatastoreOperationNotSupported, exception.ClusterInstanceOperationNotSupported, - exception.ClusterDatastoreNotSupported + exception.ClusterDatastoreNotSupported, + exception.LogsNotAvailable ], } diff --git a/trove/instance/service.py b/trove/instance/service.py index 184122f494..1e558f5f1a 100644 --- a/trove/instance/service.py +++ b/trove/instance/service.py @@ -484,6 +484,12 @@ class InstanceController(wsgi.Controller): """Return all information about all logs for an instance.""" LOG.debug("Listing logs for tenant %s", tenant_id) context = req.environ[wsgi.CONTEXT_KEY] + + try: + backup_model.verify_swift_auth_token(context) + except exception.SwiftNotFound: + raise exception.LogsNotAvailable() + instance = models.Instance.load(context, id) if not instance: raise exception.NotFound(uuid=id) @@ -496,6 +502,12 @@ class InstanceController(wsgi.Controller): """Processes a guest log.""" LOG.info("Processing log for tenant %s", tenant_id) context = req.environ[wsgi.CONTEXT_KEY] + + try: + backup_model.verify_swift_auth_token(context) + except exception.SwiftNotFound: + raise exception.LogsNotAvailable() + instance = models.Instance.load(context, id) if not instance: raise exception.NotFound(uuid=id)