Merge "Add support for HAProxy L7 checks"

This commit is contained in:
Zuul 2023-03-29 15:14:54 +00:00 committed by Gerrit Code Review
commit c0f8e970d2
3 changed files with 50 additions and 3 deletions

View File

@ -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

View File

@ -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 #
##########

View File

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