"""
for osd_id in osd_ids:
try:
- self.to_remove_osds.rm(OSD(osd_id=int(osd_id),
- remove_util=self.to_remove_osds.rm_util))
+ self.to_remove_osds.rm_by_osd_id(int(osd_id))
except (NotFoundError, KeyError, ValueError):
return f'Unable to find OSD in the queue: {osd_id}'
return None
self.started = True
self.stopped = False
+ self.original_weight = self.rm_util.get_weight(self)
def start_draining(self) -> bool:
if self.stopped:
if self.replace:
self.rm_util.set_osd_flag([self], 'out')
else:
- self.original_weight = self.rm_util.get_weight(self)
self.rm_util.reweight_osd(self, 0.0)
self.drain_started_at = datetime.utcnow()
self.draining = True
out['force'] = self.force
out['zap'] = self.zap
out['hostname'] = self.hostname # type: ignore
+ out['original_weight'] = self.original_weight
for k in ['drain_started_at', 'drain_stopped_at', 'drain_done_at', 'process_started_at']:
if getattr(self, k):
self.osds.add(osd)
osd.start()
+ def rm_by_osd_id(self, osd_id: int) -> None:
+ osd: Optional["OSD"] = None
+ for o in self.osds:
+ if o.osd_id == osd_id:
+ osd = o
+ if not osd:
+ logger.debug(f"Could not find osd with id {osd_id} in queue.")
+ raise KeyError(f'No osd with id {osd_id} in removal queue')
+ self.rm(osd)
+
def rm(self, osd: "OSD") -> None:
if not osd.exists:
raise NotFoundError()
))
@mock.patch("cephadm.services.osd.OSD.exists", True)
@mock.patch("cephadm.services.osd.RemoveUtil.get_pg_count", lambda _, __: 0)
- def test_remove_osds(self, cephadm_module):
+ @mock.patch("cephadm.services.osd.RemoveUtil.get_weight")
+ @mock.patch("cephadm.services.osd.RemoveUtil.reweight_osd")
+ def test_remove_osds(self, _reweight_osd, _get_weight, cephadm_module):
+ osd_initial_weight = 2.1
+ _get_weight.return_value = osd_initial_weight
with with_host(cephadm_module, 'test'):
CephadmServe(cephadm_module)._refresh_host_daemons('test')
c = cephadm_module.list_daemons()
out = wait(cephadm_module, c)
assert out == ["Removed osd.0 from host 'test'"]
- cephadm_module.to_remove_osds.enqueue(OSD(osd_id=0,
- replace=False,
- force=False,
- hostname='test',
- process_started_at=datetime_now(),
- remove_util=cephadm_module.to_remove_osds.rm_util
- ))
+ osd_0 = OSD(osd_id=0,
+ replace=False,
+ force=False,
+ hostname='test',
+ process_started_at=datetime_now(),
+ remove_util=cephadm_module.to_remove_osds.rm_util
+ )
+
+ cephadm_module.to_remove_osds.enqueue(osd_0)
+ _get_weight.assert_called()
+
+ # test that OSD is properly reweighted on removal
+ cephadm_module.stop_remove_osds([0])
+ _reweight_osd.assert_called_with(mock.ANY, osd_initial_weight)
+
+ # add OSD back to queue and test normal removal queue processing
+ cephadm_module.to_remove_osds.enqueue(osd_0)
cephadm_module.to_remove_osds.process_removal_queue()
assert cephadm_module.to_remove_osds == OSDRemovalQueue(cephadm_module)