From e884ae5057420f936a03826ad047b81faa3f646b Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 5 Sep 2013 11:16:55 +1000 Subject: [PATCH] Make the new template validation usable from tests This is so we can assert that new TemplateResources expose the api that we are expecting. Partial-Bug: #1215797 Change-Id: I6273f6e046bb7bd5e075e9190d8011af976573b8 --- heat/engine/resources/template_resource.py | 61 ++++++++++++---------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py index 219fca05..50bb37f7 100644 --- a/heat/engine/resources/template_resource.py +++ b/heat/engine/resources/template_resource.py @@ -114,6 +114,37 @@ class TemplateResource(stack_resource.StackResource): self.stack.t.files[self.template_name] = t_data return t_data + def _validate_against_facade(self, facade_cls): + facade_schemata = properties.schemata(facade_cls.properties_schema) + + for n, fs in facade_schemata.items(): + if fs.required and n not in self.properties_schema: + msg = ("Required property %s for facade %s " + "missing in provider") % (n, self.type()) + raise exception.StackValidationFailed(message=msg) + + ps = self.properties_schema.get(n) + if (n in self.properties_schema and + (fs.type != ps.type)): + # Type mismatch + msg = ("Property %s type mismatch between facade %s (%s) " + "and provider (%s)") % (n, self.type(), + fs.type, ps.type) + raise exception.StackValidationFailed(message=msg) + + for n, ps in self.properties_schema.items(): + if ps.required and n not in facade_schemata: + # Required property for template not present in facade + msg = ("Provider requires property %s " + "unknown in facade %s") % (n, self.type()) + raise exception.StackValidationFailed(message=msg) + + for attr in facade_cls.attributes_schema: + if attr not in self.attributes_schema: + msg = ("Attribute %s for facade %s " + "missing in provider") % (attr, self.type()) + raise exception.StackValidationFailed(message=msg) + def validate(self): cri = self.stack.env.get_resource_info( self.type(), @@ -123,35 +154,7 @@ class TemplateResource(stack_resource.StackResource): # template, check for compatibility between the interfaces. if cri is not None and not isinstance(self, cri.get_class()): facade_cls = cri.get_class() - facade_schemata = properties.schemata(facade_cls.properties_schema) - - for n, fs in facade_schemata.items(): - if fs.required and n not in self.properties_schema: - msg = ("Required property %s for facade %s " - "missing in provider") % (n, self.type()) - raise exception.StackValidationFailed(message=msg) - - ps = self.properties_schema.get(n) - if (n in self.properties_schema and - (fs.type != ps.type)): - # Type mismatch - msg = ("Property %s type mismatch between facade %s (%s) " - "and provider (%s)") % (n, self.type(), - fs.type, ps.type) - raise exception.StackValidationFailed(message=msg) - - for n, ps in self.properties_schema.items(): - if ps.required and n not in facade_schemata: - # Required property for template not present in facade - msg = ("Provider requires property %s " - "unknown in facade %s") % (n, self.type()) - raise exception.StackValidationFailed(message=msg) - - for attr in facade_cls.attributes_schema: - if attr not in self.attributes_schema: - msg = ("Attribute %s for facade %s " - "missing in provider") % (attr, self.type()) - raise exception.StackValidationFailed(message=msg) + self._validate_against_facade(facade_cls) return super(TemplateResource, self).validate() -- 2.45.2