summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py14
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/entity_type.py9
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/policytype.py11
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py2
-rw-r--r--tosca2heat/tosca-parser/toscaparser/entity_template.py9
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py22
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py17
-rw-r--r--tosca2heat/tosca-parser/tox.ini2
8 files changed, 66 insertions, 20 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py b/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py
index 3bfd7d0..887e99a 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/artifacttype.py
@@ -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,17 +28,24 @@ 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':
+ # only support normative artifact, shall be modified future
artifacts[parent_artif] = self.TOSCA_DEF[parent_artif]
parent_artif = artifacts[parent_artif]['derived_from']
return artifacts
@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)
+ else:
+ return None
def get_artifact(self, name):
'''Return the definition of an artifact field by name.'''
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py b/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py
index 5d620a5..72e7e3f 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/entity_type.py
@@ -106,8 +106,13 @@ class EntityType(object):
value[k] = v
if isinstance(value, list):
for p_value in parent_value:
- if p_value not in value:
- value.append(p_value)
+ if isinstance(p_value, dict):
+ if p_value.keys()[0] not in [
+ item.keys()[0] for item in value]:
+ value.append(p_value)
+ else:
+ if p_value not in value:
+ value.append(p_value)
else:
value = copy.copy(parent_value)
p = p.parent_type
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/elements/relationshiptype.py b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py
index 9462d38..25440ca 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py
@@ -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):
diff --git a/tosca2heat/tosca-parser/toscaparser/entity_template.py b/tosca2heat/tosca-parser/toscaparser/entity_template.py
index 281012b..f416c99 100644
--- a/tosca2heat/tosca-parser/toscaparser/entity_template.py
+++ b/tosca2heat/tosca-parser/toscaparser/entity_template.py
@@ -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):
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
index f0a87ac..7c29e67 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
@@ -188,8 +188,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 +199,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 +213,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 +228,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 +245,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 +264,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 +283,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 +297,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 +309,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 +321,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 '
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
index 3fd49bf..ac55059 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
@@ -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'],
@@ -211,6 +224,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,
@@ -728,5 +743,7 @@ 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")
diff --git a/tosca2heat/tosca-parser/tox.ini b/tosca2heat/tosca-parser/tox.ini
index 9e5f365..d646b6e 100644
--- a/tosca2heat/tosca-parser/tox.ini
+++ b/tosca2heat/tosca-parser/tox.ini
@@ -1,6 +1,6 @@
[tox]
minversion = 1.6
-envlist = py34,py27,pypy,pep8
+envlist = py34,py27,pep8
skipsdist = True
[testenv]