From 17e537a2d8deb63ef4cb70cd464beb45d1282e3b Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 17 May 2018 16:56:45 +0200 Subject: [PATCH 1/2] Check if inf id exists before deleting --- IM/InfrastructureList.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IM/InfrastructureList.py b/IM/InfrastructureList.py index 9ced7042a..e53140169 100644 --- a/IM/InfrastructureList.py +++ b/IM/InfrastructureList.py @@ -56,7 +56,8 @@ def remove_inf(del_inf): """Remove destroyed infrastructure.""" with InfrastructureList._lock: - del InfrastructureList.infrastructure_list[del_inf.id] + if del_inf.id in InfrastructureList.infrastructure_list: + del InfrastructureList.infrastructure_list[del_inf.id] @staticmethod def get_inf_ids(auth=None): From 520c06bc77572e9d41643f1d404a18def6ffc3d5 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 21 May 2018 08:43:58 +0200 Subject: [PATCH 2/2] Implements #614 --- IM/tosca/Tosca.py | 25 ++++++++++++++----------- test/files/tosca_long.yml | 2 +- test/unit/Tosca.py | 2 ++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index ffdc74cda..50f9e4633 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -44,9 +44,9 @@ def serialize(self): def deserialize(str_data): return Tosca(str_data) - def _get_cloud_id(self, sys_name): + def _get_placement_property(self, sys_name, prop): """ - Get the cloud ID of the deployment based on policies + Get the specified property of the deployment based on policies """ for policy in self.tosca.policies: if policy.type_definition.type == "tosca.policies.Placement": @@ -59,10 +59,11 @@ def _get_cloud_id(self, sys_name): for node in node_list: if node.name == sys_name: - if 'cloud_id' in policy.properties: - Tosca.logger.debug("Set cloud id: %s to system: %s." % (policy.properties['cloud_id'], - sys_name)) - return policy.properties['cloud_id'] + if prop in policy.properties: + Tosca.logger.debug("Set %s: %s to system: %s." % (prop, + policy.properties[prop], + sys_name)) + return policy.properties[prop] else: Tosca.logger.warn("Policy %s not supported. Ignoring it." % policy.type_definition.type) @@ -108,8 +109,7 @@ def to_radl(self, inf_info=None): sys = self._gen_system(node, self.tosca.nodetemplates) # add networks using the simple method with the public_ip # property - self._add_node_nets( - node, radl, sys, self.tosca.nodetemplates) + self._add_node_nets(node, radl, sys, self.tosca.nodetemplates) radl.systems.append(sys) # Add the deploy element for this system min_instances, _, default_instances, count, removal_list = self._get_scalable_properties( @@ -135,14 +135,13 @@ def to_radl(self, inf_info=None): all_removal_list.extend(removal_list[0:-num_instances]) if num_instances > 0: - cloud_id = self._get_cloud_id(sys.name) + cloud_id = self._get_placement_property(sys.name, "cloud_id") dep = deploy(sys.name, num_instances, cloud_id) radl.deploys.append(dep) compute = node else: # Select the host to host this element - compute = self._find_host_compute( - node, self.tosca.nodetemplates) + compute = self._find_host_compute(node, self.tosca.nodetemplates) if not compute: Tosca.logger.warn( "Node %s has not compute node to host in." % node.name) @@ -1259,6 +1258,10 @@ def _gen_system(self, node, nodetemplates): self._add_ansible_roles(node, nodetemplates, res) + availability_zone = self._get_placement_property(res.name, "availability_zone") + if availability_zone: + res.setValue('availability_zone', availability_zone) + return res @staticmethod diff --git a/test/files/tosca_long.yml b/test/files/tosca_long.yml index 0254eef1e..bba639952 100644 --- a/test/files/tosca_long.yml +++ b/test/files/tosca_long.yml @@ -179,7 +179,7 @@ topology_template: policies: - deploy_on_cloudid: type: tosca.policies.Placement - properties: { cloud_id: cloudid } + properties: { cloud_id: cloudid, availability_zone: some_zone } targets: [ other_server ] - deploy_group_on_cloudid: diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 89b8546ca..e5d3bc3e1 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -71,6 +71,8 @@ def test_tosca_to_radl(self): self.assertEqual("cloudid", radl.deploys[0].cloud_id) self.assertEqual("cloudid", radl.deploys[1].cloud_id) self.assertEqual("cloudid", radl.deploys[2].cloud_id) + other_server = radl.get_system_by_name('other_server') + self.assertEqual(other_server.getValue("availability_zone"), 'some_zone') def test_tosca_get_outputs(self): """Test TOSCA get_outputs function"""