From: Sage Weil Date: Thu, 31 Oct 2019 15:42:53 +0000 (-0500) Subject: mgr/ActivePyModules: behave if a module queries a devid that does not exist X-Git-Tag: v15.1.0~1038^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=67e5139b02518cbc83e5156e2f74a5d22f4d97a4;p=ceph.git 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 --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 8cdf1ed5d327..52601ec4eb95 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 27dbe175ee28..5a31ad0691d3 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(