From b75d5eefe381805be301cbfc3e05dcbd35cdca57 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Sat, 30 May 2020 01:20:42 +0200 Subject: [PATCH] cephadm: Add a bunch of type annotations Signed-off-by: Sebastian Wagner (cherry picked from commit 888754ba2c74fba42bc26c9006361150ed7ddc16) --- src/cephadm/cephadm | 19 +++++++++++++------ src/cephadm/mypy.ini | 2 +- src/cephadm/tests/test_cephadm.py | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index d5bf446955af4..f5b725fcf879a 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -237,7 +237,7 @@ class NFSGanesha(object): @staticmethod def get_version(container_id): - # type(str) -> Optional[str] + # type: (str) -> Optional[str] version = None out, err, code = call( [container_path, 'exec', container_id, @@ -249,7 +249,7 @@ class NFSGanesha(object): return version def validate(self): - # type () -> None + # type: () -> None if not is_fsid(self.fsid): raise Error('not an fsid: %s' % self.fsid) if not self.daemon_id: @@ -386,7 +386,7 @@ class CephIscsi(object): @staticmethod def get_version(container_id): - # type(str) -> Optional[str] + # type: (str) -> Optional[str] version = None out, err, code = call( [container_path, 'exec', container_id, @@ -396,7 +396,7 @@ class CephIscsi(object): return version def validate(self): - # type () -> None + # type: () -> None if not is_fsid(self.fsid): raise Error('not an fsid: %s' % self.fsid) if not self.daemon_id: @@ -451,6 +451,7 @@ class CephIscsi(object): @staticmethod def configfs_mount_umount(data_dir, mount=True): + # type: (str, bool) -> List[str] mount_path = os.path.join(data_dir, 'configfs') if mount: cmd = "if ! grep -qs {0} /proc/mounts; then " \ @@ -463,6 +464,7 @@ class CephIscsi(object): ################################## def get_supported_daemons(): + # type: () -> List[str] supported_daemons = list(Ceph.daemons) supported_daemons.extend(Monitoring.components) supported_daemons.append(NFSGanesha.daemon_type) @@ -473,7 +475,7 @@ def get_supported_daemons(): ################################## def attempt_bind(s, address, port): - # type (str) -> None + # type: (socket.socket, str, int) -> None try: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((address, port)) @@ -488,7 +490,7 @@ def attempt_bind(s, address, port): s.close() def port_in_use(port_num): - # type (int) -> bool + # type: (int) -> bool """Detect whether a port is in use on the local machine - IPv4 and IPv6""" logger.info('Verifying port %d ...' % port_num) try: @@ -503,6 +505,7 @@ def port_in_use(port_num): return False def check_ip_port(ip, port): + # type: (str, int) -> None if not args.skip_ping_check: logger.info('Verifying IP %s port %d ...' % (ip, port)) if ip.startswith('[') or '::' in ip: @@ -940,6 +943,7 @@ def pathify(p): return os.path.abspath(p) def get_file_timestamp(fn): + # type: (str) -> Optional[str] try: mt = os.path.getmtime(fn) return datetime.datetime.fromtimestamp( @@ -949,6 +953,7 @@ def get_file_timestamp(fn): return None def try_convert_datetime(s): + # type: (str) -> Optional[str] # This is super irritating because # 1) podman and docker use different formats # 2) python's strptime can't parse either one @@ -1175,6 +1180,7 @@ def get_last_local_ceph_image(): return None def write_tmp(s, uid, gid): + # type: (str, int, int) -> Any tmp_f = tempfile.NamedTemporaryFile(mode='w', prefix='ceph-tmp') os.fchown(tmp_f.fileno(), uid, gid) @@ -3797,6 +3803,7 @@ class CustomValidation(argparse.Action): ################################## def get_distro(): + # type: () -> Tuple[Optional[str], Optional[str], Optional[str]] distro = None distro_version = None distro_codename = None diff --git a/src/cephadm/mypy.ini b/src/cephadm/mypy.ini index 1215375ed9b85..313abc807e95d 100644 --- a/src/cephadm/mypy.ini +++ b/src/cephadm/mypy.ini @@ -1,2 +1,2 @@ [mypy] -ignore_missing_imports = True \ No newline at end of file +ignore_missing_imports = False diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 6f51b3e78af44..785aedac7820f 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1,3 +1,4 @@ +# type: ignore import argparse import mock import os -- 2.39.5