]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: fix exiting maintenance when systemd target doesn't exist
authorAdam King <adking@redhat.com>
Mon, 20 Sep 2021 12:02:44 +0000 (08:02 -0400)
committerAdam King <adking@redhat.com>
Wed, 22 Sep 2021 21:50:44 +0000 (17:50 -0400)
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 <adking@redhat.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 585c0f3c7802cdef84a31f97a53af6626e66b41d..3735d096880243d6f0c6b9340b58fa52dc687698 100755 (executable)
@@ -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)
index 03d872881d376e5f69317539d5a7fb4369164c28..4dedeeefbeea999e4343c3c2b78455e2d6d4dc63 100644 (file)
@@ -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'])