From bf8e3fd7eaadd008b21dd5b63634d254d629e79d Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Wed, 28 Dec 2016 16:09:49 +0400 Subject: [PATCH] Fix using parent_name for Properties Currently Properties has arg "parent_name", which is used for detailed path in error and allows to build path for nested properties schemas. But on top parent_name takes resource name as initial, which is few incorrect - Properties should raises with error about Properties, other info (about in what resource this error raised) should be built out of Properties module. Change-Id: I36e6453a1589c02a3f8cf2c080b38693b23b0f1b Related-bug: #1620859 --- heat/engine/properties.py | 10 ++++------ heat/engine/resource.py | 18 +++++++++++++++--- heat/engine/rsrc_defn.py | 4 ++-- heat/tests/openstack/aodh/test_alarm.py | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 87a2e73ad2..0544cf849b 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -273,7 +273,8 @@ class Property(object): keys = list(self.schema.schema) schemata = dict((k, self.schema.schema[k]) for k in keys) properties = Properties(schemata, dict(child_values), - context=self.context) + context=self.context, + parent_name=self.name) if validate: properties.validate() @@ -364,11 +365,8 @@ class Properties(collections.Mapping): for k, s in schema.items()) self.resolve = resolver self.data = data - self.error_prefix = [] - if parent_name is not None: - self.error_prefix.append(parent_name) - if section is not None: - self.error_prefix.append(section) + self.error_prefix = [section] if section is not None else [] + self.parent_name = parent_name self.context = context @staticmethod diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 7dbb42ff5a..cf6b456164 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -969,6 +969,18 @@ class Resource(object): else: action = self.CREATE except exception.ResourceFailure as failure: + if isinstance(failure.exc, exception.StackValidationFailed): + path = [self.t.name] + path.extend(failure.exc.path) + raise exception.ResourceFailure( + exception_or_error=exception.StackValidationFailed( + error=failure.exc.error, + path=path, + message=failure.exc.error_message + ), + resource=failure.resource, + action=failure.action + ) if not isinstance(failure.exc, exception.ResourceInError): raise failure @@ -1546,9 +1558,9 @@ class Resource(object): with_value=self.stack.strict_validate, template=self.t) except exception.StackValidationFailed as ex: - path = [self.stack.t.RESOURCES, ex.path[0], - self.stack.t.get_section_name(ex.path[1])] - path.extend(ex.path[2:]) + path = [self.stack.t.RESOURCES, self.t.name, + self.stack.t.get_section_name(ex.path[0])] + path.extend(ex.path[1:]) raise exception.StackValidationFailed( error=ex.error, path=path, diff --git a/heat/engine/rsrc_defn.py b/heat/engine/rsrc_defn.py index b56944fa01..a0f182a1c8 100644 --- a/heat/engine/rsrc_defn.py +++ b/heat/engine/rsrc_defn.py @@ -245,7 +245,7 @@ class ResourceDefinition(object): require a context to validate constraints. """ return properties.Properties(schema, self._properties or {}, - function.resolve, self.name, context, + function.resolve, context=context, section='Properties') def deletion_policy(self): @@ -262,7 +262,7 @@ class ResourceDefinition(object): require a context to validate constraints. """ return properties.Properties(schema, self._update_policy or {}, - function.resolve, self.name, context, + function.resolve, context=context, section='UpdatePolicy') def metadata(self): diff --git a/heat/tests/openstack/aodh/test_alarm.py b/heat/tests/openstack/aodh/test_alarm.py index 15ce1b6b43..a211f161ac 100644 --- a/heat/tests/openstack/aodh/test_alarm.py +++ b/heat/tests/openstack/aodh/test_alarm.py @@ -565,7 +565,7 @@ class AodhAlarmTest(common.HeatTestCase): ) self.assertEqual( "StackValidationFailed: resources.MEMAlarmHigh: Property error: " - "MEMAlarmHigh.Properties.time_constraints[0].start: Error " + "Properties.time_constraints[0].start: Error " "validating value '%s': Invalid CRON expression: " "[%s] is not acceptable, out of range" % (start_time, start_time), error.message) @@ -618,7 +618,7 @@ class AodhAlarmTest(common.HeatTestCase): ) self.assertEqual( "StackValidationFailed: resources.MEMAlarmHigh: Property error: " - "MEMAlarmHigh.Properties.time_constraints[0].timezone: Error " + "Properties.time_constraints[0].timezone: Error " "validating value '%s': Invalid timezone: '%s'" % (timezone, timezone), error.message)