From 3d3ee4bf768b4aaa3252f06c299cfee9fdb28148 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Fri, 24 Mar 2017 14:36:27 +0100 Subject: [PATCH] mgr: log module name before PyErr_Print() If an exception is raised in any of the python module functions invoked by mgr (for example, ImportError if rest_framework isn't available when serve() in called in the rest module), print the module name along with the failed method name. This commit also fixes what looks to me like a missed call to PyGILState_Release() in the failure case in MgrPyModule::serve(). Signed-off-by: Tim Serong --- src/mgr/MgrPyModule.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mgr/MgrPyModule.cc b/src/mgr/MgrPyModule.cc index 4e4c42483a5..4a8ac7d4172 100644 --- a/src/mgr/MgrPyModule.cc +++ b/src/mgr/MgrPyModule.cc @@ -82,16 +82,18 @@ int MgrPyModule::serve() auto pValue = PyObject_CallMethod(pClassInstance, const_cast("serve"), nullptr); + int r = 0; if (pValue != NULL) { Py_DECREF(pValue); } else { + derr << "Failed to invoke serve() on " << module_name << dendl; PyErr_Print(); - return -EINVAL; + r = -EINVAL; } PyGILState_Release(gstate); - return 0; + return r; } // FIXME: DRY wrt serve @@ -108,8 +110,8 @@ void MgrPyModule::shutdown() if (pValue != NULL) { Py_DECREF(pValue); } else { - PyErr_Print(); derr << "Failed to invoke shutdown() on " << module_name << dendl; + PyErr_Print(); } PyGILState_Release(gstate); @@ -130,6 +132,7 @@ void MgrPyModule::notify(const std::string ¬ify_type, const std::string ¬i if (pValue != NULL) { Py_DECREF(pValue); } else { + derr << "Failed to invoke notify() on " << module_name << dendl; PyErr_Print(); // FIXME: callers can't be expected to handle a python module // that has spontaneously broken, but Mgr() should provide @@ -243,6 +246,7 @@ int MgrPyModule::handle_command( Py_DECREF(pResult); } else { + derr << "Failed to invoke handle_command() on " << module_name << dendl; PyErr_Print(); r = -EINVAL; } -- 2.39.5