Skip to content

Commit 0a137b1

Browse files
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 <[email protected]>
1 parent cde5bee commit 0a137b1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/cephadm/cephadm.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4705,7 +4705,17 @@ def target_exists(ctx: CephadmContext) -> bool:
47054705

47064706

47074707
@infer_fsid
4708-
def command_maintenance(ctx: CephadmContext) -> str:
4708+
def command_maintenance(ctx: CephadmContext) -> int:
4709+
msg = change_maintenance_mode(ctx)
4710+
# mgr module reads the string emitted here from stderr
4711+
sys.stderr.write(msg + '\n')
4712+
sys.stderr.flush()
4713+
if msg.startswith('fail'):
4714+
return 1
4715+
return 0
4716+
4717+
4718+
def change_maintenance_mode(ctx: CephadmContext) -> str:
47094719
if not ctx.fsid:
47104720
raise Error('failed - must pass --fsid to specify cluster')
47114721

src/cephadm/tests/test_cephadm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ def test_enter_failure_1(self, _target_state, _logger, _call, _listdir):
12391239
ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(
12401240
['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid])
12411241
ctx.container_engine = mock_podman()
1242-
retval = _cephadm.command_maintenance(ctx)
1242+
retval = _cephadm.change_maintenance_mode(ctx)
12431243
assert retval.startswith('failed')
12441244

12451245
@mock.patch('os.listdir', return_value=[])
@@ -1252,7 +1252,7 @@ def test_enter_failure_2(self, _target_state, _logger, _call, _listdir):
12521252
ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(
12531253
['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid])
12541254
ctx.container_engine = mock_podman()
1255-
retval = _cephadm.command_maintenance(ctx)
1255+
retval = _cephadm.change_maintenance_mode(ctx)
12561256
assert retval.startswith('failed')
12571257

12581258
@mock.patch('os.listdir', return_value=[])
@@ -1267,7 +1267,7 @@ def test_exit_failure_1(self, _target_exists, _target_state, _logger, _call, _li
12671267
ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(
12681268
['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid])
12691269
ctx.container_engine = mock_podman()
1270-
retval = _cephadm.command_maintenance(ctx)
1270+
retval = _cephadm.change_maintenance_mode(ctx)
12711271
assert retval.startswith('failed')
12721272

12731273
@mock.patch('os.listdir', return_value=[])
@@ -1282,7 +1282,7 @@ def test_exit_failure_2(self, _target_exists, _target_state, _logger, _call, _li
12821282
ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(
12831283
['host-maintenance', 'exit', '--fsid', TestMaintenance.fsid])
12841284
ctx.container_engine = mock_podman()
1285-
retval = _cephadm.command_maintenance(ctx)
1285+
retval = _cephadm.change_maintenance_mode(ctx)
12861286
assert retval.startswith('failed')
12871287

12881288

0 commit comments

Comments
 (0)