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