From ecd78c6048ea3234aec93ceef13942b86251f2b0 Mon Sep 17 00:00:00 2001 From: dharmendra Date: Wed, 26 Jun 2019 07:22:05 +0000 Subject: [PATCH] FIX: nfv event list failed with internal server error In case of invalid id of resource-id, event list command failed with inappropriate error(i.e. internal server error). Fixing this issue with propper error handling. Change-Id: I0e23da2d63bf3bcedfea78e6e88575cb7a7adfeb Closes-Bug:#1834178 --- .../common_services/common_services_db_plugin.py | 14 ++++++++++---- tacker/extensions/common_services.py | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tacker/db/common_services/common_services_db_plugin.py b/tacker/db/common_services/common_services_db_plugin.py index 247472146..38da2f7c3 100644 --- a/tacker/db/common_services/common_services_db_plugin.py +++ b/tacker/db/common_services/common_services_db_plugin.py @@ -16,6 +16,7 @@ from sqlalchemy.orm import exc as orm_exc +from oslo_db import exception from oslo_log import log as logging from tacker.common import log @@ -82,7 +83,12 @@ class CommonServicesPluginDb(common_services.CommonServicesPluginBase, @log.log def get_events(self, context, filters=None, fields=None, sorts=None, limit=None, marker_obj=None, page_reverse=False): - return self._get_collection(context, common_services_db.Event, - self._make_event_dict, - filters, fields, sorts, limit, - marker_obj, page_reverse) + try: + return self._get_collection(context, common_services_db.Event, + self._make_event_dict, + filters, fields, sorts, limit, + marker_obj, page_reverse) + except exception.DBError as e: + LOG.error("Failed to get event: %s", e.message) + msg = "Id should be in UUID v4 format" + raise common_services.InvalidFormat(error=msg) diff --git a/tacker/extensions/common_services.py b/tacker/extensions/common_services.py index c2e1deca9..37b838e0d 100644 --- a/tacker/extensions/common_services.py +++ b/tacker/extensions/common_services.py @@ -46,6 +46,10 @@ class ParamYAMLInputMissing(exceptions.InvalidInput): message = _("Parameter YAML input missing") +class InvalidFormat(exceptions.InvalidInput): + message = _("Invalid format. '%(error)s'") + + RESOURCE_ATTRIBUTE_MAP = { 'events': {