]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make the new template validation usable from tests
authorAngus Salkeld <asalkeld@redhat.com>
Thu, 5 Sep 2013 01:16:55 +0000 (11:16 +1000)
committerSteve Baker <sbaker@redhat.com>
Fri, 6 Sep 2013 23:03:41 +0000 (11:03 +1200)
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

index 219fca05721f2a535905cfe5a8f49251c0b8e606..50bb37f73be2ee187a3335d104efc7fed3c59768 100644 (file)
@@ -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()