From 54ec595811979ca9f5dd0424977e2a959a485ddd Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 15 Mar 2020 11:52:54 +0800 Subject: [PATCH] pybind/mgr: apply_drivegroups should return Sequence[Completion] * change annotation of `orchestrator.Orchestrator.apply_drivegroups()` so it returns `Sequence[Completion]` see https://mypy.readthedocs.io/en/latest/generics.html#variance-of-generic-types * to follow the interface defined by `orchestrator.Orchestrator`. change all its implementations. see `orchestrator/_interface.py`. Signed-off-by: Kefu Chai --- src/pybind/mgr/cephadm/module.py | 5 +++-- src/pybind/mgr/orchestrator/_interface.py | 2 +- src/pybind/mgr/test_orchestrator/module.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index e4bbcaf78aa..6d9bfbf0536 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -10,7 +10,8 @@ from mgr_util import create_self_signed_cert, verify_tls, ServerConfigException import string try: - from typing import List, Dict, Optional, Callable, Tuple, TypeVar, Type, Any, NamedTuple, Iterator, Set + from typing import List, Dict, Optional, Callable, Tuple, TypeVar, Type, \ + Any, NamedTuple, Iterator, Set, Sequence from typing import TYPE_CHECKING except ImportError: TYPE_CHECKING = False # just for type checking @@ -1949,7 +1950,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): r[str(o['osd'])] = o['uuid'] return r - def apply_drivegroups(self, specs: List[DriveGroupSpec]) -> List[orchestrator.Completion]: + def apply_drivegroups(self, specs: List[DriveGroupSpec]) -> Sequence[orchestrator.Completion]: completions: List[orchestrator.Completion] = list() for spec in specs: completions.extend(self._apply(spec)) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 5a83120b065..e7ed20a903f 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -913,7 +913,7 @@ class Orchestrator(object): """ raise NotImplementedError() - def apply_drivegroups(self, specs: List[DriveGroupSpec]) -> List[Completion]: + def apply_drivegroups(self, specs: List[DriveGroupSpec]) -> Sequence[Completion]: """ Update OSD cluster """ raise NotImplementedError() diff --git a/src/pybind/mgr/test_orchestrator/module.py b/src/pybind/mgr/test_orchestrator/module.py index 5f22e30ce0d..c8db5b7ae1f 100644 --- a/src/pybind/mgr/test_orchestrator/module.py +++ b/src/pybind/mgr/test_orchestrator/module.py @@ -10,7 +10,7 @@ from subprocess import check_output, CalledProcessError from ceph.deployment.service_spec import NFSServiceSpec, ServiceSpec try: - from typing import Callable, List, Tuple + from typing import Callable, List, Sequence, Tuple except ImportError: pass # type checking @@ -259,7 +259,7 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): ) def apply_drivegroups(self, specs): - # type: (List[DriveGroupSpec]) -> TestCompletion + # type: (List[DriveGroupSpec]) -> Sequence[TestCompletion] drive_group = specs[0] def run(all_hosts): # type: (List[orchestrator.HostSpec]) -> None @@ -267,12 +267,12 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): if drive_group.placement.host_pattern: if not drive_group.placement.pattern_matches_hosts([h.hostname for h in all_hosts]): raise orchestrator.OrchestratorValidationError('failed to match') - return self.get_hosts().then(run).then( + return [self.get_hosts().then(run).then( on_complete=orchestrator.ProgressReference( message='apply_drivesgroups', mgr=self, ) - ) + )] @deferred_write("remove_daemons") def remove_daemons(self, names, force): -- 2.39.5