From: Shweta Bhosale Date: Fri, 8 May 2026 11:24:43 +0000 (+0530) Subject: cephadm: Added cephadm check-online command for offline host watcher X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07edf265cb61fa1bdb492be405f7847620b6453f;p=ceph.git cephadm: Added cephadm check-online command for offline host watcher 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 --- diff --git a/doc/man/8/cephadm.rst b/doc/man/8/cephadm.rst index 44d3beafb20..c290bf7712d 100644 --- a/doc/man/8/cephadm.rst +++ b/doc/man/8/cephadm.rst @@ -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 ------ diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index ba246ab7c40..2365054f42d 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -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, diff --git a/src/pybind/mgr/cephadm/offline_watcher.py b/src/pybind/mgr/cephadm/offline_watcher.py index 4aa07e2f584..c8bfa4cb3d1 100644 --- a/src/pybind/mgr/cephadm/offline_watcher.py +++ b/src/pybind/mgr/cephadm/offline_watcher.py @@ -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 diff --git a/src/pybind/mgr/cephadm/tests/test_ssh.py b/src/pybind/mgr/cephadm/tests/test_ssh.py index 937e3156760..ebb80b18b94 100644 --- a/src/pybind/mgr/cephadm/tests/test_ssh.py +++ b/src/pybind/mgr/cephadm/tests/test_ssh.py @@ -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 + )