]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: fix host-maintenance command always exiting with a failure 58755/head
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 27 Mar 2024 22:45:15 +0000 (18:45 -0400)
committerAdam King <adking@redhat.com>
Tue, 23 Jul 2024 16:13:31 +0000 (12:13 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit 0a137b140e47d02b03d133adb55e62aa0de7b984)

Conflicts:
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 2addee773e345a7781baafcd8675966cf7e511ab..8095568ad33683c2149116de874467fe4faf551b 100755 (executable)
@@ -9017,7 +9017,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')
 
index 755b7b0a51e7e9fcd21f26dcfa67e1ddeb159dc6..497bf32757dfb5a0db03f37c918a284c48924b49 100644 (file)
@@ -1139,7 +1139,7 @@ class TestMaintenance:
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
             ['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid])
         ctx.container_engine = mock_podman()
-        retval = cd.command_maintenance(ctx)
+        retval = cd.change_maintenance_mode(ctx)
         assert retval.startswith('failed')
 
     @mock.patch('os.listdir', return_value=[])
@@ -1151,7 +1151,7 @@ class TestMaintenance:
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
             ['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid])
         ctx.container_engine = mock_podman()
-        retval = cd.command_maintenance(ctx)
+        retval = cd.change_maintenance_mode(ctx)
         assert retval.startswith('failed')
 
     @mock.patch('os.listdir', return_value=[])
@@ -1165,7 +1165,7 @@ class TestMaintenance:
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
             ['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid])
         ctx.container_engine = mock_podman()
-        retval = cd.command_maintenance(ctx)
+        retval = cd.change_maintenance_mode(ctx)
         assert retval.startswith('failed')
 
     @mock.patch('os.listdir', return_value=[])
@@ -1179,7 +1179,7 @@ class TestMaintenance:
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
             ['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid])
         ctx.container_engine = mock_podman()
-        retval = cd.command_maintenance(ctx)
+        retval = cd.change_maintenance_mode(ctx)
         assert retval.startswith('failed')