]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: Add command to stop host drain
authorShweta Bhosale <Shweta.Bhosale1@ibm.com>
Wed, 16 Apr 2025 12:34:35 +0000 (18:04 +0530)
committerAdam King <adking@redhat.com>
Sat, 21 Jun 2025 19:38:28 +0000 (15:38 -0400)
Fixes: https://tracker.ceph.com/issues/70950
Signed-off-by: Shweta Bhosale <Shweta.Bhosale1@ibm.com>
(cherry picked from commit 7f2f0288e891e840661a14e25bec74e97ed1523b)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index 6ee03a1c696a5139dfb9b0b0dc08909e695db99a..343fa2b3360ef731076f25dcfcd278b0aee5218b 100644 (file)
@@ -4204,6 +4204,18 @@ Then run the following:
 
         return "Scheduled to remove the following daemons from host '{}'\n{}".format(hostname, daemons_table)
 
+    @handle_orch_error
+    @host_exists()
+    def stop_drain_host(self, hostname: str) -> str:
+        if not self.inventory.has_label(hostname, '_no_schedule'):
+            raise OrchestratorValidationError(f'The host {hostname} is currently not draining.')
+        self.remove_host_label(hostname, '_no_schedule')
+        self.remove_host_label(hostname, SpecialHostLabels.DRAIN_CONF_KEYRING)
+        # stop osd removal for the host osds which are in to_remove_osds queue
+        osds = [d.daemon_id for d in self.cache.get_daemons_by_type('osd', hostname)]
+        self.stop_remove_osds(osds)
+        return f'Stopped host drain for {hostname}'
+
     def trigger_connect_dashboard_rgw(self) -> None:
         self.need_connect_dashboard_rgw = True
         self.event.set()
index 946d165c702cb03aefa85aaaa1db5e24da1f8a2f..b43c5e8d727a81d2a271efeb08a647677a145761 100644 (file)
@@ -2664,6 +2664,16 @@ Traceback (most recent call last):
             cephadm_module.drain_host('host1', force=True, zap_osd_devices=True)
             _rm_osds.assert_called_with([], zap=True)
 
+    @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
+    @mock.patch("cephadm.CephadmOrchestrator.stop_remove_osds")
+    @mock.patch("cephadm.inventory.HostCache.get_daemons_by_host", lambda *a, **kw: [])
+    def test_stop_host_drain(self, _stop_rm_osds, cephadm_module):
+        # pass force=true in these tests to bypass _admin label check
+        with with_host(cephadm_module, 'host1', refresh_hosts=False, rm_with_force=True):
+            cephadm_module.drain_host('host1')
+            cephadm_module.stop_drain_host('host1')
+            _stop_rm_osds.assert_called_with([])
+
     def test_process_ls_output(self, cephadm_module):
         sample_ls_output = """[
     {
index 90adece1856bf520b44427aefad2722c9f9a60f6..501487a80fffd4fe33a6f1b480b1c590f8eeac2d 100644 (file)
@@ -454,6 +454,14 @@ class Orchestrator(object):
         """
         raise NotImplementedError()
 
+    def stop_drain_host(self, hostname: str) -> OrchResult[str]:
+        """
+        stop draining daemons of a host
+
+        :param hostname: hostname
+        """
+        raise NotImplementedError()
+
     def update_host_addr(self, host: str, addr: str) -> OrchResult[str]:
         """
         Update a host's address
index 779eac9d56d8524e947fdad276567440d4842af2..8cf7aa42949ed1b5417cd3d211fd469b9f2be81f 100644 (file)
@@ -690,6 +690,13 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule,
         raise_if_exception(completion)
         return HandleCommandResult(stdout=completion.result_str())
 
+    @_cli_write_command('orch host drain stop')
+    def _stop_drain_host(self, hostname: str) -> HandleCommandResult:
+        """drain all daemons from a host"""
+        completion = self.stop_drain_host(hostname)
+        raise_if_exception(completion)
+        return HandleCommandResult(stdout=completion.result_str())
+
     @_cli_write_command('orch host set-addr')
     def _update_set_addr(self, hostname: str, addr: str) -> HandleCommandResult:
         """Update a host address"""