From 94ce75c0d45589b197b5481d21f85035e16291ce Mon Sep 17 00:00:00 2001 From: albailey Date: Thu, 3 Mar 2022 12:59:28 -0600 Subject: [PATCH] Update nfv code to work properly on python3.7+ The coroutines in nfv internally raise StopIteration, however in python 3.7, that exception is converted to a RuntimeError: https://www.python.org/dev/peps/pep-0479/ The vim code that catches a StopIteration exception has been updated to catch both types. The OCF scripts on a Debian system runs python3, and need explicit /usr/bin/python3 added to them Test-Plan: - Verified a Debian environment running python 3.9 is able to start nfv-vim without the process immediately crashing. - Verified a Centos environment running the older python2.7 still able to run nfv-vim. - Verified Centos installation Closes-Bug: 1963277 Closes-Bug: 1962787 Signed-off-by: albailey Change-Id: Ib54926738aeafbee0c90e7a2b5a4ad9556a3d7f1 --- nfv/nfv-common/nfv_common/selobj/_selobj_module.py | 6 +++--- nfv/nfv-common/nfv_common/tasks/_task_scheduler.py | 10 +++++----- nfv/nfv-common/nfv_common/timers/_timer.py | 2 +- nfv/nfv-vim/scripts/vim | 4 ++-- nfv/nfv-vim/scripts/vim-api | 4 ++-- nfv/nfv-vim/scripts/vim-webserver | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/nfv/nfv-common/nfv_common/selobj/_selobj_module.py b/nfv/nfv-common/nfv_common/selobj/_selobj_module.py index aa3d9068..0e9128f1 100755 --- a/nfv/nfv-common/nfv_common/selobj/_selobj_module.py +++ b/nfv/nfv-common/nfv_common/selobj/_selobj_module.py @@ -103,7 +103,7 @@ def selobj_dispatch(timeout_in_ms): start_ms = timers.get_monotonic_timestamp_in_ms() try: callback.send(selobj) - except StopIteration: + except (StopIteration, RuntimeError): _read_callbacks.pop(selobj) elapsed_ms = timers.get_monotonic_timestamp_in_ms() - start_ms histogram.add_histogram_data("selobj read: " + callback.__name__, @@ -115,7 +115,7 @@ def selobj_dispatch(timeout_in_ms): start_ms = timers.get_monotonic_timestamp_in_ms() try: callback.send(selobj) - except StopIteration: + except (StopIteration, RuntimeError): _write_callbacks.pop(selobj) elapsed_ms = timers.get_monotonic_timestamp_in_ms() - start_ms histogram.add_histogram_data("selobj write: " + callback.__name__, @@ -127,7 +127,7 @@ def selobj_dispatch(timeout_in_ms): start_ms = timers.get_monotonic_timestamp_in_ms() try: callback.send(selobj) - except StopIteration: + except (StopIteration, RuntimeError): _error_callbacks.pop(selobj) elapsed_ms = timers.get_monotonic_timestamp_in_ms() - start_ms histogram.add_histogram_data("selobj error: " + callback.__name__, diff --git a/nfv/nfv-common/nfv_common/tasks/_task_scheduler.py b/nfv/nfv-common/nfv_common/tasks/_task_scheduler.py index e907e199..98a93cc3 100755 --- a/nfv/nfv-common/nfv_common/tasks/_task_scheduler.py +++ b/nfv/nfv-common/nfv_common/tasks/_task_scheduler.py @@ -134,7 +134,7 @@ class TaskScheduler(object): break try: task.timer_fired(timer_id) - except StopIteration: + except (StopIteration, RuntimeError): self.delete_task(task) break @@ -187,7 +187,7 @@ class TaskScheduler(object): break try: task.io_wait_complete(select_obj) - except StopIteration: + except (StopIteration, RuntimeError): self.delete_task(task) break @@ -330,7 +330,7 @@ class TaskScheduler(object): self._running_task = task try: task.task_work_complete(task_work) - except StopIteration: + except (StopIteration, RuntimeError): self.delete_task(task) if self._task_worker_pool.available_workers(): @@ -356,7 +356,7 @@ class TaskScheduler(object): try: task.task_work_timeout(task_work) del self._task_work_timers[timer_id] - except StopIteration: + except (StopIteration, RuntimeError): self.delete_task(task) if self._task_worker_pool.available_workers(): @@ -384,7 +384,7 @@ class TaskScheduler(object): self._running_task.name)) self._running_task.run() - except StopIteration: + except (StopIteration, RuntimeError): self.delete_task(self._running_task) finally: diff --git a/nfv/nfv-common/nfv_common/timers/_timer.py b/nfv/nfv-common/nfv_common/timers/_timer.py index 14da7d4e..f4cd9ae1 100755 --- a/nfv/nfv-common/nfv_common/timers/_timer.py +++ b/nfv/nfv-common/nfv_common/timers/_timer.py @@ -68,6 +68,6 @@ class Timer(object): self._callback.send(self._timer_id) self._arm_timestamp = get_monotonic_timestamp_in_ms() self._next_expiry_in_secs = self._interval_secs - except StopIteration: + except (StopIteration, RuntimeError): rearm = False return rearm diff --git a/nfv/nfv-vim/scripts/vim b/nfv/nfv-vim/scripts/vim index 459953b1..39698afb 100755 --- a/nfv/nfv-vim/scripts/vim +++ b/nfv/nfv-vim/scripts/vim @@ -213,12 +213,12 @@ vim_confirm_stop() { local my_processes my_binary=`which ${OCF_RESKEY_binary}` - my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)"` + my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)"` if [ -n "${my_processes}" ] then ocf_log info "About to SIGKILL the following: ${my_processes}" - pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)" + pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)" fi if [ -e "$PROCESS_NOT_RUNNING_FILE" ] ; then diff --git a/nfv/nfv-vim/scripts/vim-api b/nfv/nfv-vim/scripts/vim-api index 609dde17..1da5ddfd 100755 --- a/nfv/nfv-vim/scripts/vim-api +++ b/nfv/nfv-vim/scripts/vim-api @@ -197,12 +197,12 @@ vim_api_confirm_stop() { local my_processes my_binary=`which ${OCF_RESKEY_binary}` - my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)"` + my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)"` if [ -n "${my_processes}" ] then ocf_log info "About to SIGKILL the following: ${my_processes}" - pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)" + pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)" fi if [ -e "$PROCESS_NOT_RUNNING_FILE" ] ; then diff --git a/nfv/nfv-vim/scripts/vim-webserver b/nfv/nfv-vim/scripts/vim-webserver index 176e79c7..44457044 100755 --- a/nfv/nfv-vim/scripts/vim-webserver +++ b/nfv/nfv-vim/scripts/vim-webserver @@ -197,12 +197,12 @@ vim_webserver_confirm_stop() { local my_processes my_binary=`which ${OCF_RESKEY_binary}` - my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)"` + my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)"` if [ -n "${my_processes}" ] then ocf_log info "About to SIGKILL the following: ${my_processes}" - pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)" + pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2|/usr/bin/python3) ${my_binary}([^\w-]|$)" fi if [ -e "$PROCESS_NOT_RUNNING_FILE" ] ; then