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 <Al.Bailey@windriver.com>
Change-Id: Ib54926738aeafbee0c90e7a2b5a4ad9556a3d7f1
This commit is contained in:
albailey 2022-03-03 12:59:28 -06:00 committed by Al Bailey
parent e670434c92
commit 94ce75c0d4
6 changed files with 15 additions and 15 deletions

View File

@ -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__,

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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