From 6bfc4589f55c76d50cc87f75c4018860167f7708 Mon Sep 17 00:00:00 2001 From: Joshua Schmid Date: Tue, 14 Jul 2020 17:01:34 +0200 Subject: [PATCH] python-common/deployment: respect existing osds Fixes: https://tracker.ceph.com/issues/44888 Signed-off-by: Joshua Schmid --- src/pybind/mgr/cephadm/services/osd.py | 7 ++++++- .../deployment/drive_selection/selector.py | 20 ++++--------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/cephadm/services/osd.py b/src/pybind/mgr/cephadm/services/osd.py index b41fc6072c390..1ce2c289ffc83 100644 --- a/src/pybind/mgr/cephadm/services/osd.py +++ b/src/pybind/mgr/cephadm/services/osd.py @@ -124,8 +124,13 @@ class OSDService(CephadmService): for host in matching_hosts: inventory_for_host = _find_inv_for_host(host, self.mgr.cache.devices) logger.debug(f"Found inventory for host {inventory_for_host}") + + # List of Daemons on that host + dd_for_spec = self.mgr.cache.get_daemons_by_service(drive_group.service_name()) + dd_for_spec_and_host = [dd for dd in dd_for_spec if dd.hostname == host] + drive_selection = DriveSelection(drive_group, inventory_for_host, - self.mgr.cache.get_daemons_with_volatile_status()) + existing_daemons=len(dd_for_spec_and_host)) logger.debug(f"Found drive selection {drive_selection}") host_ds_map.append((host, drive_selection)) return host_ds_map diff --git a/src/python-common/ceph/deployment/drive_selection/selector.py b/src/python-common/ceph/deployment/drive_selection/selector.py index 255d652777cbc..681be39b245da 100644 --- a/src/python-common/ceph/deployment/drive_selection/selector.py +++ b/src/python-common/ceph/deployment/drive_selection/selector.py @@ -1,7 +1,7 @@ import logging try: - from typing import List, Optional, Iterator, Tuple, Dict + from typing import List, Optional except ImportError: pass @@ -17,12 +17,11 @@ class DriveSelection(object): def __init__(self, spec, # type: DriveGroupSpec disks, # type: List[Device] - daemons=None, # type: Iterator[Tuple[str, Dict[str, "DaemonDescription"]]] + existing_daemons=None, # type: Optional[int] ): self.disks = disks.copy() self.spec = spec - self.daemons = daemons - self.osds_for_spec = self.find_osds_in_spec() + self.existing_daemons = existing_daemons or 0 if self.spec.data_devices.paths: # type: ignore # re: type: ignore there is *always* a path attribute assigned to DeviceSelection @@ -37,17 +36,6 @@ class DriveSelection(object): self._db = self.assign_devices(self.spec.db_devices) self._journal = self.assign_devices(self.spec.journal_devices) - def find_osds_in_spec(self) -> List["DaemonDescription"]: - osds: List["DaemonDescription"] = [] - if not self.daemons: - return osds - for host, dm in self.daemons: - for name, dd in dm.items(): - if dd.daemon_type == 'osd': - if dd.osdspec_affinity == self.spec.service_id: - osds.append(dd) - return osds - def data_devices(self): # type: () -> List[Device] return self._data @@ -81,7 +69,7 @@ class DriveSelection(object): """ limit = device_filter.limit or 0 - if limit > 0 and len_devices >= limit: + if limit > 0 and (len_devices + self.existing_daemons >= limit): logger.info("Refuse to add {} due to limit policy of <{}>".format( disk_path, limit)) return True -- 2.39.5