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

This commit is contained in:
Zuul 2019-04-11 10:47:32 +00:00 committed by Gerrit Code Review
commit 61c448d7bc
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

@ -116,6 +116,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

@ -136,7 +136,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
@ -147,6 +148,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__)
@ -159,6 +163,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)
@ -168,7 +173,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