From: Adam King Date: Mon, 20 Sep 2021 12:02:44 +0000 (-0400) Subject: cephadm: fix exiting maintenance when systemd target doesn't exist X-Git-Tag: v17.1.0~822^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3a15f1dc81dfd5f963e1bf36316fa5b289a898b0;p=ceph.git cephadm: fix exiting maintenance when systemd target doesn't exist If the systemd target doesn't exist we need to just bypass enabling it and return success or the host will just be stuck in maitnenance mode. Signed-off-by: Adam King --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 585c0f3c7802..3735d0968802 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -7711,11 +7711,11 @@ def command_exporter(ctx: CephadmContext) -> None: ################################## -def systemd_target_state(target_name: str, subsystem: str = 'ceph') -> bool: +def systemd_target_state(ctx: CephadmContext, target_name: str, subsystem: str = 'ceph') -> bool: # TODO: UNITTEST return os.path.exists( os.path.join( - UNIT_DIR, + ctx.unit_dir, f'{subsystem}.target.wants', target_name ) @@ -7725,13 +7725,13 @@ def systemd_target_state(target_name: str, subsystem: str = 'ceph') -> bool: @infer_fsid def command_maintenance(ctx: CephadmContext) -> str: if not ctx.fsid: - raise Error('must pass --fsid to specify cluster') + raise Error('failed - must pass --fsid to specify cluster') target = f'ceph-{ctx.fsid}.target' if ctx.maintenance_action.lower() == 'enter': logger.info('Requested to place host into maintenance') - if systemd_target_state(target): + if systemd_target_state(ctx, target): _out, _err, code = call(ctx, ['systemctl', 'disable', target], verbosity=CallVerbosity.DEBUG) @@ -7754,8 +7754,14 @@ def command_maintenance(ctx: CephadmContext) -> str: else: logger.info('Requested to exit maintenance state') + # if we've never deployed a daemon on this host there will be no systemd + # target to disable so attempting a disable will fail. We still need to + # return success here or host will be permanently stuck in maintenance mode + # as no daemons can be deployed so no systemd target will ever exist to disable. + if not os.path.exists(ctx.unit_dir + '/ceph.target'): + return 'skipped - systemd target not present on this host. Host removed from maintenance mode.' # exit maintenance request - if not systemd_target_state(target): + if not systemd_target_state(ctx, target): _out, _err, code = call(ctx, ['systemctl', 'enable', target], verbosity=CallVerbosity.DEBUG) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 03d872881d37..4dedeeefbeea 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -921,14 +921,16 @@ class TestMaintenance: wants.mkdir() target = wants / TestMaintenance.systemd_target target.touch() - cd.UNIT_DIR = str(base) + ctx = cd.CephadmContext() + ctx.unit_dir = str(base) - assert cd.systemd_target_state(target.name) + assert cd.systemd_target_state(ctx, target.name) def test_systemd_target_NOTOK(self, tmp_path): base = tmp_path - cd.UNIT_DIR = str(base) - assert not cd.systemd_target_state(TestMaintenance.systemd_target) + ctx = cd.CephadmContext() + ctx.unit_dir = str(base) + assert not cd.systemd_target_state(ctx, TestMaintenance.systemd_target) def test_parser_OK(self): args = cd._parse_args(['host-maintenance', 'enter'])