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: v14.2.5~75^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b630bb95058052bc10b1c7fb9f1d2bcb5b28b49d;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 (cherry picked from commit 67e5139b02518cbc83e5156e2f74a5d22f4d97a4) --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 55ea6c894e49..a4bd3d415a6f 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -2705,6 +2705,13 @@ function test_mgr_tell() ceph tell mgr osd status } +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 @@ -2807,6 +2814,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 907bb0c81c93..444de30f3d8e 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -314,10 +314,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(