Skip to content

Commit dd7d119

Browse files
committed
mgr/cephadm: disallow changing OSD service type to non-OSD types
Prevent accidental or invalid service type changes for OSD daemons by enforcing that an OSD's service type cannot be changed to a different service type (e.g., mon, mds, etc.) Fixes: https://tracker.ceph.com/issues/71087 Signed-off-by: Joshua Blanch <[email protected]>
1 parent ed7bb4f commit dd7d119

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/pybind/mgr/cephadm/module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,12 @@ def set_osd_spec(self, service_name: str, osd_ids: List[str]) -> str:
41204120
"Please try again after applying an OSD service that matches "
41214121
"the service name to which you want to attach OSDs.")
41224122

4123+
# Verify that service_type is of osd type
4124+
spec = self.spec_store[service_name].spec
4125+
if spec.service_type != 'osd':
4126+
raise OrchestratorError(f"Service '{service_name}' is not an OSD service (type: {spec.service_type}). "
4127+
"OSDs can only be assigned to OSD service specs.")
4128+
41234129
daemons: List[orchestrator.DaemonDescription] = self.cache.get_daemons_by_type('osd')
41244130
update_osd = defaultdict(list)
41254131
for daemon in daemons:

src/pybind/mgr/cephadm/tests/test_cephadm.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,3 +2877,33 @@ def _get_nvmeof_daemons(sname) -> List[DaemonDescription]:
28772877
# on nvmeof.foo.foo's daemons
28782878
nvmeof_bar_blocking_hosts = NvmeofService(cephadm_module).get_blocking_daemon_hosts('nvmeof.bar.bar')
28792879
assert set([h.hostname for h in nvmeof_bar_blocking_hosts]) == set(['host1', 'host2'])
2880+
2881+
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
2882+
@mock.patch("cephadm.inventory.HostCache.get_daemons_by_type")
2883+
def test_set_osd_spec_non_osd_service(self, _get_daemons_by_type, cephadm_module):
2884+
with with_host(cephadm_module, 'test'):
2885+
osd_daemon = DaemonDescription(daemon_type='osd', daemon_id='1', hostname='test')
2886+
_get_daemons_by_type.return_value = [osd_daemon]
2887+
2888+
mgr_service = ServiceSpec('mgr', placement=PlacementSpec(hosts=['test']))
2889+
2890+
with with_service(cephadm_module, mgr_service):
2891+
with pytest.raises(OrchestratorError) as e:
2892+
cephadm_module.set_osd_spec('mgr', ['1'])
2893+
2894+
assert "Service 'mgr' is not an OSD service (type: mgr). OSDs can only be assigned to OSD service specs." in str(e.value)
2895+
2896+
# Move osd.1 to osd.foo service
2897+
spec = DriveGroupSpec(
2898+
service_id='foo',
2899+
placement=PlacementSpec(
2900+
host_pattern='*',
2901+
),
2902+
data_devices=DeviceSelection(
2903+
all=True
2904+
)
2905+
)
2906+
c = cephadm_module.apply([spec])
2907+
assert wait(cephadm_module, c) == ['Scheduled osd.foo update...']
2908+
2909+
cephadm_module.set_osd_spec('osd.foo', ['1'])

0 commit comments

Comments
 (0)