]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/mgr_module.py
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / mgr_module.py
index d6ba31f72086247711e4b14b375b53a66856047d..554310d9813fc6713866de059f36e150ec3271c6 100644 (file)
@@ -96,6 +96,9 @@ class HandleCommandResult(namedtuple('HandleCommandResult', ['retval', 'stdout',
         return super(HandleCommandResult, cls).__new__(cls, retval, stdout, stderr)
 
 
+class MonCommandFailed(RuntimeError): pass
+
+
 class OSDMap(ceph_module.BasePyOSDMap):
     def get_epoch(self):
         return self._get_epoch()
@@ -1078,6 +1081,17 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
         """
         return self._ceph_get_daemon_status(svc_type, svc_id)
 
+    def check_mon_command(self, cmd_dict: dict) -> HandleCommandResult:
+        """
+        Wrapper around :func:`~mgr_module.MgrModule.mon_command`, but raises,
+        if ``retval != 0``.
+        """
+
+        r = HandleCommandResult(*self.mon_command(cmd_dict))
+        if r.retval:
+            raise MonCommandFailed(f'{cmd_dict["prefix"]} failed: {r.stderr} retval: {r.retval}')
+        return r
+
     def mon_command(self, cmd_dict):
         """
         Helper for modules that do simple, synchronous mon command
@@ -1386,7 +1400,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
 
                 schema = self.get_perf_schema(service['type'], service['id'])
                 if not schema:
-                    self.log.warn("No perf counter schema for {0}.{1}".format(
+                    self.log.warning("No perf counter schema for {0}.{1}".format(
                         service['type'], service['id']
                     ))
                     continue