From: Sage Weil Date: Wed, 17 Feb 2021 21:20:22 +0000 (-0600) Subject: mgr/cephadm: remove daemon before osd destroy/purge X-Git-Tag: v15.2.17~21^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=81226dcd6c05b410f0a0fa41232ffe9e2266d75f;p=ceph.git mgr/cephadm: remove daemon before osd destroy/purge Otherwise it doesn't work! Drop the fullname property: it is always "osd.{self.osd_id}". Signed-off-by: Sage Weil (cherry picked from commit b5eab0ddfa0bb8ae7b1a6aec4ea2e4257a01a045) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 76a4d9b765e..a4c5a0f20cc 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2238,7 +2238,6 @@ To check that the host is reachable: replace=replace, force=force, hostname=daemon.hostname, - fullname=daemon.name(), process_started_at=datetime_now(), remove_util=self.to_remove_osds.rm_util)) except NotFoundError: diff --git a/src/pybind/mgr/cephadm/services/osd.py b/src/pybind/mgr/cephadm/services/osd.py index 22c94fac89c..f2ca301caaa 100644 --- a/src/pybind/mgr/cephadm/services/osd.py +++ b/src/pybind/mgr/cephadm/services/osd.py @@ -479,7 +479,6 @@ class OSD: replace: bool = False, force: bool = False, hostname: Optional[str] = None, - fullname: Optional[str] = None, ): # the ID of the OSD self.osd_id = osd_id @@ -511,8 +510,6 @@ class OSD: self.force = force # The name of the node self.hostname = hostname - # The full name of the osd - self.fullname = fullname # mgr obj to make mgr/mon calls self.rm_util: RemoveUtil = remove_util @@ -707,21 +704,24 @@ class OSDRemovalQueue(object): raise orchestrator.OrchestratorError( f"Could not set OSD <{osd.osd_id}> to 'down'") + # stop and remove daemon + assert osd.hostname is not None + self.mgr._remove_daemon(f'osd.{osd.osd_id}', osd.hostname) + logger.info(f"Successfully removed {osd} on {osd.hostname}") + if osd.replace: + # mark destroyed in osdmap if not osd.destroy(): raise orchestrator.OrchestratorError( - f"Could not destroy OSD <{osd.osd_id}>") + f"Could not destroy {osd}") + logger.info(f"Successfully destroyed old {osd} on {osd.hostname}; ready for replacement") else: + # purge from osdmap if not osd.purge(): - raise orchestrator.OrchestratorError(f"Could not purge OSD <{osd.osd_id}>") + raise orchestrator.OrchestratorError(f"Could not purge {osd}") + logger.info(f"Successfully purged {osd} on {osd.hostname}") - if not osd.exists: - continue - assert osd.fullname is not None - assert osd.hostname is not None - self.mgr._remove_daemon(osd.fullname, osd.hostname) - logger.info(f"Successfully removed OSD <{osd.osd_id}> on {osd.hostname}") - logger.debug(f"Removing {osd.osd_id} from the queue.") + logger.debug(f"Removing {osd} from the queue.") # self could change while this is processing (osds get added from the CLI) # The new set is: 'an intersection of all osds that are still not empty/removed (new_queue) and diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index ae17dd3201f..5000d08be31 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -634,7 +634,6 @@ class TestCephadm(object): replace=False, force=False, hostname='test', - fullname='osd.0', process_started_at=datetime_now(), remove_util=cephadm_module.to_remove_osds.rm_util )) diff --git a/src/pybind/mgr/cephadm/tests/test_osd_removal.py b/src/pybind/mgr/cephadm/tests/test_osd_removal.py index 0fb81796ab3..b2f27abbc4f 100644 --- a/src/pybind/mgr/cephadm/tests/test_osd_removal.py +++ b/src/pybind/mgr/cephadm/tests/test_osd_removal.py @@ -105,13 +105,25 @@ class TestOSD: assert osd_obj.started is True assert osd_obj.stopped is False - def test_start_draining(self, osd_obj): + def test_start_draining_purge(self, osd_obj): assert osd_obj.draining is False assert osd_obj.drain_started_at is None ret = osd_obj.start_draining() + osd_obj.rm_util.reweight_osd.assert_called_with(osd_obj, 0.0) + assert isinstance(osd_obj.drain_started_at, datetime) + assert osd_obj.draining is True + assert osd_obj.replace is False + assert ret is True + + def test_start_draining_replace(self, osd_obj): + assert osd_obj.draining is False + assert osd_obj.drain_started_at is None + osd_obj.replace = True + ret = osd_obj.start_draining() osd_obj.rm_util.set_osd_flag.assert_called_with([osd_obj], 'out') assert isinstance(osd_obj.drain_started_at, datetime) assert osd_obj.draining is True + assert osd_obj.replace is True assert ret is True def test_start_draining_stopped(self, osd_obj): @@ -121,13 +133,22 @@ class TestOSD: assert ret is False assert osd_obj.draining is False - def test_stop_draining(self, osd_obj): + def test_stop_draining_replace(self, osd_obj): + osd_obj.replace = True ret = osd_obj.stop_draining() osd_obj.rm_util.set_osd_flag.assert_called_with([osd_obj], 'in') assert isinstance(osd_obj.drain_stopped_at, datetime) assert osd_obj.draining is False assert ret is True + def test_stop_draining_purge(self, osd_obj): + osd_obj.original_weight = 1.0 + ret = osd_obj.stop_draining() + osd_obj.rm_util.reweight_osd.assert_called_with(osd_obj, 1.0) + assert isinstance(osd_obj.drain_stopped_at, datetime) + assert osd_obj.draining is False + assert ret is True + @mock.patch('cephadm.services.osd.OSD.stop_draining') def test_stop(self, stop_draining_mock, osd_obj): ret = osd_obj.stop()