summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjulien zhang <zhang.jun3g@zte.com.cn>2016-06-30 16:25:42 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-30 16:25:42 +0000
commit467b0d29ca83943cc028d776a7cd97522a99644a (patch)
tree69c92ffe22a11eed47659650395805102e084591
parent5359c6d752c29d10d8c0459f47bb7697203f1515 (diff)
parentdc0e2e51304dbc085546ee869617d9c545610667 (diff)
Merge "The policytype's parent_type definition is error"
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/policytype.py11
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py9
2 files changed, 13 insertions, 7 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/policytype.py b/tosca2heat/tosca-parser/toscaparser/elements/policytype.py
index 04cbab5..8fbb0f0 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/policytype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/policytype.py
@@ -28,6 +28,7 @@ class PolicyType(StatefulEntityType):
super(PolicyType, self).__init__(ptype, self.POLICY_PREFIX,
custom_def)
self.type = ptype
+ self.custom_def = custom_def
self._validate_keys()
self.meta_data = None
@@ -55,7 +56,7 @@ class PolicyType(StatefulEntityType):
def _get_parent_policies(self):
policies = {}
- parent_policy = self.parent_type
+ parent_policy = self.parent_type.type if self.parent_type else None
if parent_policy:
while parent_policy != 'tosca.policies.Root':
policies[parent_policy] = self.TOSCA_DEF[parent_policy]
@@ -64,8 +65,12 @@ class PolicyType(StatefulEntityType):
@property
def parent_type(self):
- '''Return a policy this policy is derived from.'''
- return self.derived_from(self.defs)
+ '''Return a policy statefulentity of this node is derived from.'''
+ if not hasattr(self, 'defs'):
+ return None
+ ppolicy_entity = self.derived_from(self.defs)
+ if ppolicy_entity:
+ return PolicyType(ppolicy_entity, self.custom_def)
def get_policy(self, name):
'''Return the definition of a policy field by name.'''
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
index f0a87ac..104fab3 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
@@ -282,8 +282,9 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
def test_policies(self):
+ self.assertEqual(policy_root_type.parent_type, None)
self.assertEqual('tosca.policies.Root',
- policy_placement_type.parent_type)
+ policy_placement_type.parent_type.type)
self.assertEqual({}, policy_placement_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -295,7 +296,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_scaling_type.parent_type)
+ policy_scaling_type.parent_type.type)
self.assertEqual({}, policy_scaling_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -307,7 +308,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_update_type.parent_type)
+ policy_update_type.parent_type.type)
self.assertEqual({}, policy_update_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -319,7 +320,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_performance_type.parent_type)
+ policy_performance_type.parent_type.type)
self.assertEqual({}, policy_performance_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '