From 60036703a8343474a54d60d2dbff89109c6b0a34 Mon Sep 17 00:00:00 2001 From: aticig Date: Thu, 30 Jun 2022 12:40:46 +0300 Subject: [PATCH] Fix Bug 2086 Updating VNF status configurable This fix allows to set REFRESH_ACTIVE period as config option which periodically checks the VM status from VIM. Env variable can be set in the ro container export OSMRO_PERIOD_REFRESH_ACTIVE=-1 to disable VM status updates. This config parameter allowed to set >= 60 seconds or -1. Giving execute permission stage-releasenote.sh file. Change-Id: I9e0ed82830ca09532f87f76480003f278aac51ea Signed-off-by: aticig --- NG-RO/osm_ng_ro/ns_thread.py | 111 +++++++++++++++--- NG-RO/osm_ng_ro/ro.cfg | 7 ++ NG-RO/osm_ng_ro/ro_main.py | 2 +- devops-stages/stage-releasenote.sh | 0 .../notes/fix_bug_2086-6d2583a3801aa0ee.yaml | 24 ++++ 5 files changed, 126 insertions(+), 18 deletions(-) mode change 100644 => 100755 devops-stages/stage-releasenote.sh create mode 100644 releasenotes/notes/fix_bug_2086-6d2583a3801aa0ee.yaml diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index 8a5c5c1e..edf1bbff 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -33,6 +33,7 @@ from shutil import rmtree import threading import time import traceback +from typing import Dict from unittest.mock import Mock from importlib_metadata import entry_points @@ -1265,15 +1266,39 @@ class VimInteractionSdnNet(VimInteractionBase): return "DONE", ro_vim_item_update_ok -class NsWorker(threading.Thread): - REFRESH_BUILD = 5 # 5 seconds - REFRESH_ACTIVE = 60 # 1 minute - REFRESH_ERROR = 600 - REFRESH_IMAGE = 3600 * 10 - REFRESH_DELETE = 3600 * 10 - QUEUE_SIZE = 100 - terminate = False +class ConfigValidate: + def __init__(self, config: Dict): + self.conf = config + + @property + def active(self): + # default 1 min, allowed >= 60 or -1, -1 disables periodic checks + if ( + self.conf["period"]["refresh_active"] >= 60 + or self.conf["period"]["refresh_active"] == -1 + ): + return self.conf["period"]["refresh_active"] + + return 60 + + @property + def build(self): + return self.conf["period"]["refresh_build"] + + @property + def image(self): + return self.conf["period"]["refresh_image"] + @property + def error(self): + return self.conf["period"]["refresh_error"] + + @property + def queue_size(self): + return self.conf["period"]["queue_size"] + + +class NsWorker(threading.Thread): def __init__(self, worker_index, config, plugins, db): """ @@ -1288,7 +1313,9 @@ class NsWorker(threading.Thread): self.plugin_name = "unknown" self.logger = logging.getLogger("ro.worker{}".format(worker_index)) self.worker_index = worker_index - self.task_queue = queue.Queue(self.QUEUE_SIZE) + # refresh periods for created items + self.refresh_config = ConfigValidate(config) + self.task_queue = queue.Queue(self.refresh_config.queue_size) # targetvim: vimplugin class self.my_vims = {} # targetvim: vim information from database @@ -1662,6 +1689,7 @@ class NsWorker(threading.Thread): "tasks.status": ["SCHEDULED", "BUILD", "DONE", "FAILED"], "locked_at.lt": now - self.task_locked_time, "to_check_at.lt": self.time_last_task_processed, + "to_check_at.gt": -1, }, update_dict={"locked_by": self.my_id, "locked_at": now}, fail_on_empty=False, @@ -1959,6 +1987,52 @@ class NsWorker(threading.Thread): return ro_task_dependency, task_index raise NsWorkerException("Cannot get depending task {}".format(task_id)) + def update_vm_refresh(self): + """Enables the VM status updates if self.refresh_config.active parameter + is not -1 and than 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 + + if next_refresh != -1: + db_ro_task_update = {} + now = time.time() + next_check_at = now + (24 * 60 * 60) + next_check_at = min(next_check_at, next_refresh) + db_ro_task_update["vim_info.refresh_at"] = next_refresh + db_ro_task_update["to_check_at"] = next_check_at + + self.logger.debug( + "Finding tasks which to be updated to enable VM status updates" + ) + refresh_tasks = self.db.get_list( + "ro_tasks", + q_filter={ + "tasks.status": "DONE", + "to_check_at.lt": 0, + }, + ) + self.logger.debug("Updating tasks to change the to_check_at status") + for task in refresh_tasks: + q_filter = { + "_id": task["_id"], + } + self.db.set_one( + "ro_tasks", + q_filter=q_filter, + update_dict=db_ro_task_update, + fail_on_empty=True, + ) + + except Exception as e: + self.logger.error(f"Error updating tasks to enable VM status updates: {e}") + def _process_pending_tasks(self, ro_task): ro_task_id = ro_task["_id"] now = time.time() @@ -1976,13 +2050,16 @@ class NsWorker(threading.Thread): next_refresh = time.time() if task["item"] in ("image", "flavor"): - next_refresh += self.REFRESH_IMAGE + next_refresh += self.refresh_config.image elif new_status == "BUILD": - next_refresh += self.REFRESH_BUILD + next_refresh += self.refresh_config.build elif new_status == "DONE": - next_refresh += self.REFRESH_ACTIVE + if self.refresh_config.active == -1: + next_refresh = -1 + else: + next_refresh += self.refresh_config.active else: - next_refresh += self.REFRESH_ERROR + next_refresh += self.refresh_config.error next_check_at = min(next_check_at, next_refresh) db_ro_task_update["vim_info.refresh_at"] = next_refresh @@ -1994,6 +2071,8 @@ class NsWorker(threading.Thread): if self.logger.getEffectiveLevel() == logging.DEBUG: self._log_ro_task(ro_task, None, None, "TASK_WF", "GET_TASK") """ + # Check if vim status refresh is enabled again + self.update_vm_refresh() # 0: get task_status_create lock_object = None task_status_create = None @@ -2147,10 +2226,8 @@ class NsWorker(threading.Thread): # self._create_task(ro_task, task_index, task_depends, db_ro_task_update) _update_refresh(new_status) else: - if ( - ro_task["vim_info"]["refresh_at"] - and now > ro_task["vim_info"]["refresh_at"] - ): + refresh_at = ro_task["vim_info"]["refresh_at"] + if refresh_at and refresh_at != -1 and now > refresh_at: new_status, db_vim_info_update = self.item2class[ task["item"] ].refresh(ro_task) diff --git a/NG-RO/osm_ng_ro/ro.cfg b/NG-RO/osm_ng_ro/ro.cfg index 6969702a..e232ad1c 100644 --- a/NG-RO/osm_ng_ro/ro.cfg +++ b/NG-RO/osm_ng_ro/ro.cfg @@ -62,6 +62,13 @@ task_locked_time: 300 task_max_locked_time: 1200 # lock is renewed until this maximum time task_relock_time: 15 # 30s before expiring lock time, it is re-locked again +[period] +# use env for OSMRO_PERIOD_XXX +refresh_active: 60 # default 1 min +refresh_build: 15 # default 15 seconds +refresh_image: 3600 * 10 +refresh_error: 600 +queue_size: 100 [database] # use env OSMRO_DATABASE_XXX to override diff --git a/NG-RO/osm_ng_ro/ro_main.py b/NG-RO/osm_ng_ro/ro_main.py index ac381603..a7ca1002 100644 --- a/NG-RO/osm_ng_ro/ro_main.py +++ b/NG-RO/osm_ng_ro/ro_main.py @@ -792,7 +792,7 @@ def _start_service(): elif k1 == "tools": # update [/] configuration engine_config["/"]["tools." + k2.replace("_", ".")] = yaml.safe_load(v) - elif k1 in ("message", "database", "storage", "authentication"): + elif k1 in ("message", "database", "storage", "authentication", "period"): engine_config[k1][k2] = yaml.safe_load(v) except Exception as e: diff --git a/devops-stages/stage-releasenote.sh b/devops-stages/stage-releasenote.sh old mode 100644 new mode 100755 diff --git a/releasenotes/notes/fix_bug_2086-6d2583a3801aa0ee.yaml b/releasenotes/notes/fix_bug_2086-6d2583a3801aa0ee.yaml new file mode 100644 index 00000000..cc00314e --- /dev/null +++ b/releasenotes/notes/fix_bug_2086-6d2583a3801aa0ee.yaml @@ -0,0 +1,24 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### +--- +fixes: + - | + Fix Bug 2086 Updating VNF status configurable + This fix allows to set REFRESH_ACTIVE period as config option which + periodically checks the VM status from VIM. Env variable can be set in the + ro container export OSMRO_PERIOD_REFRESH_ACTIVE=-1 to disable VM status updates. + This config parameter allowed to set >= 60 seconds or -1. -- 2.25.1