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: v16.2.7~67^2~62 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5d11e3da2daa1b199aaa77136e4e224a9797c127;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 (cherry picked from commit 3a15f1dc81dfd5f963e1bf36316fa5b289a898b0) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index fbf5a81d22ac..477719bbec67 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -7685,11 +7685,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 ) @@ -7699,13 +7699,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) @@ -7728,8 +7728,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 16e32833f636..43a0e4a35ed4 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -901,14 +901,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'])