From 49c2da65d93e1a01781baf05ff022526403aca66 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 12 Nov 2019 11:28:25 +0100 Subject: [PATCH] mgr: Python cleanup and type check - Add/remove missing/obsolete empty lines - Add type check doc - Rename inner function args to make pylint happy Signed-off-by: Volker Theile --- src/pybind/mgr/orchestrator.py | 6 +++++- src/pybind/mgr/orchestrator_cli/module.py | 3 ++- src/pybind/mgr/ssh/module.py | 24 ++++++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index dc9e57f2fe9..683675cc051 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -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 diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 6f9f3c30008..8ba3f0fe73e 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -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') diff --git a/src/pybind/mgr/ssh/module.py b/src/pybind/mgr/ssh/module.py index 62beeb7abe5..d36757d81ed 100644 --- a/src/pybind/mgr/ssh/module.py +++ b/src/pybind/mgr/ssh/module.py @@ -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: -- 2.47.3