@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')
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=[])
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=[])
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=[])
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')