From 67e5139b02518cbc83e5156e2f74a5d22f4d97a4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 31 Oct 2019 10:42:53 -0500 Subject: [PATCH] mgr/ActivePyModules: behave if a module queries a devid that does not exist The GIL reacquire was being handled in the lambda, but that was not getting called if the device didn't exist, leading to a crash. Add a trivial CLI test. Fixes: https://tracker.ceph.com/issues/42578 Signed-off-by: Sage Weil --- qa/workunits/cephtool/test.sh | 8 ++++++++ src/mgr/ActivePyModules.cc | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 8cdf1ed5d32..52601ec4eb9 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -2739,6 +2739,13 @@ function test_mgr_tell() ceph tell mgr version } +function test_mgr_devices() +{ + ceph device ls + expect_false ceph device info doesnotexist + expect_false ceph device get-health-metrics doesnotexist +} + function test_per_pool_scrub_status() { ceph osd pool create noscrub_pool 12 @@ -2841,6 +2848,7 @@ MDS_TESTS+=" mon_mds_metadata" MDS_TESTS+=" mds_tell_help_command" MGR_TESTS+=" mgr_tell" +MGR_TESTS+=" mgr_devices" TESTS+=$MON_TESTS TESTS+=$OSD_TESTS diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 27dbe175ee2..5a31ad0691d 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -341,10 +341,15 @@ PyObject *ActivePyModules::get_python(const std::string &what) } else if (what.size() > 7 && what.substr(0, 7) == "device ") { string devid = what.substr(7); - daemon_state.with_device(devid, [&f, &tstate] (const DeviceState& dev) { - PyEval_RestoreThread(tstate); - f.dump_object("device", dev); - }); + if (!daemon_state.with_device( + devid, + [&f, &tstate] (const DeviceState& dev) { + PyEval_RestoreThread(tstate); + f.dump_object("device", dev); + })) { + // device not found + PyEval_RestoreThread(tstate); + } return f.get(); } else if (what == "io_rate") { cluster_state.with_pgmap( -- 2.47.3