diff --git a/IM/CloudInfo.py b/IM/CloudInfo.py index 4e9c864a6..60f70a321 100644 --- a/IM/CloudInfo.py +++ b/IM/CloudInfo.py @@ -72,7 +72,7 @@ def get_cloud_list(auth_data): res = [] for i, auth in enumerate(auth_data.auth_list): - if auth['type'] not in ['InfrastructureManager', 'VMRC']: + if 'type' in auth and auth['type'] not in ['InfrastructureManager', 'VMRC']: cloud_item = CloudInfo() cloud_item.type = auth['type'] if 'id' in auth.keys() and auth['id']: diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 2aaa87e90..a79845e4b 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -142,7 +142,7 @@ def get_instance_type(self, system, credentials, subscription_id): disk_free_op = ">=" if system.getValue('disks.free_size'): disk_free = system.getFeature('disks.free_size').getValue('M') - disk_free_op = system.getFeature('memory.size').getLogOperator() + disk_free_op = system.getFeature('disks.free_size').getLogOperator() compute_client = ComputeManagementClient(credentials, subscription_id) instace_types = list(compute_client.virtual_machine_sizes.list(location)) @@ -555,11 +555,7 @@ def create_vms(self, inf, radl, requested_radl, num_vm, location, storage_accoun # Delete Resource group and everything in it if group_name: - self.log_info("Delete Resource group %s and everything in it." % group_name) - try: - resource_client.resource_groups.delete(group_name).wait() - except: - self.log_exception("Error deleting Resource group %s." % group_name) + self.delete_resource_group(group_name, resource_client) i += 1 @@ -604,11 +600,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data): ).wait() except: self.log_exception("Error creating storage account: %s" % storage_account) - self.log_info("Delete Inf RG group %s" % "rg-%s" % inf.id) - try: - resource_client.resource_groups.delete("rg-%s" % inf.id) - except: - pass + self.delete_resource_group("rg-%s" % inf.id, resource_client) subnets = self.create_nets(radl, credentials, subscription_id, "rg-%s" % inf.id) @@ -635,11 +627,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data): if remaining_vms > 0: # Remove the general group - self.log_info("Delete Inf RG group %s" % "rg-%s" % inf.id) - try: - resource_client.resource_groups.delete("rg-%s" % inf.id) - except: - pass + self.delete_resource_group("rg-%s" % inf.id, resource_client) else: self.log_info("All VMs created successfully.") @@ -757,16 +745,14 @@ def finalize(self, vm, last, auth_data): # Delete Resource group and everything in it if self.get_rg(group_name, credentials, subscription_id): - self.log_info("Removing RG: %s" % group_name) - resource_client.resource_groups.delete(group_name).wait() + self.delete_resource_group(group_name, resource_client) else: self.log_info("RG: %s does not exist. Do not remove." % group_name) # if it is the last VM delete the RG of the Inf if last: if self.get_rg("rg-%s" % vm.inf.id, credentials, subscription_id): - self.log_info("Removing Inf. RG: %s" % "rg-%s" % vm.inf.id) - resource_client.resource_groups.delete("rg-%s" % vm.inf.id) + self.delete_resource_group("rg-%s" % vm.inf.id, resource_client) else: self.log_info("RG: %s does not exist. Do not remove." % "rg-%s" % vm.inf.id) @@ -831,3 +817,26 @@ def alterVM(self, vm, radl, auth_data): return False, "Error altering the VM: " + str(ex) return (True, "") + + def delete_resource_group(self, group_name, resource_client, max_retries=3): + """ + Delete a RG with retries + """ + cont = 0 + deleted = False + + self.log_info("Delete RG %s." % group_name) + while cont < max_retries and not deleted: + cont += 1 + try: + resource_client.resource_groups.delete(group_name).wait() + deleted = True + except: + self.log_exception("Error deleting Resource group %s (%d/%d)." % (group_name, cont, max_retries)) + + if not deleted: + self.log_error("Resource group %s cannot be deleted!!!" % group_name) + else: + self.log_info("Resource group %s successfully deleted." % group_name) + + return deleted diff --git a/IM/connectors/AzureClassic.py b/IM/connectors/AzureClassic.py index 036c82687..db958727b 100644 --- a/IM/connectors/AzureClassic.py +++ b/IM/connectors/AzureClassic.py @@ -755,7 +755,7 @@ def get_instance_type(self, system, auth_data): disk_free_op = ">=" if system.getValue('disks.free_size'): disk_free = system.getFeature('disks.free_size').getValue('M') - disk_free_op = system.getFeature('memory.size').getLogOperator() + disk_free_op = system.getFeature('disks.free_size').getLogOperator() instace_types = self.get_all_instance_types(auth_data) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index d1d633565..3f289fdc5 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -283,7 +283,7 @@ def get_instance_type(self, radl, vpc=None): disk_free_op = ">=" if radl.getValue('disks.free_size'): disk_free = radl.getFeature('disks.free_size').getValue('G') - disk_free_op = radl.getFeature('memory.size').getLogOperator() + disk_free_op = radl.getFeature('disks.free_size').getLogOperator() performance = 0 performance_op = ">=" diff --git a/IM/connectors/OpenNebula.py b/IM/connectors/OpenNebula.py index fd223381d..05644f835 100644 --- a/IM/connectors/OpenNebula.py +++ b/IM/connectors/OpenNebula.py @@ -941,19 +941,16 @@ def get_networks_template(self, radl, sgs, auth_data): for public in [True, False]: i = 0 while system.getValue("net_interface." + str(i) + ".connection"): - network = system.getValue( - "net_interface." + str(i) + ".connection") + network = system.getValue("net_interface." + str(i) + ".connection") fixed_ip = system.getValue("net_interface." + str(i) + ".ip") # get the one network info - if nets[network]: + if network in nets and nets[network]: (net_name, net_id, is_public) = nets[network] radl.get_network_by_id(network).setValue('provider_id', str(net_name)) else: - self.log_error( - "No ONE network found for network: " + network) - raise Exception( - "No ONE network found for network: " + network) + self.log_error("No ONE network found for network: " + network) + raise Exception("No ONE network found for network: " + network) if public == is_public: if net_id is not None: diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 5afbb82bd..4ee13997f 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -53,6 +53,19 @@ def __init__(self, cloud_info, inf): self.add_public_ip_count = 0 LibCloudCloudConnector.__init__(self, cloud_info, inf) + def get_node_with_id(self, node_id, auth_data): + """ + Get the node with the specified ID + + Arguments: + - node_id(str): ID of the node to get + - auth(Authentication): parsed authentication tokens. + Returns: a :py:class:`libcloud.compute.base.Node` with the node info + """ + driver = self.get_driver(auth_data) + node = driver.ex_get_node_details(node_id) + return node + def get_driver(self, auth_data): """ Get the driver from the auth data @@ -171,9 +184,9 @@ def get_instance_type(self, sizes, radl): memory_op = radl.getFeature('memory.size').getLogOperator() disk_free = 0 disk_free_op = ">=" - if radl.getValue('disk.0.free_size'): - disk_free = radl.getFeature('disk.0.free_size').getValue('G') - disk_free_op = radl.getFeature('memory.size').getLogOperator() + if radl.getValue('disks.free_size'): + disk_free = radl.getFeature('disks.free_size').getValue('G') + disk_free_op = radl.getFeature('disks.free_size').getLogOperator() # get the node size with the lowest price, vcpus and memory sizes.sort(key=lambda x: (x.price, x.vcpus, x.ram)) diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 3402a68d1..4372a9892 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -240,7 +240,7 @@ def test_30_updateVMInfo(self, get_driver): node.public_ips = [] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node node_size = MagicMock() node_size.ram = 512 @@ -308,7 +308,7 @@ def test_40_stop(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node driver.ex_stop_node.return_value = True @@ -336,7 +336,7 @@ def test_50_start(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node driver.ex_start_node.return_value = True @@ -386,7 +386,7 @@ def test_55_alter(self, get_driver): node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node node_size = MagicMock() node_size.ram = 2048 @@ -435,7 +435,7 @@ def test_60_finalize(self, sleep, get_driver): node.private_ips = ['10.0.0.1'] node.driver = driver node.destroy.return_value = True - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node keypair = MagicMock() driver.get_key_pair.return_value = keypair @@ -468,7 +468,7 @@ def test_70_create_snapshot(self, get_driver): node = MagicMock() node.id = "1" node.driver = driver - driver.list_nodes.return_value = [node] + driver.ex_get_node_details.return_value = node image = MagicMock() image.id = "newimage" driver.create_image.return_value = image