From 2cfb681003029621d7564a52b011469b4f7d8edb Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 20 Dec 2021 16:08:07 +0100 Subject: [PATCH] mgr/cephadm: Fix count for OSDs with OSD specs osd counting is special Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 9 ++++++++- src/pybind/mgr/cephadm/tests/fixtures.py | 2 +- src/pybind/mgr/cephadm/tests/test_cephadm.py | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 080cc0459f1..beafce7e759 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1732,9 +1732,16 @@ Then run the following: continue if service_name is not None and service_name != nm: continue + + if spec.service_type != 'osd': + size = spec.placement.get_target_count(self.cache.get_schedulable_hosts()) + else: + # osd counting is special + size = 0 + sm[nm] = orchestrator.ServiceDescription( spec=spec, - size=spec.placement.get_target_count(self.cache.get_schedulable_hosts()), + size=size, running=0, events=self.events.get_for_service(spec.service_name()), created=self.spec_store.spec_created[nm], diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 75ce9900661..33c6d19a4bf 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -176,7 +176,7 @@ def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth=No dds = wait(cephadm_module, cephadm_module.list_daemons()) own_dds = [dd for dd in dds if dd.service_name() == spec.service_name()] - if host: + if host and spec.service_type != 'osd': assert own_dds yield [dd.name() for dd in own_dds] diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 5b0ed3547bb..093b7d4e7cc 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -1665,6 +1665,15 @@ Traceback (most recent call last): with with_osd_daemon(cephadm_module, _run_cephadm, 'test', 1, ceph_volume_lvm_list=_ceph_volume_list): pass + @mock.patch("cephadm.serve.CephadmServe._run_cephadm") + def test_osd_count(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) + dg = DriveGroupSpec(service_id='', data_devices=DeviceSelection(all=True)) + with with_host(cephadm_module, 'test', refresh_hosts=False): + with with_service(cephadm_module, dg, host='test'): + with with_osd_daemon(cephadm_module, _run_cephadm, 'test', 1): + assert wait(cephadm_module, cephadm_module.describe_service())[0].size == 1 + @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) def test_host_rm_last_admin(self, cephadm_module: CephadmOrchestrator): with pytest.raises(OrchestratorError):