From ca52b4935111c7bb0439be111f5b6936f3993b3f Mon Sep 17 00:00:00 2001 From: jianglong01 Date: Tue, 8 Jun 2021 14:00:48 +0800 Subject: [PATCH 1/2] mgr/cephadm: When create osd which include db, _create_daemon will be executed twice. So we should filter the db type Signed-off-by: jianglong01 --- src/pybind/mgr/cephadm/services/osd.py | 2 ++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 38 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/cephadm/services/osd.py b/src/pybind/mgr/cephadm/services/osd.py index 2b49a581bf5..3c30a413980 100644 --- a/src/pybind/mgr/cephadm/services/osd.py +++ b/src/pybind/mgr/cephadm/services/osd.py @@ -112,6 +112,8 @@ class OSDService(CephService): created = [] for osd_id, osds in osds_elems.items(): for osd in osds: + if osd['type'] == 'db': + continue if osd['tags']['ceph.cluster_fsid'] != fsid: logger.debug('mismatched fsid, skipping %s' % osd) continue diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 84c4cb5f6a6..72e365b345f 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -1221,7 +1221,7 @@ Traceback (most recent call last): ] @mock.patch("cephadm.serve.CephadmServe._run_cephadm") - def test_osd_activate(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + def test_osd_activate_datadevice(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.return_value = ('{}', '', 0) with with_host(cephadm_module, 'test', refresh_hosts=False): cephadm_module.mock_store_set('_ceph_get', 'osd_map', { @@ -1239,7 +1239,41 @@ Traceback (most recent call last): 'tags': { 'ceph.cluster_fsid': cephadm_module._cluster_fsid, 'ceph.osd_fsid': 'uuid' - } + }, + 'type': 'data' + }] + } + _run_cephadm.return_value = (json.dumps(ceph_volume_lvm_list), '', 0) + assert cephadm_module._osd_activate( + ['test']).stdout == "Created osd(s) 1 on host 'test'" + + @mock.patch("cephadm.serve.CephadmServe._run_cephadm") + def test_osd_activate_datadevice_dbdevice(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + _run_cephadm.return_value = ('{}', '', 0) + with with_host(cephadm_module, 'test', refresh_hosts=False): + cephadm_module.mock_store_set('_ceph_get', 'osd_map', { + 'osds': [ + { + 'osd': 1, + 'up_from': 0, + 'uuid': 'uuid' + } + ] + }) + + ceph_volume_lvm_list = { + '1': [{ + 'tags': { + 'ceph.cluster_fsid': cephadm_module._cluster_fsid, + 'ceph.osd_fsid': 'uuid' + }, + 'type': 'data' + }, { + 'tags': { + 'ceph.cluster_fsid': cephadm_module._cluster_fsid, + 'ceph.osd_fsid': 'uuid' + }, + 'type': 'db' }] } _run_cephadm.return_value = (json.dumps(ceph_volume_lvm_list), '', 0) From 73dd266dc837b9a11d27ee17cbe75f8b6c36c799 Mon Sep 17 00:00:00 2001 From: jianglong01 Date: Fri, 11 Jun 2021 10:56:30 +0800 Subject: [PATCH 2/2] mgr/cephadm: When test osd active, it need to add "mock call" to make sure execute correctly Signed-off-by: jianglong01 --- src/pybind/mgr/cephadm/tests/test_cephadm.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 72e365b345f..3a876d5ff84 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -1244,8 +1244,17 @@ Traceback (most recent call last): }] } _run_cephadm.return_value = (json.dumps(ceph_volume_lvm_list), '', 0) + _run_cephadm.reset_mock() assert cephadm_module._osd_activate( ['test']).stdout == "Created osd(s) 1 on host 'test'" + assert _run_cephadm.mock_calls == [ + mock.call('test', 'osd', 'ceph-volume', + ['--', 'lvm', 'list', '--format', 'json'], no_fsid=False, image=''), + mock.call('test', 'osd.1', 'deploy', + ['--name', 'osd.1', '--meta-json', mock.ANY, + '--config-json', '-', '--osd-fsid', 'uuid'], + stdin=mock.ANY, image=''), + ] @mock.patch("cephadm.serve.CephadmServe._run_cephadm") def test_osd_activate_datadevice_dbdevice(self, _run_cephadm, cephadm_module: CephadmOrchestrator): @@ -1277,5 +1286,14 @@ Traceback (most recent call last): }] } _run_cephadm.return_value = (json.dumps(ceph_volume_lvm_list), '', 0) + _run_cephadm.reset_mock() assert cephadm_module._osd_activate( ['test']).stdout == "Created osd(s) 1 on host 'test'" + assert _run_cephadm.mock_calls == [ + mock.call('test', 'osd', 'ceph-volume', + ['--', 'lvm', 'list', '--format', 'json'], no_fsid=False, image=''), + mock.call('test', 'osd.1', 'deploy', + ['--name', 'osd.1', '--meta-json', mock.ANY, + '--config-json', '-', '--osd-fsid', 'uuid'], + stdin=mock.ANY, image=''), + ]