]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rook: Added Mypy static type checking 32127/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 9 Dec 2019 14:55:41 +0000 (15:55 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 9 Dec 2019 14:55:41 +0000 (15:55 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/orchestrator.py
src/pybind/mgr/requirements.txt
src/pybind/mgr/rook/module.py
src/pybind/mgr/rook/rook_cluster.py
src/pybind/mgr/tox.ini

index 65120ac87b120907473fd81dfb6b6dfc14d80da1..3b8b8909c0204235ba4b98f045bd6ca7280097bc 100644 (file)
@@ -26,7 +26,8 @@ from mgr_util import format_bytes
 
 try:
     from ceph.deployment.drive_group import DriveGroupSpec
-    from typing import TypeVar, Generic, List, Optional, Union, Tuple, Iterator, Callable, Any, Type
+    from typing import TypeVar, Generic, List, Optional, Union, Tuple, Iterator, Callable, Any, \
+        Type, Sequence
 except ImportError:
     pass
 
@@ -606,7 +607,7 @@ class Completion(_Promise):
 
 
 def pretty_print(completions):
-    # type: (List[Completion]) -> str
+    # type: (Sequence[Completion]) -> str
     return ', '.join(c.pretty_print() for c in completions)
 
 
index fe76eee7964f6937bcf09f8449ebe4a7d04d465a..c60dc4a8982d66923d829227e56e7b8c079c73f8 100644 (file)
@@ -2,3 +2,4 @@ pytest-cov==2.7.1
 mock; python_version <= '3.3'
 ipaddress; python_version < '3.3'
 ../../python-common
+kubernetes
index 4b534d967f21bfdada459c8c1951826f2de30ee8..6ed4a0e917db9300845cde07866d8d4ceea18de1 100644 (file)
@@ -5,7 +5,7 @@ import os
 from ceph.deployment import inventory
 
 try:
-    from typing import List, Dict, Optional, Callable, TypeVar
+    from typing import List, Dict, Optional, Callable, Any
     from ceph.deployment.drive_group import DriveGroupSpec
 except ImportError:
     pass  # just for type checking
@@ -97,7 +97,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
 
     MODULE_OPTIONS = [
         # TODO: configure k8s API addr instead of assuming local
-    ]
+    ]  # type: List[Dict[str, Any]]
 
     def process(self, completions):
         # type: (List[RookCompletion]) -> None
@@ -146,13 +146,16 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
 
     @property
     def k8s(self):
+        # type: () -> client.CoreV1Api
         self._initialized.wait()
+        assert self._k8s is not None
         return self._k8s
 
     @property
     def rook_cluster(self):
         # type: () -> RookCluster
         self._initialized.wait()
+        assert self._rook_cluster is not None
         return self._rook_cluster
 
     def serve(self):
@@ -346,9 +349,11 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
 
     def update_mds(self, spec):
         num = spec.count
-        return RookWriteCompletion(
-            lambda: self.rook_cluster.update_mds_count(spec.name, num), None,
-                "Updating MDS server count in {0} to {1}".format(spec.name, num))
+        return write_completion(
+            lambda: self.rook_cluster.update_mds_count(spec.name, num),
+            "Updating MDS server count in {0} to {1}".format(spec.name, num),
+            mgr=self
+        )
 
     def update_nfs(self, spec):
         num = spec.count
@@ -395,7 +400,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
         def has_osds(all_hosts):
             # Find OSD pods on this host
             pod_osd_ids = set()
-            pods = self._k8s.list_namespaced_pod(self._rook_env.namespace,
+            pods = self.k8s.list_namespaced_pod(self._rook_env.namespace,
                                                  label_selector="rook_cluster={},app=rook-ceph-osd".format(self._rook_env.cluster_name),
                                                  field_selector="spec.nodeName={0}".format(
                                                      drive_group.hosts(all_hosts)[0]
index 4d4c3ed76e6d49cd59c2528a1265c19d0355a805..97fd2ddc4305846b1fe683be6705c7545e10beac 100644 (file)
@@ -19,12 +19,18 @@ from urllib3.exceptions import ProtocolError
 
 from mgr_util import merge_dicts
 
+try:
+    from typing import Optional
+except ImportError:
+    pass  # just for type annotations
+
 try:
     from kubernetes.client.rest import ApiException
     from kubernetes.client import V1ListMeta, CoreV1Api, V1Pod
     from kubernetes import watch
 except ImportError:
-    class ApiException(Exception): pass
+    class ApiException(Exception):  # type: ignore
+        status = 0
 
 
 import orchestrator
@@ -85,7 +91,7 @@ class KubernetesResource(object):
 
         # ``_items`` is accessed by different threads. I assume assignment is atomic.
         self._items = dict()
-        self.thread = None  # type: threading.Thread
+        self.thread = None  # type: Optional[threading.Thread]
         self.exception = None
         if not _urllib3_supports_read_chunked:
             logging.info('urllib3 is too old. Fallback to full fetches')
@@ -115,7 +121,7 @@ class KubernetesResource(object):
             if _urllib3_supports_read_chunked:
                 # Start a thread which will use the kubernetes watch client against a resource
                 log.debug("Attaching resource watcher for k8s {}".format(self.api_func))
-                self.thread = self._watch(resource_version)  # type: threading.Thread
+                self.thread = self._watch(resource_version)
 
         return self._items.values()
 
@@ -376,7 +382,7 @@ class RookCluster(object):
         }
 
         if spec.namespace:
-            rook_nfsgw["spec"]["rados"]["namespace"] = spec.namespace
+            rook_nfsgw["spec"]["rados"]["namespace"] = spec.namespace  # type: ignore
 
         with self.ignore_409("NFS cluster '{0}' already exists".format(spec.name)):
             self.rook_api_post("cephnfses/", body=rook_nfsgw)
@@ -525,7 +531,7 @@ class RookCluster(object):
             if directories:
                 pd["directories"] = [{'path': p} for p in directories]
 
-            patch.append({ "op": "add", "path": "/spec/storage/nodes/-", "value": pd })
+            patch.append({ "op": "add", "path": "/spec/storage/nodes/-", "value": pd })  # type: ignore
         else:
             # Extend existing node
             node_idx = None
@@ -544,7 +550,7 @@ class RookCluster(object):
                 patch.append({
                     "op": "add",
                     "path": "/spec/storage/nodes/{0}/devices/-".format(node_idx),
-                    "value": {'name': n}
+                    "value": {'name': n}  # type: ignore
                 })
 
             new_dirs = list(set(directories) - set(current_node['directories']))
@@ -552,7 +558,7 @@ class RookCluster(object):
                 patch.append({
                     "op": "add",
                     "path": "/spec/storage/nodes/{0}/directories/-".format(node_idx),
-                    "value": {'path': p}
+                    "value": {'path': p}  # type: ignore
                 })
 
         if len(patch) == 0:
index 15ea35bcaa8f8b86e274148d3578bdbf7d56333a..31a661a8f88d473b466f1a4fa70294c043d3ffbc 100644 (file)
@@ -12,4 +12,4 @@ basepython = python3
 deps =
     -r requirements.txt
     mypy
-commands = mypy --config-file=../../mypy.ini orchestrator.py ssh/module.py
\ No newline at end of file
+commands = mypy --config-file=../../mypy.ini orchestrator.py ssh/module.py rook/module.py
\ No newline at end of file