replace: bool = False,
force: bool = False,
hostname: Optional[str] = None,
- fullname: Optional[str] = None,
):
# the ID of the OSD
self.osd_id = osd_id
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
raise orchestrator.OrchestratorError(
f"Could not set OSD <{osd.osd_id}> to 'down'")
+ # stop and remove daemon
+ assert osd.hostname is not None
+ CephadmServe(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
- CephadmServe(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
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):
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):
osd_obj.stop()