Make systemd.service_delete handle healthchecks

Deletion of healthcheck unit files was inadvertenly lost in a rebase in
I1949b7ba9e06110a2e91c9cb3359605cae3638e5. This change adds that support
for removing systemd service and timer files for healthchecks.

Change-Id: I0c91c5364f82d09c10a40ef3a59da2c6c7110101
This commit is contained in:
Jill Rouleau 2018-12-14 11:49:38 -07:00
parent 077a8d95c3
commit 401daee6bd
2 changed files with 32 additions and 13 deletions

View File

@ -54,10 +54,25 @@ class TestUtilsSystemd(base.TestCase):
mock_isfile.return_value = True
container = 'my_app'
service = 'tripleo_' + container
systemd.service_delete(container)
tempdir = tempfile.mkdtemp()
systemd.service_delete(container, tempdir)
mock_rm.assert_has_calls([
mock.call(tempdir + service + '.service'),
mock.call(tempdir + service + '_healthcheck.service'),
mock.call(tempdir + service + '_healthcheck.timer'),
])
mock_subprocess_call.assert_has_calls([
mock.call(['systemctl', 'stop', service]),
mock.call(['systemctl', 'disable', service]),
mock.call(['systemctl', 'stop', service + '.service']),
mock.call(['systemctl', 'disable', service + '.service']),
mock.call(['systemctl', 'daemon-reload']),
mock.call(['systemctl', 'stop', service + '_healthcheck.service']),
mock.call(['systemctl', 'disable', service +
'_healthcheck.service']),
mock.call(['systemctl', 'daemon-reload']),
mock.call(['systemctl', 'stop', service + '_healthcheck.timer']),
mock.call(['systemctl', 'disable', service +
'_healthcheck.timer']),
mock.call(['systemctl', 'daemon-reload']),
])

View File

@ -99,16 +99,20 @@ def service_delete(container, sysdir=constants.SYSTEMD_DIR, log=None):
# prefix is explained in the service_create().
service = 'tripleo_' + container
sysd_unit_f = sysdir + service + '.service'
if os.path.isfile(sysd_unit_f):
log.debug('Stopping and disabling systemd service for %s' % service)
subprocess.call(['systemctl', 'stop', service])
subprocess.call(['systemctl', 'disable', service])
log.debug('Removing systemd unit file %s' % sysd_unit_f)
os.remove(sysd_unit_f)
subprocess.call(['systemctl', 'daemon-reload'])
else:
log.warning('No systemd unit file was found for %s' % service)
sysd_unit_f = service + '.service'
sysd_health_f = service + '_healthcheck.service'
sysd_timer_f = service + '_healthcheck.timer'
for sysd_f in sysd_unit_f, sysd_health_f, sysd_timer_f:
if os.path.isfile(sysdir + sysd_f):
log.debug('Stopping and disabling systemd service for %s' %
service)
subprocess.call(['systemctl', 'stop', sysd_f])
subprocess.call(['systemctl', 'disable', sysd_f])
log.debug('Removing systemd unit file %s' % sysd_f)
os.remove(sysdir + sysd_f)
subprocess.call(['systemctl', 'daemon-reload'])
else:
log.warning('No systemd unit file was found for %s' % sysd_f)
def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):