From: John Mulligan Date: Wed, 27 Mar 2024 22:45:15 +0000 (-0400) Subject: cephadm: fix host-maintenance command always exiting with a failure X-Git-Tag: v19.1.0~39^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=42f0031fee27a0d43f7e549484dc15cc8f1ab529;p=ceph.git cephadm: fix host-maintenance command always exiting with a failure The host-maintenance command would always fail because command_maintenance always returns a string. This string is passed to sys.exit and thus always gets printed and causes a non-zero exit code. Fix the command line behavior by renaming the original function and adding a new command_maintenance that prints the string and returns an int like other command_* functions do. Fixes: https://tracker.ceph.com/issues/65122 Signed-off-by: John Mulligan (cherry picked from commit 0a137b140e47d02b03d133adb55e62aa0de7b984) --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index eccb330fda907..396880b5d4a14 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4634,7 +4634,17 @@ def target_exists(ctx: CephadmContext) -> bool: @infer_fsid -def command_maintenance(ctx: CephadmContext) -> str: +def command_maintenance(ctx: CephadmContext) -> int: + msg = change_maintenance_mode(ctx) + # mgr module reads the string emitted here from stderr + sys.stderr.write(msg + '\n') + sys.stderr.flush() + if msg.startswith('fail'): + return 1 + return 0 + + +def change_maintenance_mode(ctx: CephadmContext) -> str: if not ctx.fsid: raise Error('failed - must pass --fsid to specify cluster') diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 9c6caf0092b74..ac956caa70bad 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1164,7 +1164,7 @@ class TestMaintenance: ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx( ['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid]) ctx.container_engine = mock_podman() - retval = _cephadm.command_maintenance(ctx) + retval = _cephadm.change_maintenance_mode(ctx) assert retval.startswith('failed') @mock.patch('os.listdir', return_value=[]) @@ -1177,7 +1177,7 @@ class TestMaintenance: ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx( ['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid]) ctx.container_engine = mock_podman() - retval = _cephadm.command_maintenance(ctx) + retval = _cephadm.change_maintenance_mode(ctx) assert retval.startswith('failed') @mock.patch('os.listdir', return_value=[]) @@ -1192,7 +1192,7 @@ class TestMaintenance: ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx( ['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid]) ctx.container_engine = mock_podman() - retval = _cephadm.command_maintenance(ctx) + retval = _cephadm.change_maintenance_mode(ctx) assert retval.startswith('failed') @mock.patch('os.listdir', return_value=[]) @@ -1207,7 +1207,7 @@ class TestMaintenance: ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx( ['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid]) ctx.container_engine = mock_podman() - retval = _cephadm.command_maintenance(ctx) + retval = _cephadm.change_maintenance_mode(ctx) assert retval.startswith('failed')