diff --git a/hooks/cinder_contexts.py b/hooks/cinder_contexts.py index 29393905..b532aff5 100644 --- a/hooks/cinder_contexts.py +++ b/hooks/cinder_contexts.py @@ -36,6 +36,7 @@ from charmhelpers.contrib.openstack.utils import ( from charmhelpers.contrib.hahelpers.cluster import ( determine_apache_port, determine_api_port, + https ) CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf' @@ -100,16 +101,26 @@ class HAProxyContext(OSContextGenerator): specific to this charm. Also used to extend cinder.conf context with correct api_listening_port ''' + service = 'cinder_api' haproxy_port = config('api-listening-port') api_port = determine_api_port(config('api-listening-port'), singlenode_mode=True) apache_port = determine_apache_port(config('api-listening-port'), singlenode_mode=True) + backend_options = { + service: [{ + 'option': 'httpchk GET /healthcheck', + 'http-check': 'expect status 200', + }] + } + ctxt = { - 'service_ports': {'cinder_api': [haproxy_port, apache_port]}, + 'service_ports': {service: [haproxy_port, apache_port]}, 'osapi_volume_listen_port': api_port, 'port': api_port, + 'backend_options': backend_options, + 'https': https() } return ctxt diff --git a/templates/ocata/api-paste.ini b/templates/ocata/api-paste.ini index a761f53d..678ae490 100644 --- a/templates/ocata/api-paste.ini +++ b/templates/ocata/api-paste.ini @@ -5,6 +5,7 @@ [composite:osapi_volume] use = call:cinder.api:root_app_factory /: apiversions +/healthcheck: healthcheck /v1: openstack_volume_api_v1 /v2: openstack_volume_api_v2 /v3: openstack_volume_api_v3 @@ -64,6 +65,14 @@ pipeline = cors http_proxy_to_wsgi faultwrap osvolumeversionapp [app:osvolumeversionapp] paste.app_factory = cinder.api.versions:Versions.factory +[pipeline:healthcheck] +pipeline = request_id healthcheckapp + +[app:healthcheckapp] +paste.app_factory = oslo_middleware:Healthcheck.app_factory +backends = disable_by_file +disable_by_file_path = /etc/cinder/healthcheck_disable + ########## # Shared # ########## diff --git a/tox.ini b/tox.ini index ae4d124c..2cb6ca16 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ setenv = VIRTUAL_ENV={envdir} commands = stestr run --slowest {posargs} allowlist_externals = charmcraft - rename.sh + {toxinidir}/rename.sh passenv = HOME TERM diff --git a/unit_tests/test_cinder_contexts.py b/unit_tests/test_cinder_contexts.py index fe6e7f69..de72314b 100644 --- a/unit_tests/test_cinder_contexts.py +++ b/unit_tests/test_cinder_contexts.py @@ -26,8 +26,6 @@ TO_PATCH = [ 'config', 'relation_ids', 'service_name', - 'determine_apache_port', - 'determine_api_port', 'os_release', 'related_units', 'relation_get' @@ -545,3 +543,32 @@ class TestCinderContext(CharmTestCase): contexts.VolumeUsageAuditContext.DEFAULT_CRONTAB_PATH, "wt+") self.assertEqual(self.config.return_value, ctxt["volume_usage_audit_period"]) + + @patch('charmhelpers.contrib.hahelpers.cluster.https') + @patch('cinder_contexts.https') + def test_haproxy_context(self, mock_https, mock_ch_https): + config = {'api-listening-port': 8776} + self.config.side_effect = lambda x: config[x] + for https_mode in [False, True]: + mock_https.return_value = https_mode + mock_ch_https.return_value = https_mode + api_port = 8766 + if https_mode: + api_port = 8756 + + haproxy_context = contexts.HAProxyContext() + expected = { + "service_ports": {"cinder_api": [8776, 8766]}, + "osapi_volume_listen_port": api_port, + 'port': api_port, + "backend_options": { + "cinder_api": [ + { + 'option': 'httpchk GET /healthcheck', + 'http-check': 'expect status 200', + } + ] + }, + "https": https_mode, + } + self.assertEqual(expected, haproxy_context())