]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: Enable basic mypy support for qa/ directory 32495/head
authorThomas Bechtold <tbechtold@suse.com>
Thu, 9 Jan 2020 07:28:22 +0000 (08:28 +0100)
committerThomas Bechtold <tbechtold@suse.com>
Thu, 5 Mar 2020 05:54:56 +0000 (06:54 +0100)
A first step to do more automatic code checks on the qa/
directory. This is useful while transitioning to python3.

Also use log_exc to top-level to not run into:

error: Argument 1 to "log_exc" has incompatible type
  "Callable[[OSDThrasher], Any]"; expected "OSDThrasher"

Signed-off-by: Thomas Bechtold <tbechtold@suse.com>
qa/mypy.ini [new file with mode: 0644]
qa/tasks/ceph_manager.py
qa/tasks/cephfs/cephfs_test_case.py
qa/tasks/cephfs/test_full.py
qa/tox.ini
src/test/rgw/rgw_multi/tests.py
src/test/rgw/rgw_multi/zone_cloud.py
src/test/rgw/rgw_multi/zone_es.py
src/test/rgw/rgw_multi/zone_rados.py

diff --git a/qa/mypy.ini b/qa/mypy.ini
new file mode 100644 (file)
index 0000000..1215375
--- /dev/null
@@ -0,0 +1,2 @@
+[mypy]
+ignore_missing_imports = True
\ No newline at end of file
index eae0fe0b5032401cf6329d9c1c7efe68a8ec423f..aea091f65cf4f0f1702e967021a13e5ea9205a81 100644 (file)
@@ -29,7 +29,7 @@ import six
 try:
     from subprocess import DEVNULL # py3k
 except ImportError:
-    DEVNULL = open(os.devnull, 'r+')
+    DEVNULL = open(os.devnull, 'r+')  # type: ignore
 
 DEFAULT_CONF_PATH = '/etc/ceph/ceph.conf'
 
@@ -116,6 +116,17 @@ def mount_osd_data(ctx, remote, cluster, osd):
             )
 
 
+def log_exc(func):
+    @wraps(func)
+    def wrapper(self):
+        try:
+            return func(self)
+        except:
+            self.log(traceback.format_exc())
+            raise
+    return wrapper
+
+
 class PoolType:
     REPLICATED = 1
     ERASURE_CODED = 3
@@ -1067,16 +1078,6 @@ class OSDThrasher(Thrasher):
             # Allow successful completion so gevent doesn't see an exception.
             # The DaemonWatchdog will observe the error and tear down the test.
 
-    def log_exc(func):
-        @wraps(func)
-        def wrapper(self):
-            try:
-                return func(self)
-            except:
-                self.log(traceback.format_exc())
-                raise
-        return wrapper
-
     @log_exc
     def do_sighup(self):
         """
@@ -2179,13 +2180,13 @@ class CephManager:
                 ret[status] += 1
         return ret
 
-    @wait_for_pg_stats
+    @wait_for_pg_stats # type: ignore
     def with_pg_state(self, pool, pgnum, check):
         pgstr = self.get_pgid(pool, pgnum)
         stats = self.get_single_pg_stats(pgstr)
         assert(check(stats['state']))
 
-    @wait_for_pg_stats
+    @wait_for_pg_stats # type: ignore
     def with_pg(self, pool, pgnum, check):
         pgstr = self.get_pgid(pool, pgnum)
         stats = self.get_single_pg_stats(pgstr)
index 98a18b3d550f3efe57e3df0a94fcfc6f47b87387..d9464dd4135aa24389a5e0530515e89eb40f5123 100644 (file)
@@ -58,7 +58,7 @@ class CephFSTestCase(CephTestCase):
     # requires REQUIRE_FILESYSTEM = True
     REQUIRE_RECOVERY_FILESYSTEM = False
 
-    LOAD_SETTINGS = []
+    LOAD_SETTINGS = [] # type: ignore
 
     def setUp(self):
         super(CephFSTestCase, self).setUp()
index 10f111ae635273ca5279dfabc7fe357e7e967f7e..112407de18c32e3185e8113bbd7d5321484e155d 100644 (file)
@@ -1,10 +1,13 @@
-
-
 import json
 import logging
 import os
 from textwrap import dedent
 import time
+try:
+    from typing import Optional
+except:
+    # make it work for python2
+    pass
 from teuthology.orchestra.run import CommandFailedError
 from tasks.cephfs.fuse_mount import FuseMount
 from tasks.cephfs.cephfs_test_case import CephFSTestCase
@@ -20,7 +23,7 @@ class FullnessTestCase(CephFSTestCase):
     data_only = False
 
     # Subclasses define how many bytes should be written to achieve fullness
-    pool_capacity = None
+    pool_capacity = None  # type: Optional[int]
     fill_mb = None
 
     # Subclasses define what fullness means to them
@@ -364,8 +367,8 @@ class TestQuotaFull(FullnessTestCase):
     """
     Test per-pool fullness, which indicates quota limits exceeded
     """
-    pool_capacity = 1024 * 1024 * 32   # arbitrary low-ish limit
-    fill_mb = pool_capacity / (1024 * 1024)
+    pool_capacity = 1024 * 1024 * 32  # arbitrary low-ish limit
+    fill_mb = pool_capacity / (1024 * 1024)  # type: ignore
 
     # We are only testing quota handling on the data pool, not the metadata
     # pool.
index 16792011cff98aadba5d82da6757b95df8b7bf34..041c6ed298e665ffdc627bc9b5c86f6c0c1dbc1c 100644 (file)
@@ -1,5 +1,5 @@
 [tox]
-envlist = flake8-py2, flake8-py3
+envlist = flake8-py2, flake8-py3, mypy
 skipsdist = True
 
 [testenv:flake8-py2]
@@ -14,3 +14,7 @@ deps=
   flake8
 commands=flake8 --select=F,E9 --exclude=venv,.tox
 
+[testenv:mypy]
+basepython = python3
+deps = mypy
+commands = mypy {posargs:.}
index 6cada052d3dfcc477552557349cd16104c76d49a..598356dff0e12ea06efa5a50aa110a5dbb152cc2 100644 (file)
@@ -7,7 +7,7 @@ import logging
 import errno
 
 try:
-    from itertools import izip_longest as zip_longest
+    from itertools import izip_longest as zip_longest  # type: ignore
 except ImportError:
     from itertools import zip_longest
 from itertools import combinations
index fdfca4f1eca12973af9b6780e2d56282588d48c0..83bfae19e6c1cf1c9fbc6389f25b1738a0ad0824 100644 (file)
@@ -12,7 +12,7 @@ import re
 
 from nose.tools import eq_ as eq
 try:
-    from itertools import izip_longest as zip_longest
+    from itertools import izip_longest as zip_longest  # type: ignore
 except ImportError:
     from itertools import zip_longest
 
index ec9b178fd16889671b01ee9f993a7a75d131a2f6..1f85744a49cec8f196f6b77b54b80438bdb6b03f 100644 (file)
@@ -9,7 +9,7 @@ import dateutil.parser
 
 from nose.tools import eq_ as eq
 try:
-    from itertools import izip_longest as zip_longest
+    from itertools import izip_longest as zip_longest  # type: ignore
 except ImportError:
     from itertools import zip_longest
 
index e645e9abe89fa2068ebcd0c0e5a83409c162e82f..3b298e8b42f78c2f55d71dbf44a58afd83d04c53 100644 (file)
@@ -2,7 +2,7 @@ import logging
 from boto.s3.deletemarker import DeleteMarker
 
 try:
-    from itertools import izip_longest as zip_longest
+    from itertools import izip_longest as zip_longest  # type: ignore
 except ImportError:
     from itertools import zip_longest