systemd/healthcheck: fix service names for requires/requisite

The services are prefixed by tripleo_ by default, it was missed during a
rebase.
It also adds a assertIn test for the service healthcheck, to verify that
Requisite is properly set.

Change-Id: Ia07edb9597c098a1e5df0e20982c91005b245b9c
This commit is contained in:
Emilien Macchi 2018-12-14 09:51:09 -05:00
parent 077a8d95c3
commit 62703333cf
2 changed files with 6 additions and 3 deletions

View File

@ -73,6 +73,7 @@ class TestUtilsSystemd(base.TestCase):
systemd.healthcheck_create(container, tempdir)
unit = open(sysd_unit_f, 'rt').read()
self.assertIn('Requisite=tripleo_my_app.service', unit)
self.assertIn('ExecStart=/usr/bin/podman exec my_app '
'/openstack/healthcheck', unit)
mock_chmod.assert_has_calls([mock.call(sysd_unit_f, 420)])
@ -95,7 +96,7 @@ class TestUtilsSystemd(base.TestCase):
systemd.healthcheck_timer_create(container, cconfig, tempdir)
unit = open(sysd_unit_f, 'rt').read()
self.assertIn('Requires=my_app_healthcheck.service', unit)
self.assertIn('Requires=tripleo_my_app_healthcheck.service', unit)
self.assertIn('OnCalendar=*-*-* *:*:00/15', unit)
mock_chmod.assert_has_calls([mock.call(sysd_unit_f, 420)])
mock_subprocess_call.assert_has_calls([

View File

@ -132,6 +132,7 @@ def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):
log.debug('Creating systemd unit file: %s' % sysd_unit_f)
s_config = {
'name': container,
'service': service,
'restart': 'restart',
}
with open(sysd_unit_f, 'w') as unit_file:
@ -139,7 +140,7 @@ def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):
unit_file.write("""[Unit]
Description=%(name)s healthcheck
After=paunch-container-shutdown.service
Requisite=%(name)s.service
Requisite=%(service)s.service
[Service]
Type=oneshot
ExecStart=/usr/bin/podman exec %(name)s /openstack/healthcheck
@ -176,13 +177,14 @@ def healthcheck_timer_create(container, cconfig, sysdir='/etc/systemd/system/',
interval = cconfig.get('check_interval', 30)
s_config = {
'name': container,
'service': service,
'interval': interval
}
with open(sysd_timer_f, 'w') as timer_file:
os.chmod(timer_file.name, 0o644)
timer_file.write("""[Unit]
Description=%(name)s container healthcheck
Requires=%(name)s_healthcheck.service
Requires=%(service)s_healthcheck.service
[Timer]
OnUnitActiveSec=90
OnCalendar=*-*-* *:*:00/%(interval)s