]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: define HandleCommandResult using NamedTuple
authorKefu Chai <kchai@redhat.com>
Tue, 19 Jan 2021 06:08:39 +0000 (14:08 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 26 Jan 2021 10:02:24 +0000 (18:02 +0800)
simpler this way, so we don't need to define __new__

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/cephadm/services/cephadmservice.py
src/pybind/mgr/mgr_module.py

index b6df0cd9b8e40507c27170238c2327043dc49c24..4632d5a0fa35824763aa60173f1f8d06ea91d9c0 100644 (file)
@@ -215,7 +215,7 @@ class CephadmService(metaclass=ABCMeta):
 
         if self.TYPE not in ['mon', 'osd', 'mds']:
             logger.info(out)
-            return HandleCommandResult(0, out, None)
+            return HandleCommandResult(0, out)
 
         r = HandleCommandResult(*self.mgr.mon_command({
             'prefix': f'{self.TYPE} ok-to-stop',
index 7da1f3c24749db8a5cdcc6f9557b8442121ddd49..5a87e528de03c2c7e761465c64434d06e4d0cc36 100644 (file)
@@ -1,7 +1,7 @@
 import ceph_module  # noqa
 
 from typing import cast, Tuple, Any, Dict, Generic, Optional, Callable, List, \
-    Sequence, Union, TYPE_CHECKING
+    NamedTuple, Sequence, Union, TYPE_CHECKING
 if TYPE_CHECKING:
     import sys
     if sys.version_info >= (3, 8):
@@ -15,7 +15,7 @@ import errno
 import functools
 import json
 import threading
-from collections import defaultdict, namedtuple
+from collections import defaultdict
 from enum import IntEnum
 import rados
 import re
@@ -104,26 +104,20 @@ class CommandResult(object):
         return self.r, self.outb, self.outs
 
 
-class HandleCommandResult(namedtuple('HandleCommandResult', ['retval', 'stdout', 'stderr'])):
-    def __new__(cls, retval=0, stdout="", stderr=""):
-        """
-        Tuple containing the result of `handle_command()`
-
-        Only write to stderr if there is an error, or in extraordinary circumstances
+class HandleCommandResult(NamedTuple):
+    """
+    Tuple containing the result of `handle_command()`
 
-        Avoid having `ceph foo bar` commands say "did foo bar" on success unless there
-        is critical information to include there.
+    Only write to stderr if there is an error, or in extraordinary circumstances
 
-        Everything programmatically consumable should be put on stdout
+    Avoid having `ceph foo bar` commands say "did foo bar" on success unless there
+    is critical information to include there.
 
-        :param retval: return code. E.g. 0 or -errno.EINVAL
-        :type retval: int
-        :param stdout: data of this result.
-        :type stdout: str
-        :param stderr: Typically used for error messages.
-        :type stderr: str
-        """
-        return super(HandleCommandResult, cls).__new__(cls, retval, stdout, stderr)
+    Everything programmatically consumable should be put on stdout
+    """
+    retval: int = 0             # return code. E.g. 0 or -errno.EINVAL
+    stdout: str = ""            # data of this result.
+    stderr: str = ""            # Typically used for error messages.
 
 
 class MonCommandFailed(RuntimeError): pass