]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Add a bunch of type annotations
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 29 May 2020 23:20:42 +0000 (01:20 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 8 Jun 2020 11:52:24 +0000 (13:52 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit 888754ba2c74fba42bc26c9006361150ed7ddc16)

src/cephadm/cephadm
src/cephadm/mypy.ini
src/cephadm/tests/test_cephadm.py

index d5bf446955af480c585fd0dc76c2df09430fc6b8..f5b725fcf879a575f90682ff3f5611ada76d909e 100755 (executable)
@@ -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
index 1215375ed9b859e1a000693758d35bad90ce592c..313abc807e95d2ac17a8c8faa9f0882898e8c57a 100644 (file)
@@ -1,2 +1,2 @@
 [mypy]
-ignore_missing_imports = True
\ No newline at end of file
+ignore_missing_imports = False
index 6f51b3e78af4414f9200ef48555f92bf4f6436c6..785aedac7820f102d3b3cff7e4db881f05eb0d8b 100644 (file)
@@ -1,3 +1,4 @@
+# type: ignore
 import argparse
 import mock
 import os