From: Sage Weil Date: Thu, 28 Oct 2021 22:11:38 +0000 (-0400) Subject: pybind/mgr/mgr_module: add tool_exec() command X-Git-Tag: v17.1.0~557^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e24171f8180bc60fb1876b7c7097f4fa45e17325;p=ceph.git pybind/mgr/mgr_module: add tool_exec() command Run a (ceph) tool with the appropriate keyring and entity name. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index fa71980ee99d..73839000cd56 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1557,6 +1557,34 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): """ self._ceph_send_command(result, svc_type, svc_id, command, tag, inbuf) + def tool_exec( + self, + args: List[str], + timeout: int = 10, + stdin: Optional[bytes] = None + ) -> Tuple[int, str, str]: + try: + tool = args.pop(0) + cmd = [ + tool, + '-k', str(self.get_ceph_option('keyring')), + '-n', f'mgr.{self.get_mgr_id()}', + ] + args + self.log.debug('exec: ' + ' '.join(cmd)) + p = subprocess.run( + cmd, + input=stdin, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + timeout=timeout, + ) + except subprocess.TimeoutExpired as ex: + self.log.error(ex) + return -errno.ETIMEDOUT, '', str(ex) + if p.returncode: + self.log.error(f'Non-zero return from {cmd}: {p.stderr.decode()}') + return p.returncode, p.stdout.decode(), p.stderr.decode() + def set_health_checks(self, checks: HealthChecksT) -> None: """ Set the module's current map of health checks. Argument is a