X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns_thread.py;h=6336d9e60f50d5174228ec788f8016614f3f44a9;hb=33b7503d75a1f44f782224be5cadcbed9bd3d03c;hp=edf1bbffde904ae0e548a8577f955495751d3b78;hpb=60036703a8343474a54d60d2dbff89109c6b0a34;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index edf1bbff..6336d9e6 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -489,8 +489,10 @@ class VimInteractionVdu(VimInteractionBase): vim_info_info = yaml.safe_load(vim_info["vim_info"]) if vim_info_info.get("name"): vim_info["name"] = vim_info_info["name"] - except Exception: - pass + except Exception as vim_info_error: + self.logger.exception( + f"{vim_info_error} occured while getting the vim_info from yaml" + ) except vimconn.VimConnException as e: # Mark all tasks at VIM_ERROR status self.logger.error( @@ -730,7 +732,7 @@ class VimInteractionFlavor(VimInteractionBase): flavor_data = task["find_params"]["flavor_data"] vim_flavor_id = target_vim.get_flavor_id_from_data(flavor_data) except vimconn.VimConnNotFoundException: - pass + self.logger.exception("VimConnNotFoundException occured.") if not vim_flavor_id and task.get("params"): # CREATE @@ -975,7 +977,6 @@ class VimInteractionSdnNet(VimInteractionBase): return self.new(ro_task, task_create_index, None) def new(self, ro_task, task_index, task_depends): - task = ro_task["tasks"][task_index] task_id = task["task_id"] target_vim = self.my_vims[ro_task["target_id"]] @@ -1385,7 +1386,9 @@ class NsWorker(threading.Thread): try: mkdir(file_name) except FileExistsError: - pass + self.logger.exception( + "FileExistsError occured while processing vim_config." + ) file_name = file_name + "/ca_cert" @@ -1438,7 +1441,8 @@ class NsWorker(threading.Thread): self.logger.info("Unloaded {}".format(target_id)) rmtree("{}:{}".format(target_id, self.worker_index)) except FileNotFoundError: - pass # this is raised by rmtree if folder does not exist + # This is raised by rmtree if folder does not exist. + self.logger.exception("FileNotFoundError occured while unloading VIM.") except Exception as e: self.logger.error("Cannot unload {}: {}".format(target_id, e)) @@ -1987,18 +1991,15 @@ class NsWorker(threading.Thread): return ro_task_dependency, task_index raise NsWorkerException("Cannot get depending task {}".format(task_id)) - def update_vm_refresh(self): + def update_vm_refresh(self, ro_task): """Enables the VM status updates if self.refresh_config.active parameter - is not -1 and than updates the DB accordingly + is not -1 and then updates the DB accordingly """ try: self.logger.debug("Checking if VM status update config") next_refresh = time.time() - if self.refresh_config.active == -1: - next_refresh = -1 - else: - next_refresh += self.refresh_config.active + next_refresh = self._get_next_refresh(ro_task, next_refresh) if next_refresh != -1: db_ro_task_update = {} @@ -2033,6 +2034,23 @@ class NsWorker(threading.Thread): except Exception as e: self.logger.error(f"Error updating tasks to enable VM status updates: {e}") + def _get_next_refresh(self, ro_task: dict, next_refresh: float): + """Decide the next_refresh according to vim type and refresh config period. + Args: + ro_task (dict): ro_task details + next_refresh (float): next refresh time as epoch format + + Returns: + next_refresh (float) -1 if vm updates are disabled or vim type is openstack. + """ + target_vim = ro_task["target_id"] + vim_type = self.db_vims[target_vim]["vim_type"] + if self.refresh_config.active == -1 or vim_type == "openstack": + next_refresh = -1 + else: + next_refresh += self.refresh_config.active + return next_refresh + def _process_pending_tasks(self, ro_task): ro_task_id = ro_task["_id"] now = time.time() @@ -2054,10 +2072,7 @@ class NsWorker(threading.Thread): elif new_status == "BUILD": next_refresh += self.refresh_config.build elif new_status == "DONE": - if self.refresh_config.active == -1: - next_refresh = -1 - else: - next_refresh += self.refresh_config.active + next_refresh = self._get_next_refresh(ro_task, next_refresh) else: next_refresh += self.refresh_config.error @@ -2072,7 +2087,7 @@ class NsWorker(threading.Thread): self._log_ro_task(ro_task, None, None, "TASK_WF", "GET_TASK") """ # Check if vim status refresh is enabled again - self.update_vm_refresh() + self.update_vm_refresh(ro_task) # 0: get task_status_create lock_object = None task_status_create = None @@ -2180,7 +2195,10 @@ class NsWorker(threading.Thread): ) if task["action"] == "DELETE": - (new_status, db_vim_info_update,) = self._delete_task( + ( + new_status, + db_vim_info_update, + ) = self._delete_task( ro_task, task_index, task_depends, db_ro_task_update ) new_status = (