]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Added cephadm check-online command for offline host watcher
authorShweta Bhosale <Shweta.Bhosale1@ibm.com>
Fri, 8 May 2026 11:24:43 +0000 (16:54 +0530)
committerShweta Bhosale <Shweta.Bhosale1@ibm.com>
Thu, 11 Jun 2026 05:10:34 +0000 (10:40 +0530)
Added a `cephadm check-online` subcommand that returns 0,
and use it from the mgr cephadm offline host watcher via
`CephadmServe._run_cephadm` instead of SSHing `true` directly.

Fixes: https://tracker.ceph.com/issues/74045
Signed-off-by: Shweta Bhosale <Shweta.Bhosale1@ibm.com>
doc/man/8/cephadm.rst
src/cephadm/cephadm.py
src/pybind/mgr/cephadm/offline_watcher.py
src/pybind/mgr/cephadm/tests/test_ssh.py

index 44d3beafb208db2e88d06013a5132a3451df7279..c290bf7712d8bc53f35653bb96ad3d4ec15fdbf2 100644 (file)
@@ -13,7 +13,7 @@ Synopsis
 |             [--log-dir LOG_DIR] [--logrotate-dir LOGROTATE_DIR]
 |             [--unit-dir UNIT_DIR] [--verbose] [--timeout TIMEOUT]
 |             [--retry RETRY] [--no-container-init]
-|             {version,pull,inspect-image,ls,list-networks,list-rdma,adopt,rm-daemon,rm-cluster,run,shell,enter,ceph-volume,unit,logs,bootstrap,deploy,check-host,prepare-host,prepare-host-sudo-hardening,setup-ssh-user,add-repo,rm-repo,install,list-images,update-osd-service}
+|             {version,pull,inspect-image,ls,list-networks,list-rdma,adopt,rm-daemon,rm-cluster,run,shell,enter,ceph-volume,unit,logs,bootstrap,deploy,check-host,check-online,prepare-host,prepare-host-sudo-hardening,setup-ssh-user,add-repo,rm-repo,install,list-images,update-osd-service}
 |               ...
 
 
@@ -90,6 +90,8 @@ Synopsis
 
 | **cephadm** **check-host** [-h] [--expect-hostname EXPECT_HOSTNAME]
 
+| **cephadm** **check-online**
+
 | **cephadm** **prepare-host**
 
 | **cephadm** **add-repo** [-h] [--release RELEASE] [--version VERSION]
@@ -289,6 +291,15 @@ Arguments:
 * [--expect-hostname EXPECT_HOSTNAME] Check that hostname matches an expected value
 
 
+check-online
+------------
+
+check that the host is online by running ``true`` locally.
+
+This command is primarily intended for cephadm internals (for example, the
+offline host watcher), rather than direct operator workflows.
+
+
 deploy
 ------
 
index ba246ab7c409b1070dad877c7ca34f879897a910..2365054f42dd4a9d2ee82f7a8a116ee9a57ed730 100755 (executable)
@@ -4454,6 +4454,10 @@ def command_check_host(ctx: CephadmContext) -> None:
 ##################################
 
 
+def command_check_online(ctx: CephadmContext) -> int:
+    return 0
+
+
 def command_prepare_host(ctx: CephadmContext) -> None:
     logger.info('Verifying podman|docker is present...')
     pkg = None
@@ -5597,6 +5601,10 @@ def _get_parser():
         '--expect-hostname',
         help='Check that hostname matches an expected value')
 
+    parser_check_online = subparsers.add_parser(
+        'check-online', help='return true to indicate host is running')
+    parser_check_online.set_defaults(func=command_check_online)
+
     parser_prepare_host = subparsers.add_parser(
         'prepare-host', help='prepare a host for cephadm use')
     parser_prepare_host.set_defaults(func=command_prepare_host)
@@ -5832,6 +5840,7 @@ def main() -> None:
         if ctx.func not in \
                 [
                     command_check_host,
+                    command_check_online,
                     command_prepare_host,
                     command_add_repo,
                     command_rm_repo,
index 4aa07e2f584ae8590ab636bcc3f8bd5d339806b1..c8bfa4cb3d1f4466ff7ac7269b07915b7aaa5b10 100644 (file)
@@ -4,7 +4,8 @@ from typing import List, Optional, TYPE_CHECKING
 import multiprocessing as mp
 import threading
 
-from . import ssh
+from .serve import CephadmServe
+from .utils import cephadmNoImage
 
 if TYPE_CHECKING:
     from cephadm.module import CephadmOrchestrator
@@ -40,8 +41,10 @@ class OfflineHostWatcher(threading.Thread):
     def check_host(self, host: str) -> None:
         if host not in self.mgr.offline_hosts:
             try:
-                rcmd = ssh.RemoteCommand(ssh.Executables.TRUE)
-                self.mgr.ssh.check_execute_command(host, rcmd, log_command=self.mgr.log_refresh_metadata)
+                with self.mgr.async_timeout_handler(host, 'cephadm check-online'):
+                    self.mgr.wait_async(CephadmServe(self.mgr)._run_cephadm(
+                        host, cephadmNoImage, 'check-online', [],
+                        no_fsid=True, log_output=self.mgr.log_refresh_metadata))
             except Exception:
                 logger.debug(f'OfflineHostDetector: detected {host} to be offline')
                 # kick serve loop in case corrective action must be taken for offline host
index 937e31567602ef46c6598f74c5f679dbbb072e46..ebb80b18b94da3d483853c7b1b1ca2007de20951 100644 (file)
@@ -21,6 +21,7 @@ from ceph.deployment.hostspec import HostSpec
 from cephadm import CephadmOrchestrator
 from cephadm.serve import CephadmServe
 from cephadm.tests.fixtures import with_host, wait, async_side_effect
+from cephadm.utils import cephadmNoImage
 from orchestrator import OrchestratorError
 
 
@@ -111,3 +112,17 @@ def test_remote_command():
         '-rf',
         '/tmp/blat',
     ]
+
+
+@mock.patch("cephadm.offline_watcher.CephadmServe._run_cephadm")
+def test_offline_watcher_uses_cephadm_check_online(run_cephadm, cephadm_module):
+    run_cephadm.side_effect = async_side_effect(([''], [''], 0))
+
+    with with_host(cephadm_module, 'test'):
+        run_cephadm.reset_mock()
+        cephadm_module.offline_watcher.check_host('test')
+
+    run_cephadm.assert_called_once_with(
+        'test', cephadmNoImage, 'check-online', [],
+        no_fsid=True, log_output=cephadm_module.log_refresh_metadata
+    )