]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr: Add ceph_module.pyi to improve type checking
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 6 Jan 2020 14:00:13 +0000 (15:00 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 23 Jan 2020 16:34:22 +0000 (17:34 +0100)
ceph_module.pyi is an interface definition of classes that are generated within C++.
Used by mypy to do proper type checking of mgr modules.
Without this file, all classes have undefined base classes.

Now, we're also finding accesses to undefinied class properties.

Secondly, this also improves the development experience when using IDEs.

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/CMakeLists.txt
src/pybind/mgr/ceph_module.pyi [new file with mode: 0644]
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/mgr_module.py

index 3d58d0904f0946666ba7a2517187d51506f2012f..de237e29c45b374195003cb261b99d6782976b9d 100644 (file)
@@ -15,6 +15,7 @@ install(DIRECTORY
   DESTINATION ${CEPH_INSTALL_DATADIR}
   REGEX "CMakeLists.txt" EXCLUDE
   REGEX "\\.gitignore" EXCLUDE
+  REGEX ".*\\.pyi" EXCLUDE
   REGEX "hello/.*" EXCLUDE
   REGEX "tests/.*" EXCLUDE
   REGEX "osd_perf_query/.*" EXCLUDE
diff --git a/src/pybind/mgr/ceph_module.pyi b/src/pybind/mgr/ceph_module.pyi
new file mode 100644 (file)
index 0000000..d71259c
--- /dev/null
@@ -0,0 +1,73 @@
+# This is an interface definition of classes that are generated within C++.
+# Used by mypy to do proper type checking of mgr modules.
+# Without this file, all classes have undefined base classes.
+
+class BasePyOSDMap(object):
+    def _get_epoch(self): ...
+    def _get_crush_version(self): ...
+    def _dump(self):...
+    def _new_incremental(self):...
+    def _apply_incremental(self, inc:int):...
+    def _get_crush(self):...
+    def _get_pools_by_take(self, take):...
+    def _calc_pg_upmaps(self, inc, max_deviation, max_iterations, pool):...
+    def _map_pool_pgs_up(self, poolid):...
+    def _pg_to_up_acting_osds(self, pool_id, ps):...
+    def _pool_raw_used_rate(self, pool_id):...
+
+class BasePyOSDMapIncremental(object):
+    def _get_epoch(self):...
+    def _dump(self):...
+    def _set_osd_reweights(self, weightmap):...
+    def _set_crush_compat_weight_set_weights(self, weightmap):...
+
+class BasePyCRUSH(object):
+    def _dump(self):...
+    def _get_item_weight(self, item):...
+    def _get_item_name(self, item):...
+    def _find_takes(self):...
+    def _get_take_weight_osd_map(self, root):...
+
+class BaseMgrStandbyModule(object):
+    def __init__(self, capsule): pass
+    def _ceph_get_mgr_id(self):...
+    def _ceph_get_module_option(self, key, prefix=None):...
+    def _ceph_get_option(self, key):...
+    def _ceph_get_store(self, key):...
+    def _ceph_get_active_uri(self):...
+
+class BaseMgrModule(object):
+    def __init__(self, py_modules_ptr, this_ptr): pass
+    def _ceph_get_version(self):...
+    def _ceph_get_release_name(self):...
+    def _ceph_cluster_log(self, channel, priority, message):...
+    def _ceph_get_context(self):...
+    def _ceph_get(self, data_name):...
+    def _ceph_get_server(self, hostname):...
+    def _ceph_get_perf_schema(self, svc_type, svc_name):...
+    def _ceph_get_counter(self, svc_type, svc_name, path):...
+    def _ceph_get_latest_counter(self, svc_type, svc_name, path):...
+    def _ceph_get_metadata(self, svc_type, svc_id):...
+    def _ceph_get_daemon_status(self, svc_type, svc_id):...
+    def _ceph_send_command(self, *args, **kwargs):...
+    def _ceph_set_health_checks(self, checks):...
+    def _ceph_get_mgr_id(self):...
+    def _ceph_get_option(self, key):...
+    def _ceph_get_module_option(self, key, default, localized_prefix=""):...
+    def _ceph_get_store_prefix(self, key_prefix):...
+    def _ceph_set_module_option(self, module, key, val):...
+    def _ceph_set_store(self, key, val):...
+    def _ceph_get_store(self, key):...
+    def _ceph_get_osdmap(self):...
+    def _ceph_set_uri(self, uri):...
+    def _ceph_have_mon_connection(self):...
+    def _ceph_update_progress_event(self, evid, desc, progress):...
+    def _ceph_complete_progress_event(self, evid):...
+    def _ceph_clear_all_progress_events(self):...
+    def _ceph_dispatch_remote(self, module_name, method_name, *args, **kwargs):...
+    def _ceph_add_osd_perf_query(self, query):...
+    def _ceph_remove_osd_perf_query(self, query_id):...
+    def _ceph_get_osd_perf_counters(self, query_id):...
+    def _ceph_unregister_client(self, addrs):...
+    def _ceph_register_client(self, addrs):...
+    def _ceph_is_authorized(self, arguments):...
index d64701b71bda9775a71e2a30fe6ca670df628418..59f208eb281eb259769435139850d4b58d10b7d9 100644 (file)
@@ -642,7 +642,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         ssh_options = []  # type: List[str]
 
         # ssh_config
-        ssh_config_fname = self.ssh_config_file
+        ssh_config_fname = self.ssh_config_file  # type: ignore
         ssh_config = self.get_store("ssh_config")
         if ssh_config is not None or ssh_config_fname is None:
             if not ssh_config:
@@ -683,9 +683,9 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             self._ssh_options = None
         self.log.info('ssh_options %s' % ssh_options)
 
-        if self.mode == 'root':
+        if self.mode == 'root':  # type: ignore
             self.ssh_user = 'root'
-        elif self.mode == 'cephadm-package':
+        elif self.mode == 'cephadm-package':  # type: ignore
             self.ssh_user = 'cephadm'
 
     @staticmethod
@@ -876,7 +876,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
                 final_args += ['--fsid', self._cluster_fsid]
             final_args += args
 
-            if self.mode == 'root':
+            if self.mode == 'root':  # type: ignore
                 self.log.debug('args: %s' % (' '.join(final_args)))
                 self.log.debug('stdin: %s' % stdin)
                 script = 'injected_argv = ' + json.dumps(final_args) + '\n'
@@ -897,7 +897,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
                     if error_ok:
                         return '', str(e), 1
                     raise
-            elif self.mode == 'cephadm-package':
+            elif self.mode == 'cephadm-package':  # type: ignore
                 try:
                     out, err, code = remoto.process.check(
                         conn,
@@ -907,6 +907,9 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
                     if error_ok:
                         return '', str(e), 1
                     raise
+            else:
+                assert False, 'unsupported mode'
+
             if code and not error_ok:
                 raise RuntimeError(
                     'cephadm exited with an error code: %d, stderr:%s' % (
@@ -1014,7 +1017,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             keys = [node_name]
         for host, host_info in self.service_cache.items_filtered(keys):
             hosts.append(host)
-            if host_info.outdated(self.service_cache_timeout) or refresh:
+            if host_info.outdated(self.service_cache_timeout) or refresh:  # type: ignore
                 self.log.info("refreshing stale services for '{}'".format(host))
                 wait_for_args.append((host,))
             else:
@@ -1151,7 +1154,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         def _get_inventory(host, host_info):
             # type: (str, orchestrator.OutdatableData) -> orchestrator.InventoryNode
 
-            if host_info.outdated(self.inventory_cache_timeout) or refresh:
+            if host_info.outdated(self.inventory_cache_timeout) or refresh:  # type: ignore
                 self.log.info("refresh stale inventory for '{}'".format(host))
                 out, err, code = self._run_cephadm(
                     host, 'osd',
@@ -1748,7 +1751,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
 
     def upgrade_check(self, image, version):
         if version:
-            target_name = self.container_image_base + ':v' + version
+            target_name = self.container_image_base + ':v' + version  # type: ignore
         elif image:
             target_name = image
         else:
@@ -1793,7 +1796,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
 
     def upgrade_start(self, image, version):
         if version:
-            target_name = self.container_image_base + ':v' + version
+            target_name = self.container_image_base + ':v' + version  # type: ignore
         elif image:
             target_name = image
         else:
index 11e965fbda2a30c04c732233707e10c7d0324078..c79709790656bd9ac5756cf5987ca5fa59a17404 100644 (file)
@@ -223,7 +223,7 @@ class CRUSHMap(ceph_module.BasePyCRUSH):
         try:
             first_take = [s for s in rule['steps'] if s['op'] == 'take'][0]
         except IndexError:
-            self.log.warn("CRUSH rule '{0}' has no 'take' step".format(
+            logging.warning("CRUSH rule '{0}' has no 'take' step".format(
                 rule_name))
             return None
         else: