toscaparser: Support deriving from capability types of no property 64/67664/2
authorLianhao Lu <lianhao.lu@intel.com>
Mon, 22 Apr 2019 05:48:41 +0000 (13:48 +0800)
committerLianhao Lu <lianhao.lu@intel.com>
Mon, 22 Apr 2019 07:09:21 +0000 (15:09 +0800)
Change-Id: I259a43b72a4dd3c74ad54a250ada9f913b5ce67b
Issue-ID: PARSER-188
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
tosca2heat/tosca-parser/toscaparser/tests/test_properties.py

index 23c5afc..c37aa9d 100644 (file)
@@ -35,7 +35,7 @@ class CapabilityTypeDef(StatefulEntityType):
         parent_properties = {}
         if self.parent_capabilities:
             for type, value in self.parent_capabilities.items():
-                parent_properties[type] = value.get('properties')
+                parent_properties[type] = value.get('properties', {})
         if self.properties:
             for prop, schema in self.properties.items():
                 properties.append(PropertyDef(prop, None, schema))
index 6b95537..faa8af4 100644 (file)
@@ -314,6 +314,31 @@ class PropertyTest(TestCase):
                      num_cpus: 1
         '''
 
+        tosca_custom_def_example3 = '''
+          tosca.capabilities.New:
+            derived_from: tosca.capabilities.Node
+            properties:
+              test_case:
+                type: integer
+                required: yes
+
+          tosca.nodes.ComputeNew:
+            derived_from: tosca.nodes.Compute
+            capabilities:
+              scalable:
+                type: tosca.capabilities.New
+        '''
+
+        tosca_node_template_example3 = '''
+          node_templates:
+            compute_instance:
+              type: tosca.nodes.ComputeNew
+              capabilities:
+                scalable:
+                  properties:
+                    test_case: 1
+        '''
+
         tpl1 = self._get_nodetemplate(tosca_node_template_example1,
                                       tosca_custom_def_example1)
         self.assertIsNone(tpl1.validate())
@@ -322,6 +347,10 @@ class PropertyTest(TestCase):
                                       tosca_custom_def_example2)
         self.assertIsNone(tpl2.validate())
 
+        tpl3 = self._get_nodetemplate(tosca_node_template_example3,
+                                      tosca_custom_def_example3)
+        self.assertIsNone(tpl3.validate())
+
     def _get_nodetemplate(self, tpl_snippet,
                           custom_def_snippet=None):
         nodetemplates = yamlparser.\