Skip to content

Commit 062f85c

Browse files
authored
Merge pull request ceph#62984 from JoshuaGabriel/jblanch_71087
mgr/cephadm: disallow changing OSD service type to non-OSD types Reviewed-by: Adam King <[email protected]>
2 parents 62b1b6a + dd7d119 commit 062f85c

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
@@ -2888,3 +2888,33 @@ def _get_nvmeof_daemons(sname) -> List[DaemonDescription]:
28882888
# on nvmeof.foo.foo's daemons
28892889
nvmeof_bar_blocking_hosts = NvmeofService(cephadm_module).get_blocking_daemon_hosts('nvmeof.bar.bar')
28902890
assert set([h.hostname for h in nvmeof_bar_blocking_hosts]) == set(['host1', 'host2'])
2891+
2892+
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
2893+
@mock.patch("cephadm.inventory.HostCache.get_daemons_by_type")
2894+
def test_set_osd_spec_non_osd_service(self, _get_daemons_by_type, cephadm_module):
2895+
with with_host(cephadm_module, 'test'):
2896+
osd_daemon = DaemonDescription(daemon_type='osd', daemon_id='1', hostname='test')
2897+
_get_daemons_by_type.return_value = [osd_daemon]
2898+
2899+
mgr_service = ServiceSpec('mgr', placement=PlacementSpec(hosts=['test']))
2900+
2901+
with with_service(cephadm_module, mgr_service):
2902+
with pytest.raises(OrchestratorError) as e:
2903+
cephadm_module.set_osd_spec('mgr', ['1'])
2904+
2905+
assert "Service 'mgr' is not an OSD service (type: mgr). OSDs can only be assigned to OSD service specs." in str(e.value)
2906+
2907+
# Move osd.1 to osd.foo service
2908+
spec = DriveGroupSpec(
2909+
service_id='foo',
2910+
placement=PlacementSpec(
2911+
host_pattern='*',
2912+
),
2913+
data_devices=DeviceSelection(
2914+
all=True
2915+
)
2916+
)
2917+
c = cephadm_module.apply([spec])
2918+
assert wait(cephadm_module, c) == ['Scheduled osd.foo update...']
2919+
2920+
cephadm_module.set_osd_spec('osd.foo', ['1'])

0 commit comments

Comments
 (0)