]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: Python cleanup and type check 31559/head
authorVolker Theile <vtheile@suse.com>
Tue, 12 Nov 2019 10:28:25 +0000 (11:28 +0100)
committerVolker Theile <vtheile@suse.com>
Tue, 12 Nov 2019 11:28:31 +0000 (12:28 +0100)
- Add/remove missing/obsolete empty lines
- Add type check doc
- Rename inner function args to make pylint happy

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/ssh/module.py

index dc9e57f2fe9ed7a686b0b80279d99932469626fa..683675cc051aa38fd00ca366d65fbb04cb9d2762 100644 (file)
@@ -236,10 +236,12 @@ class WriteCompletion(_Completion):
         """
         return not self.is_persistent
 
+
 def _hide_in_features(f):
     f._hide_in_features = True
     return f
 
+
 class Orchestrator(object):
     """
     Calls in this class may do long running remote operations, with time
@@ -332,7 +334,6 @@ class Orchestrator(object):
                 ... except (OrchestratorError, NotImplementedError):
                 ...     ...
 
-
         :returns: Dict of API method names to ``{'available': True or False}``
         """
         module = self.__class__
@@ -576,6 +577,7 @@ class Orchestrator(object):
         """
         raise NotImplementedError()
 
+
 class UpgradeSpec(object):
     # Request to orchestrator to initiate an upgrade to a particular
     # version of Ceph
@@ -1188,8 +1190,10 @@ class OutdatableDictMixin(object):
         self[key] = OutdatableData(self[key].data,
                                    datetime.datetime.fromtimestamp(0))
 
+
 class OutdatablePersistentDict(OutdatableDictMixin, PersistentStoreDict):
     pass
 
+
 class OutdatableDict(OutdatableDictMixin, dict):
     pass
index 6f9f3c30008b7c9e33bafbff9d950bd2580a37a0..8ba3f0fe73e49f8c4c0d163991915c5522720401 100644 (file)
@@ -41,6 +41,7 @@ def _cli_command(perm):
 _read_cli = _cli_command('r')
 _write_cli = _cli_command('rw')
 
+
 class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule):
     MODULE_OPTIONS = [
         {'name': 'orchestrator'}
@@ -89,7 +90,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule):
     def _get_device_locations(self, dev_id):
         # type: (str) -> List[orchestrator.DeviceLightLoc]
         locs = [d['location'] for d in self.get('devices')['devices'] if d['devid'] == dev_id]
-        return [orchestrator.DeviceLightLoc(**l) for l in  sum(locs, [])]
+        return [orchestrator.DeviceLightLoc(**l) for l in sum(locs, [])]
 
     @_read_cli(prefix='device ls-lights',
                desc='List currently active device indicator lights')
index 62beeb7abe55feea7931e2897f851c52846ce536..d36757d81edc57543f330249a9df01ab954abeec 100644 (file)
@@ -22,6 +22,11 @@ except ImportError as e:
     remoto = None
     remoto_import_error = str(e)
 
+try:
+    from typing import List
+except ImportError:
+    pass
+
 logger = logging.getLogger(__name__)
 
 DEFAULT_SSH_CONFIG = ('Host *\n'
@@ -32,6 +37,7 @@ DEFAULT_SSH_CONFIG = ('Host *\n'
 #  - bring over some of the protections from ceph-deploy that guard against
 #    multiple bootstrapping / initialization
 
+
 class SSHCompletionmMixin(object):
     def __init__(self, result):
         if isinstance(result, multiprocessing.pool.AsyncResult):
@@ -44,6 +50,7 @@ class SSHCompletionmMixin(object):
     def result(self):
         return list(map(lambda r: r.get(), self._result))
 
+
 class SSHReadCompletion(SSHCompletionmMixin, orchestrator.ReadCompletion):
     @property
     def is_complete(self):
@@ -69,6 +76,7 @@ class SSHWriteCompletion(SSHCompletionmMixin, orchestrator.WriteCompletion):
                 return True
         return False
 
+
 class SSHWriteCompletionReady(SSHWriteCompletion):
     def __init__(self, result):
         orchestrator.WriteCompletion.__init__(self)
@@ -90,6 +98,7 @@ class SSHWriteCompletionReady(SSHWriteCompletion):
     def is_errored(self):
         return False
 
+
 def log_exceptions(f):
     if six.PY3:
         return f
@@ -604,7 +613,6 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             self.log.debug('_service_action code %s out %s' % (code, out))
         return "{} {} from host '{}'".format(action, name, host)
 
-
     def get_inventory(self, node_filter=None, refresh=False):
         """
         Return the storage inventory of nodes matching the given filter.
@@ -626,7 +634,6 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         def run(host, host_info):
             # type: (str, orchestrator.OutdatableData) -> orchestrator.InventoryNode
 
-
             if host_info.outdated(self.inventory_cache_timeout) or refresh:
                 self.log.info("refresh stale inventory for '{}'".format(host))
                 out, code = self._run_ceph_daemon(
@@ -651,12 +658,15 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
 
     @log_exceptions
     def blink_device_light(self, ident_fault, on, locs):
-        def blink(host, dev, ident_fault, on):
+        # type: (str, bool, List[orchestrator.DeviceLightLoc]) -> SSHWriteCompletion
+
+        def blink(host, dev, ident_fault_, on_):
+            # type: (str, str, str, bool) -> str
             cmd = [
                 'lsmcli',
                 'local-disk-%s-led-%s' % (
-                    ident_fault,
-                    'on' if on else 'off'),
+                    ident_fault_,
+                    'on' if on_ else 'off'),
                 '--path', '/dev/' + dev,
             ]
             out, code = self._run_ceph_daemon(host, 'osd', 'shell', ['--'] + cmd,
@@ -664,9 +674,9 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             if code:
                 raise RuntimeError(
                     'Unable to affect %s light for %s:%s. Command: %s' % (
-                        ident_fault, host, dev, ' '.join(cmd)))
+                        ident_fault_, host, dev, ' '.join(cmd)))
             return "Set %s light for %s:%s %s" % (
-                ident_fault, host, dev, 'on' if on else 'off')
+                ident_fault_, host, dev, 'on' if on_ else 'off')
 
         results = []
         for loc in locs: