From 35d047bcd376b70c9b8f8b2cd87c228e42bcc7e1 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 7 Jun 2019 10:21:47 +0200 Subject: [PATCH] Fix #853 --- IM/InfrastructureManager.py | 12 ++++++++++-- IM/VirtualMachine.py | 15 ++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/IM/InfrastructureManager.py b/IM/InfrastructureManager.py index acba6ac59..c0eac8452 100644 --- a/IM/InfrastructureManager.py +++ b/IM/InfrastructureManager.py @@ -512,6 +512,8 @@ def AddResource(inf_id, radl_data, auth, context=True): sel_inf.update_radl(radl, []) InfrastructureManager.logger.warn("Inf ID: " + sel_inf.id + ": without any deploy. Exiting.") sel_inf.add_cont_msg("Infrastructure without any deploy. Exiting.") + if sel_inf.configured is None: + sel_inf.configured = False return [] except Exception as ex: sel_inf.configured = False @@ -570,6 +572,8 @@ def AddResource(inf_id, radl_data, auth, context=True): if not deploy_group: InfrastructureManager.logger.warning("Inf ID: %s: No VMs to deploy!" % sel_inf.id) sel_inf.add_cont_msg("No VMs to deploy. Exiting.") + if sel_inf.configured is None: + sel_inf.configured = False return [] cloud_id = deploys_group_cloud[id(deploy_group)] @@ -901,14 +905,15 @@ def GetInfrastructureState(inf_id, auth): sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth) + vm_list = sel_inf.get_vm_list() vm_states = {} - for vm in sel_inf.get_vm_list(): + for vm in vm_list: # First try to update the status of the VM vm.update_status(auth) vm_states[str(vm.im_id)] = vm.state state = None - for vm in sel_inf.get_vm_list(): + for vm in vm_list: # First try to update the status of the VM if vm.state == VirtualMachine.FAILED: state = VirtualMachine.FAILED @@ -937,6 +942,9 @@ def GetInfrastructureState(inf_id, auth): if state is None: if sel_inf.configured is False: state = VirtualMachine.FAILED + elif not vm_list and sel_inf.configured is None: + # if there are no vms we probably are in the vm creation process + state = VirtualMachine.PENDING else: state = VirtualMachine.UNKNOWN diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index 4476cfea2..c9a18a2d0 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -505,24 +505,25 @@ def update_status(self, auth, force=False): updated = False # To avoid to refresh the information too quickly if force or now - self.last_update > Config.VM_INFO_UPDATE_FREQUENCY: + success = False try: (success, new_vm) = self.getCloudConnector().updateVMInfo(self, auth) if success: state = new_vm.state updated = True self.last_update = now - elif self.creating: - self.log_info("VM is in creation process, set pending state") - state = VirtualMachine.PENDING else: self.log_error("Error updating VM status: %s" % new_vm) - except: + except Exception: self.log_exception("Error updating VM status.") - updated = False + + if not success and self.creating: + self.log_info("VM is in creation process, set pending state") + state = VirtualMachine.PENDING # If we have problems to update the VM info too much time, set to - # unknown - if now - self.last_update > Config.VM_INFO_UPDATE_ERROR_GRACE_PERIOD: + # unknown unless we are still creating the VM + if now - self.last_update > Config.VM_INFO_UPDATE_ERROR_GRACE_PERIOD and not self.creating: new_state = VirtualMachine.UNKNOWN self.log_warn("Grace period to update VM info passed. Set state to 'unknown'") else: