From: Sage Weil Date: Fri, 21 May 2021 22:49:58 +0000 (-0400) Subject: mgr: expose ceph.conf path to modules X-Git-Tag: v16.2.5~87^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f9aa8c5c24e0163b78e3dc3151729ffa4c0890b4;p=ceph.git mgr: expose ceph.conf path to modules This is useful for shelling back out to ceph utilities. Signed-off-by: Sage Weil (cherry picked from commit 3194b8d789ecf6d6b9cd8cadfd962011fa5f6ea0) --- diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 8bf924d6a12a..da8785eaa97d 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -601,6 +601,12 @@ ceph_get_version(BaseMgrModule *self, PyObject *args) return PyUnicode_FromString(pretty_version_to_str().c_str()); } +static PyObject * +ceph_get_ceph_conf_path(BaseMgrModule *self, PyObject *args) +{ + return PyUnicode_FromString(g_conf().get_conf_path().c_str()); +} + static PyObject * ceph_get_release_name(BaseMgrModule *self, PyObject *args) { @@ -1418,6 +1424,9 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get_mgr_id", (PyCFunction)ceph_get_mgr_id, METH_NOARGS, "Get the name of the Mgr daemon where we are running"}, + {"_ceph_get_ceph_conf_path", (PyCFunction)ceph_get_ceph_conf_path, METH_NOARGS, + "Get path to ceph.conf"}, + {"_ceph_get_option", (PyCFunction)ceph_option_get, METH_VARARGS, "Get a native configuration option value"}, diff --git a/src/pybind/mgr/ceph_module.pyi b/src/pybind/mgr/ceph_module.pyi index 19ad8a4f8a54..2a7f2d2711e5 100644 --- a/src/pybind/mgr/ceph_module.pyi +++ b/src/pybind/mgr/ceph_module.pyi @@ -80,6 +80,7 @@ class BaseMgrModule(object): inbuf: Optional[str]) -> None: ... def _ceph_set_health_checks(self, checks: Mapping[str, HealthCheckT]) -> None: ... def _ceph_get_mgr_id(self) -> str: ... + def _ceph_get_ceph_conf_path(self) -> str: ... def _ceph_get_option(self, key: str) -> OptionValue: ... def _ceph_get_foreign_option(self, entity: str, key: str) -> OptionValue: ... def _ceph_get_module_option(self, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 701b1eaf1e5d..eee8fc346f9c 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1369,6 +1369,9 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): """ return self._ceph_get_mgr_id() + def get_ceph_conf_path(self) -> str: + return self._ceph_get_ceph_conf_path() + def get_ceph_option(self, key: str) -> OptionValue: return self._ceph_get_option(key) diff --git a/src/pybind/mgr/tests/__init__.py b/src/pybind/mgr/tests/__init__.py index 9d5e2dcabea7..66c1cbc87b69 100644 --- a/src/pybind/mgr/tests/__init__.py +++ b/src/pybind/mgr/tests/__init__.py @@ -184,6 +184,7 @@ if 'UNITTEST' in os.environ: super(M, self).__init__() self._ceph_get_version = mock.Mock() + self._ceph_get_ceph_conf_path = mock.MagicMock() self._ceph_get_option = mock.MagicMock() self._ceph_get_context = mock.MagicMock() self._ceph_register_client = mock.MagicMock()