From: shangxdy <shang.xiaodong@zte.com.cn>
Date: Tue, 14 Jun 2016 16:24:41 +0000 (+0800)
Subject: The grouptype's parent_type definition is error
X-Git-Tag: colorado.1.0~63^2
X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F49%2F15549%2F3;p=parser.git

The grouptype's parent_type definition is error

1. Group type define parent_type, but it shall be statuefulentity, not string,
 so the method of is_derived_from in group entity may be error when it's called.
2. The bug will submit to openstack community.

Change-Id: I6e78b9dbf9ad0593db9246d34be29d8ec6f092ed
JIRA: PARSER-54
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
---

diff --git a/tosca2heat/tosca-parser/toscaparser/elements/grouptype.py b/tosca2heat/tosca-parser/toscaparser/elements/grouptype.py
index ec5571c..5587f05 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/grouptype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/grouptype.py
@@ -51,6 +51,17 @@ class GroupType(StatefulEntityType):
             self.meta_data = self.defs[self.METADATA]
             self._validate_metadata(self.meta_data)
 
+    @property
+    def parent_type(self):
+        '''Return a group statefulentity of this entity is derived from.'''
+        if not hasattr(self, 'defs'):
+            return None
+        pgroup_entity = self.derived_from(self.defs)
+        if pgroup_entity:
+            return GroupType(pgroup_entity, self.custom_def)
+        else:
+            return None
+
     @property
     def description(self):
         return self.group_description
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
index f0a87ac..9c2ce35 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
@@ -60,6 +60,7 @@ class ToscaDefTest(TestCase):
 
     def test_group(self):
         self.assertEqual(group_type.type, "tosca.groups.Root")
+        self.assertEqual(group_type.parent_type, None)
         self.assertIn(ifaces.LIFECYCLE_SHORTNAME, group_type.interfaces)
 
     def test_capabilities(self):