Allow to use t-h-t "healthcheck" config entry for podman

Until now, paunch configures the "healthcheck" systemd unit
with a hard-coded path, while we can set it in tripleo-heat-templates.

Change-Id: Ic15bfb974e53703bfaf324be7d1b9b0352e2e644
This commit is contained in:
Cédric Jeanneret 2019-04-10 15:09:18 +02:00
parent 6e99f2e233
commit a7ea1aa1f0
4 changed files with 26 additions and 3 deletions

View File

@ -109,8 +109,9 @@ class BaseBuilder(object):
cconfig=cconfig,
log=self.log)
if 'healthcheck' in cconfig:
check = cconfig.get('healthcheck')['test']
systemd.healthcheck_create(container=container_name,
log=self.log)
log=self.log, test=check)
systemd.healthcheck_timer_create(
container=container_name,
cconfig=cconfig,

View File

@ -115,6 +115,20 @@ class TestUtilsSystemd(base.TestCase):
'/openstack/healthcheck', unit)
mock_chmod.assert_has_calls([mock.call(sysd_unit_f, 420)])
@mock.patch('os.chmod')
def test_healthcheck_create_command(self, mock_chmod):
container = 'my_app'
service = 'tripleo_' + container
tempdir = tempfile.mkdtemp()
healthcheck = service + '_healthcheck.service'
sysd_unit_f = tempdir + healthcheck
check = '/foo/bar baz'
systemd.healthcheck_create(container, tempdir, test=check)
unit = open(sysd_unit_f, 'rt').read()
self.assertIn('ExecStart=/usr/bin/podman exec my_app '
'/foo/bar baz', unit)
@mock.patch('subprocess.check_call', autospec=True)
@mock.patch('os.chmod')
def test_healthcheck_timer_create(self, mock_chmod,

View File

@ -134,7 +134,8 @@ def service_delete(container, sysdir=constants.SYSTEMD_DIR, log=None):
log.info('No systemd unit file was found for %s' % sysd_f)
def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):
def healthcheck_create(container, sysdir='/etc/systemd/system/',
log=None, test='/openstack/healthcheck'):
"""Create a healthcheck for a service in systemd
:param container: container name
@ -145,6 +146,9 @@ def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):
:param log: optional pre-defined logger for messages
:type log: logging.RootLogger
:param test: optional test full command
:type test: String
"""
log = log or common.configure_logging(__name__)
@ -157,6 +161,7 @@ def healthcheck_create(container, sysdir='/etc/systemd/system/', log=None):
'name': container,
'service': service,
'restart': 'restart',
'test': test,
}
with open(sysd_unit_f, 'w') as unit_file:
os.chmod(unit_file.name, 0o644)
@ -166,7 +171,7 @@ After=paunch-container-shutdown.service
Requisite=%(service)s.service
[Service]
Type=oneshot
ExecStart=/usr/bin/podman exec %(name)s /openstack/healthcheck
ExecStart=/usr/bin/podman exec %(name)s %(test)s
[Install]
WantedBy=multi-user.target
""" % s_config)

View File

@ -0,0 +1,3 @@
---
features:
- Allows to configure the healthcheck as set in tripleo-heat-templates