From 2465f986680cc489bc82ec2a6f5652b24cdf171b Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Tue, 23 Feb 2021 14:42:38 +0100 Subject: [PATCH] mgr/cephadm: drop `create_func` arg from _add_daemon Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 93 +++++++++++--------------------- 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index e6d19115b09..a04f5e38bef 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -11,7 +11,7 @@ from threading import Event import string from typing import List, Dict, Optional, Callable, Tuple, TypeVar, \ - Any, Set, TYPE_CHECKING, cast, NamedTuple, Sequence + Any, Set, TYPE_CHECKING, cast, NamedTuple, Sequence, Type import datetime import os @@ -411,41 +411,19 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self.migration = Migrations(self) - # services: - self.osd_service = OSDService(self) - self.nfs_service = NFSService(self) - self.mon_service = MonService(self) - self.mgr_service = MgrService(self) - self.mds_service = MdsService(self) - self.rgw_service = RgwService(self) - self.rbd_mirror_service = RbdMirrorService(self) - self.grafana_service = GrafanaService(self) - self.alertmanager_service = AlertmanagerService(self) - self.prometheus_service = PrometheusService(self) - self.node_exporter_service = NodeExporterService(self) - self.crash_service = CrashService(self) - self.iscsi_service = IscsiService(self) - self.ha_rgw_service = HA_RGWService(self) - self.container_service = CustomContainerService(self) - self.cephadm_exporter_service = CephadmExporter(self) - self.cephadm_services = { - 'mon': self.mon_service, - 'mgr': self.mgr_service, - 'osd': self.osd_service, - 'mds': self.mds_service, - 'rgw': self.rgw_service, - 'rbd-mirror': self.rbd_mirror_service, - 'nfs': self.nfs_service, - 'grafana': self.grafana_service, - 'alertmanager': self.alertmanager_service, - 'prometheus': self.prometheus_service, - 'node-exporter': self.node_exporter_service, - 'crash': self.crash_service, - 'iscsi': self.iscsi_service, - 'ha-rgw': self.ha_rgw_service, - 'container': self.container_service, - 'cephadm-exporter': self.cephadm_exporter_service, - } + _service_clses: Sequence[Type[CephadmService]] = [ + OSDService, NFSService, MonService, MgrService, MdsService, + RgwService, RbdMirrorService, GrafanaService, AlertmanagerService, + PrometheusService, NodeExporterService, CrashService, IscsiService, + HA_RGWService, CustomContainerService, CephadmExporter + ] + + # https://github.com/python/mypy/issues/8993 + self.cephadm_services: Dict[str, CephadmService] = { + cls.TYPE: cls(self) for cls in _service_clses} # type: ignore + + self.mgr_service: MgrService = cast(MgrService, self.cephadm_services['mgr']) + self.osd_service: OSDService = cast(OSDService, self.cephadm_services['osd']) self.template = TemplateMgr(self) @@ -2017,8 +1995,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, def _add_daemon(self, daemon_type: str, - spec: ServiceSpec, - create_func: Callable[..., CephadmDaemonDeploySpec]) -> List[str]: + spec: ServiceSpec) -> List[str]: """ Add (and place) a daemon. Require explicit host placement. Do not schedule, and do not apply the related scheduling limitations. @@ -2034,16 +2011,14 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, count = spec.placement.count or len(spec.placement.hosts) daemons = self.cache.get_daemons_by_service(spec.service_name()) return self._create_daemons(daemon_type, spec, daemons, - spec.placement.hosts, count, - create_func) + spec.placement.hosts, count) def _create_daemons(self, daemon_type: str, spec: ServiceSpec, daemons: List[DaemonDescription], hosts: List[HostPlacementSpec], - count: int, - create_func: Callable[..., CephadmDaemonDeploySpec]) -> List[str]: + count: int) -> List[str]: if count > len(hosts): raise OrchestratorError('too few hosts: want %d, have %s' % ( count, hosts)) @@ -2077,7 +2052,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @ forall_hosts def create_func_map(*args: Any) -> str: - daemon_spec = create_func(*args) + daemon_spec = self.cephadm_services[daemon_type].prepare_create(*args) return CephadmServe(self)._create_daemon(daemon_spec) return create_func_map(args) @@ -2089,12 +2064,12 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_mon(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('mon', spec, self.mon_service.prepare_create) + return self._add_daemon('mon', spec) @handle_orch_error def add_mgr(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('mgr', spec, self.mgr_service.prepare_create) + return self._add_daemon('mgr', spec) def _apply(self, spec: GenericSpec) -> str: if spec.service_type == 'host': @@ -2195,7 +2170,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_mds(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('mds', spec, self.mds_service.prepare_create) + return self._add_daemon('mds', spec) @handle_orch_error def apply_mds(self, spec: ServiceSpec) -> str: @@ -2203,7 +2178,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_rgw(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('rgw', spec, self.rgw_service.prepare_create) + return self._add_daemon('rgw', spec) @handle_orch_error def apply_rgw(self, spec: ServiceSpec) -> str: @@ -2216,7 +2191,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_iscsi(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('iscsi', spec, self.iscsi_service.prepare_create) + return self._add_daemon('iscsi', spec) @handle_orch_error def apply_iscsi(self, spec: ServiceSpec) -> str: @@ -2224,7 +2199,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_rbd_mirror(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('rbd-mirror', spec, self.rbd_mirror_service.prepare_create) + return self._add_daemon('rbd-mirror', spec) @handle_orch_error def apply_rbd_mirror(self, spec: ServiceSpec) -> str: @@ -2232,7 +2207,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_nfs(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('nfs', spec, self.nfs_service.prepare_create) + return self._add_daemon('nfs', spec) @handle_orch_error def apply_nfs(self, spec: ServiceSpec) -> str: @@ -2244,7 +2219,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_prometheus(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('prometheus', spec, self.prometheus_service.prepare_create) + return self._add_daemon('prometheus', spec) @handle_orch_error def apply_prometheus(self, spec: ServiceSpec) -> str: @@ -2253,8 +2228,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_node_exporter(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('node-exporter', spec, - self.node_exporter_service.prepare_create) + return self._add_daemon('node-exporter', spec) @handle_orch_error def apply_node_exporter(self, spec: ServiceSpec) -> str: @@ -2263,8 +2237,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_crash(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('crash', spec, - self.crash_service.prepare_create) + return self._add_daemon('crash', spec) @handle_orch_error def apply_crash(self, spec: ServiceSpec) -> str: @@ -2273,7 +2246,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_grafana(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('grafana', spec, self.grafana_service.prepare_create) + return self._add_daemon('grafana', spec) @handle_orch_error def apply_grafana(self, spec: ServiceSpec) -> str: @@ -2282,7 +2255,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_alertmanager(self, spec): # type: (ServiceSpec) -> List[str] - return self._add_daemon('alertmanager', spec, self.alertmanager_service.prepare_create) + return self._add_daemon('alertmanager', spec) @handle_orch_error def apply_alertmanager(self, spec: ServiceSpec) -> str: @@ -2290,8 +2263,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, @handle_orch_error def add_container(self, spec: ServiceSpec) -> List[str]: - return self._add_daemon('container', spec, - self.container_service.prepare_create) + return self._add_daemon('container', spec) @handle_orch_error def apply_container(self, spec: ServiceSpec) -> str: @@ -2301,8 +2273,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, def add_cephadm_exporter(self, spec): # type: (ServiceSpec) -> List[str] return self._add_daemon('cephadm-exporter', - spec, - self.cephadm_exporter_service.prepare_create) + spec) @handle_orch_error def apply_cephadm_exporter(self, spec: ServiceSpec) -> str: -- 2.39.5