]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: log module name before PyErr_Print()
authorTim Serong <tserong@suse.com>
Fri, 24 Mar 2017 13:36:27 +0000 (14:36 +0100)
committerKefu Chai <kchai@redhat.com>
Fri, 21 Apr 2017 06:17:09 +0000 (14:17 +0800)
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 <tserong@suse.com>
src/mgr/MgrPyModule.cc

index 4e4c42483a51b41223ce2fbad0186da1f03d79ce..4a8ac7d4172b3dd1f15e504f7b23732d00aedde5 100644 (file)
@@ -82,16 +82,18 @@ int MgrPyModule::serve()
   auto pValue = PyObject_CallMethod(pClassInstance,
       const_cast<char*>("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 &notify_type, const std::string &noti
   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;
   }