EntityTemplate has no property of parent_type 05/15505/4
authorshangxdy <shang.xiaodong@zte.com.cn>
Tue, 14 Jun 2016 07:28:35 +0000 (15:28 +0800)
committershangxdy <shang.xiaodong@zte.com.cn>
Thu, 16 Jun 2016 12:13:19 +0000 (20:13 +0800)
1. EntityTemplate is the parent of NodeTemplate,but there is no definition
of parent_type definition, so the method of is_derived_from will be error
when call the parent_type's method.
2. The bug will submit to openstack community.

Change-Id: If6d360932fd610f001934d23aac63e11ac16fddf
JIRA: PARSER-51
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
tosca2heat/tosca-parser/toscaparser/entity_template.py
tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py

index 281012b..f416c99 100644 (file)
@@ -81,6 +81,15 @@ class EntityTemplate(object):
     def type(self):
         if self.type_definition:
             return self.type_definition.type
+        else:
+            return None
+
+    @property
+    def parent_type(self):
+        if self.type_definition:
+            return self.type_definition.parent_type
+        else:
+            return None
 
     @property
     def requirements(self):
index 3fd49bf..efc71fd 100644 (file)
@@ -134,6 +134,19 @@ class ToscaTemplateTest(TestCase):
                 self.assertEqual('Linux', os_props['type'].value)
                 self.assertEqual('Linux', os_type_prop)
 
+    def test_node_inheritance_type(self):
+        wordpress_node = [
+            node for node in self.tosca.nodetemplates
+            if node.name == 'wordpress'][0]
+        self.assertTrue(
+            wordpress_node.is_derived_from("tosca.nodes.WebApplication"))
+        self.assertTrue(
+            wordpress_node.is_derived_from("tosca.nodes.Root"))
+        self.assertFalse(
+            wordpress_node.is_derived_from("tosca.policies.Root"))
+        self.assertFalse(
+            wordpress_node.is_derived_from("tosca.groups.Root"))
+
     def test_outputs(self):
         self.assertEqual(
             ['website_url'],