From 60bef081f845223428d9f944d60c7c78a97e60a8 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 29 Jan 2021 11:26:15 +0800 Subject: [PATCH] pybind/mgr/status: add typing annotations Signed-off-by: Kefu Chai --- src/mypy.ini | 3 +++ src/pybind/mgr/status/module.py | 17 ++++++++++------- src/pybind/mgr/tox.ini | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mypy.ini b/src/mypy.ini index 9aa575ef79502..5ad34b0f7cb9a 100755 --- a/src/mypy.ini +++ b/src/mypy.ini @@ -33,6 +33,9 @@ disallow_untyped_defs = True [mypy-orchestrator.*] disallow_untyped_defs = True +[mypy-status.*] +disallow_untyped_defs = True + [mypy-zabbix.*] disallow_untyped_defs = True diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index e9f14c5f883b5..c932bbb8ea9da 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -5,7 +5,7 @@ High level status display commands from collections import defaultdict from prettytable import PrettyTable -from typing import Optional +from typing import Dict, List, Optional, Tuple, Union import errno import fnmatch import mgr_util @@ -16,7 +16,7 @@ from mgr_module import CLIReadCommand, MgrModule, HandleCommandResult class Module(MgrModule): - def get_latest(self, daemon_type, daemon_name, stat): + def get_latest(self, daemon_type: str, daemon_name: str, stat: str) -> int: data = self.get_counter(daemon_type, daemon_name, stat)[stat] #self.log.error("get_latest {0} data={1}".format(stat, data)) if data: @@ -24,9 +24,8 @@ class Module(MgrModule): else: return 0 - def get_rate(self, daemon_type, daemon_name, stat): + def get_rate(self, daemon_type: str, daemon_name: str, stat: str) -> int: data = self.get_counter(daemon_type, daemon_name, stat)[stat] - #self.log.error("get_latest {0} data={1}".format(stat, data)) if data and len(data) > 1 and data[-1][0] != data[-2][0]: return (data[-1][1] - data[-2][1]) // int(data[-1][0] - data[-2][0]) @@ -34,12 +33,16 @@ class Module(MgrModule): return 0 @CLIReadCommand("fs status") - def handle_fs_status(self, fs: Optional[str] = None, format: str = 'plain'): + def handle_fs_status(self, fs: Optional[str] = None, format: str = 'plain') -> Tuple[int, str, str]: """ Show the status of a CephFS filesystem """ output = "" - json_output = defaultdict(list) + json_output: Dict[str, List[Dict[str, Union[int, str, List[str]]]]] = \ + dict(mdsmap=[], + pools=[], + clients=[], + mds_version=[]) output_format = format fs_filter = fs @@ -275,7 +278,7 @@ class Module(MgrModule): return HandleCommandResult(stdout=output) @CLIReadCommand("osd status") - def handle_osd_status(self, bucket: Optional[str] = None): + def handle_osd_status(self, bucket: Optional[str] = None) -> Tuple[int, str, str]: """ Show the status of OSDs within a bucket, or all """ diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index f9562a0c42f21..484d182b7d3b2 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -69,6 +69,7 @@ commands = -m rook \ -m snap_schedule \ -m stats \ + -m status \ -m test_orchestrator \ -m volumes \ -m zabbix -- 2.39.5