From 96a2bb3af9a9b3b5756e5d618371187fa6e09b8f Mon Sep 17 00:00:00 2001 From: Gabriel Cocenza Date: Mon, 24 Oct 2022 12:04:05 -0300 Subject: [PATCH] Add support for HAProxy L7 checks This change add several configuration options to enable HTTP checks to the HAProxy configuration, instead of the default TCP connection checks (which continue to be the default) Closes-Bug: #1880610 Change-Id: I81d7fd67029dd5025f95b41d788b03ce4b6038bb --- hooks/glance_contexts.py | 13 ++++++++++++- unit_tests/test_glance_contexts.py | 27 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/hooks/glance_contexts.py b/hooks/glance_contexts.py index 5a857e2d..72c9f47f 100644 --- a/hooks/glance_contexts.py +++ b/hooks/glance_contexts.py @@ -38,6 +38,7 @@ from charmhelpers.contrib.openstack.context import ( from charmhelpers.contrib.hahelpers.cluster import ( determine_apache_port, determine_api_port, + https, ) from charmhelpers.contrib.openstack.utils import ( @@ -402,14 +403,24 @@ class HAProxyContext(OSContextGenerator): specific to this charm. Also used to extend glance-api.conf context with correct bind_port ''' + service = 'glance_api' haproxy_port = 9292 apache_port = determine_apache_port(9292, singlenode_mode=True) api_port = determine_api_port(9292, singlenode_mode=True) + backend_options = { + service: [{ + 'option': 'httpchk GET /healthcheck', + 'http-check': 'expect status 200', + }] + } + ctxt = { - 'service_ports': {'glance_api': [haproxy_port, apache_port]}, + 'service_ports': {service: [haproxy_port, apache_port]}, 'bind_port': api_port, } + ctxt['backend_options'] = backend_options + ctxt['https'] = https() return ctxt diff --git a/unit_tests/test_glance_contexts.py b/unit_tests/test_glance_contexts.py index 983577ce..2f83c14b 100644 --- a/unit_tests/test_glance_contexts.py +++ b/unit_tests/test_glance_contexts.py @@ -24,8 +24,6 @@ TO_PATCH = [ 'relation_ids', 'is_relation_made', 'service_name', - 'determine_apache_port', - 'determine_api_port', 'os_release', 'juju_log', ] @@ -604,3 +602,28 @@ class TestGlanceContexts(CharmTestCase): ctxt = contexts.GlanceIPv6Context() self.assertEqual(ctxt(), {'bind_host': '0.0.0.0', 'registry_host': '0.0.0.0'}) + + @patch('charmhelpers.contrib.hahelpers.cluster.https') + @patch('glance_contexts.https') + def test_ctxt(self, mock_https, mock_ch_https): + bind_port = 9282 + for https_mode in [False, True]: + mock_https.return_value = https_mode + mock_ch_https.return_value = https_mode + if https_mode: + bind_port = 9272 + haproxy_context = contexts.HAProxyContext() + expected = { + "service_ports": {"glance_api": [9292, 9282]}, + "bind_port": bind_port, + "backend_options": { + "glance_api": [ + { + 'option': 'httpchk GET /healthcheck', + 'http-check': 'expect status 200', + } + ] + }, + "https": https_mode, + } + self.assertEqual(expected, haproxy_context())