incorrect parent_type definition in policy,artifacts, group and policy
Policytype, GroupType, ArtifactsType and RelationshipType which are derived from statefulentity defines parent_type, but theirs value shall be type objects, not a string, so the method of is_derived_from in policy entity may be error currently. Closes-Bug: https://bugs.launchpad.net/tosca-parser/+bug/1597443 Change-Id: Iaf250922ac22a36f0fc74c4a465e4e73b8edcd01 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
This commit is contained in:
parent
47ad5c7df3
commit
d4e01afe3b
@ -20,6 +20,7 @@ class ArtifactTypeDef(StatefulEntityType):
|
||||
super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX,
|
||||
custom_def)
|
||||
self.type = atype
|
||||
self.custom_def = custom_def
|
||||
self.properties = None
|
||||
if self.PROPERTIES in self.defs:
|
||||
self.properties = self.defs[self.PROPERTIES]
|
||||
@ -27,7 +28,7 @@ class ArtifactTypeDef(StatefulEntityType):
|
||||
|
||||
def _get_parent_artifacts(self):
|
||||
artifacts = {}
|
||||
parent_artif = self.parent_type
|
||||
parent_artif = self.parent_type.type if self.parent_type else None
|
||||
if parent_artif:
|
||||
while parent_artif != 'tosca.artifacts.Root':
|
||||
artifacts[parent_artif] = self.TOSCA_DEF[parent_artif]
|
||||
@ -36,8 +37,12 @@ class ArtifactTypeDef(StatefulEntityType):
|
||||
|
||||
@property
|
||||
def parent_type(self):
|
||||
'''Return an artifact this artifact is derived from.'''
|
||||
return self.derived_from(self.defs)
|
||||
'''Return a artifact entity from which this entity is derived.'''
|
||||
if not hasattr(self, 'defs'):
|
||||
return None
|
||||
partifact_entity = self.derived_from(self.defs)
|
||||
if partifact_entity:
|
||||
return ArtifactTypeDef(partifact_entity, self.custom_def)
|
||||
|
||||
def get_artifact(self, name):
|
||||
'''Return the definition of an artifact field by name.'''
|
||||
|
@ -51,6 +51,15 @@ 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)
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self.group_description
|
||||
|
@ -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.'''
|
||||
|
@ -26,7 +26,7 @@ class RelationshipType(StatefulEntityType):
|
||||
'''Return a relationship this reletionship is derived from.'''
|
||||
prel = self.derived_from(self.defs)
|
||||
if prel:
|
||||
return RelationshipType(prel)
|
||||
return RelationshipType(prel, self.custom_def)
|
||||
|
||||
@property
|
||||
def valid_target_types(self):
|
||||
|
@ -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):
|
||||
@ -188,8 +189,9 @@ class ToscaDefTest(TestCase):
|
||||
self.assertIn(ifaces.LIFECYCLE_SHORTNAME, root_node.interfaces)
|
||||
|
||||
def test_artifacts(self):
|
||||
self.assertEqual(artif_root_type.parent_type, None)
|
||||
self.assertEqual('tosca.artifacts.Root',
|
||||
artif_file_type.parent_type)
|
||||
artif_file_type.parent_type.type)
|
||||
self.assertEqual({}, artif_file_type.parent_artifacts)
|
||||
self.assertEqual(sorted(['tosca.artifacts.Root'],
|
||||
key=lambda x: str(x)),
|
||||
@ -198,7 +200,7 @@ class ToscaDefTest(TestCase):
|
||||
key=lambda x: str(x)))
|
||||
|
||||
self.assertEqual('tosca.artifacts.Implementation',
|
||||
artif_bash_type.parent_type)
|
||||
artif_bash_type.parent_type.type)
|
||||
self.assertEqual({'tosca.artifacts.Implementation':
|
||||
{'derived_from': 'tosca.artifacts.Root',
|
||||
'description':
|
||||
@ -212,7 +214,7 @@ class ToscaDefTest(TestCase):
|
||||
key=lambda x: str(x)))
|
||||
|
||||
self.assertEqual('tosca.artifacts.Implementation',
|
||||
artif_python_type.parent_type)
|
||||
artif_python_type.parent_type.type)
|
||||
self.assertEqual({'tosca.artifacts.Implementation':
|
||||
{'derived_from': 'tosca.artifacts.Root',
|
||||
'description':
|
||||
@ -227,7 +229,7 @@ class ToscaDefTest(TestCase):
|
||||
key=lambda x: str(x)))
|
||||
|
||||
self.assertEqual('tosca.artifacts.Deployment.Image',
|
||||
artif_container_docker_type.parent_type)
|
||||
artif_container_docker_type.parent_type.type)
|
||||
self.assertEqual({'tosca.artifacts.Deployment':
|
||||
{'derived_from': 'tosca.artifacts.Root',
|
||||
'description':
|
||||
@ -244,7 +246,7 @@ class ToscaDefTest(TestCase):
|
||||
key=lambda x: str(x)))
|
||||
|
||||
self.assertEqual('tosca.artifacts.Deployment.Image',
|
||||
artif_vm_iso_type.parent_type)
|
||||
artif_vm_iso_type.parent_type.type)
|
||||
self.assertEqual({'tosca.artifacts.Deployment':
|
||||
{'derived_from': 'tosca.artifacts.Root',
|
||||
'description':
|
||||
@ -263,7 +265,7 @@ class ToscaDefTest(TestCase):
|
||||
key=lambda x: str(x)))
|
||||
|
||||
self.assertEqual('tosca.artifacts.Deployment.Image',
|
||||
artif_vm_qcow2_type.parent_type)
|
||||
artif_vm_qcow2_type.parent_type.type)
|
||||
self.assertEqual({'tosca.artifacts.Deployment':
|
||||
{'derived_from': 'tosca.artifacts.Root',
|
||||
'description':
|
||||
@ -282,8 +284,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 +298,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 +310,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 +322,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 '
|
||||
|
@ -223,6 +223,8 @@ class ToscaTemplateTest(TestCase):
|
||||
for key in relation.keys():
|
||||
rel_tpl = relation.get(key).get_relationship_template()
|
||||
if rel_tpl:
|
||||
self.assertTrue(rel_tpl[0].is_derived_from(
|
||||
"tosca.relationships.Root"))
|
||||
interfaces = rel_tpl[0].interfaces
|
||||
for interface in interfaces:
|
||||
self.assertEqual(config_interface,
|
||||
@ -688,6 +690,8 @@ class ToscaTemplateTest(TestCase):
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
for policy in tosca.topology_template.policies:
|
||||
self.assertTrue(
|
||||
policy.is_derived_from("tosca.policies.Root"))
|
||||
if policy.name == 'my_compute_placement_policy':
|
||||
self.assertEqual('tosca.policies.Placement', policy.type)
|
||||
self.assertEqual(['my_server_1', 'my_server_2'],
|
||||
@ -708,6 +712,8 @@ class ToscaTemplateTest(TestCase):
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
|
||||
for policy in tosca.topology_template.policies:
|
||||
self.assertTrue(
|
||||
policy.is_derived_from("tosca.policies.Root"))
|
||||
if policy.name == 'my_groups_placement':
|
||||
self.assertEqual('mycompany.mytypes.myScalingPolicy',
|
||||
policy.type)
|
||||
@ -752,6 +758,8 @@ class ToscaTemplateTest(TestCase):
|
||||
"data/test_tosca_custom_rel_with_script.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
rel = tosca.relationship_templates[0]
|
||||
self.assertEqual(rel.type, "tosca.relationships.HostedOn")
|
||||
self.assertTrue(rel.is_derived_from("tosca.relationships.Root"))
|
||||
self.assertEqual(len(rel.interfaces), 1)
|
||||
self.assertEqual(rel.interfaces[0].type, "Configure")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user