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())