From aac38555f144d7f3468e8a99092e3daea9b5c95b Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Wed, 18 Nov 2015 11:32:48 +0530 Subject: [PATCH] Update resource type exceptions with error_code Adds the error_code for resource type exceptions and for resource type error code starts with 99xxx. implements blueprint heat-template-validate-improvements Change-Id: Id73cfd06bfb28e15a52696757bb9f10cbe2596e3 --- heat/common/exception.py | 25 ++++++++++++++++++++----- heat/tests/engine/test_resource_type.py | 4 ++-- heat/tests/test_resource.py | 5 +++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/heat/common/exception.py b/heat/common/exception.py index 4696100150..a413bd2ff2 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -31,6 +31,13 @@ _FATAL_EXCEPTION_FORMAT_ERRORS = False LOG = logging.getLogger(__name__) +# TODO(kanagaraj-manickam): Expose this to user via REST API +ERROR_CODE_MAP = { + '99001': _("Service %(service_name)s does not have required endpoint in " + "service catalog for the resource type %(resource_type)s") +} + + @six.python_2_unicode_compatible class HeatException(Exception): """Base Heat Exception. @@ -40,12 +47,21 @@ class HeatException(Exception): provided to the constructor. """ message = _("An unknown exception occurred.") + # error_code helps to provide an unique number for a given exception + # and is encoded in XXYYY format. + # Here, XX - For each of the entity type like stack, resource, etc + # an unique number will be provided. All exceptions for a entity will + # have same XX code. + # YYY - Specific error code for a given exception. error_code = None def __init__(self, **kwargs): self.kwargs = kwargs try: + if self.error_code in ERROR_CODE_MAP: + self.msg_fmt = ERROR_CODE_MAP[self.error_code] + self.message = self.msg_fmt % kwargs if self.error_code: @@ -206,6 +222,10 @@ class InvalidGlobalResource(HeatException): "resource type %(type_name)s.") +class ResourceTypeUnavailable(HeatException): + error_code = '99001' + + class InvalidBreakPointHook(HeatException): msg_fmt = _("%(message)s") @@ -440,10 +460,5 @@ class SIGHUPInterrupt(HeatException): msg_fmt = _("System SIGHUP signal received.") -class ResourceTypeUnavailable(HeatException): - msg_fmt = _("Service %(service_name)s does not have required endpoint in " - "service catalog for the resource type %(resource_type)s") - - class NoActionRequired(Exception): pass diff --git a/heat/tests/engine/test_resource_type.py b/heat/tests/engine/test_resource_type.py index e65c51b728..2ebf79352c 100644 --- a/heat/tests/engine/test_resource_type.py +++ b/heat/tests/engine/test_resource_type.py @@ -167,8 +167,8 @@ class ResourceTypeTest(common.HeatTestCase): self.ctx, type_name) - msg = ('Service sample does not have required endpoint in service' - ' catalog for the resource type' + msg = ('HEAT-E99001 Service sample does not have required endpoint' + ' in service catalog for the resource type' ' ResourceWithDefaultClientName') self.assertEqual(msg, six.text_type(ex), diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 972cacee72..3a62fc2805 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -3265,8 +3265,9 @@ class ResourceAvailabilityTest(common.HeatTestCase): definition=definition, stack=mock_stack) - msg = ('Service sample does not have required endpoint in service' - ' catalog for the resource type UnavailableResourceType') + msg = ('HEAT-E99001 Service sample does not have required endpoint' + ' in service catalog for the resource type' + ' UnavailableResourceType') self.assertEqual(msg, six.text_type(ex), 'invalid exception message')