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). It also enables /healthcheck
endpoint for cinder-api on openstack releases >= ocata.

Closes-Bug: #1880610
Change-Id: I9d118f70fc1390be7b800ad20ae20e77818adac7
This commit is contained in:
Gabriel Cocenza 2023-02-16 18:18:29 -03:00
parent 70deb577f9
commit 51e32a4f7e
4 changed files with 51 additions and 4 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

@ -25,7 +25,7 @@ setenv = VIRTUAL_ENV={envdir}
commands = stestr run --slowest {posargs}
allowlist_externals =
charmcraft
rename.sh
{toxinidir}/rename.sh
passenv =
HOME
TERM

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