From 696ef12f4e67582b8345f7ae97b6df550436662d Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Thu, 30 Apr 2020 13:42:13 +0200 Subject: [PATCH] Add a /healthcheck middleware By default, cinder-api isn't providing a /healthcheck URL, which is super useful for setting-up monitoring and HAProxy. This patch adds it by default. Change-Id: I03a93bf14a5ba159b68bfba15a7f4f26c8200e36 --- cinder/tests/functional/test_middleware.py | 33 +++++++++++++++++++ etc/cinder/api-paste.ini | 6 ++++ .../notes/healthcheck-449ed4292e6bfa22.yaml | 7 ++++ 3 files changed, 46 insertions(+) create mode 100644 cinder/tests/functional/test_middleware.py create mode 100644 releasenotes/notes/healthcheck-449ed4292e6bfa22.yaml diff --git a/cinder/tests/functional/test_middleware.py b/cinder/tests/functional/test_middleware.py new file mode 100644 index 00000000000..7e7d2cb7c9a --- /dev/null +++ b/cinder/tests/functional/test_middleware.py @@ -0,0 +1,33 @@ +# Copyright 2020 Thomas Goirand +# Copyright 2020 Infomaniak Networks. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_serialization import jsonutils +import requests + +from cinder.tests.functional import functional_helpers + + +class TestHealthCheckMiddleware(functional_helpers._FunctionalTestBase): + + def test_healthcheck(self): + # We verify that we return a HTTP200 when calling api_get + url = 'http://%s:%s/healthcheck' % (self.osapi.host, self.osapi.port) + response = requests.request( + 'GET', + url, + headers={'Accept': 'application/json'}) + output = jsonutils.loads(response.content) + self.assertEqual(['OK'], output['reasons']) diff --git a/etc/cinder/api-paste.ini b/etc/cinder/api-paste.ini index cb783b8c1ed..93764008002 100644 --- a/etc/cinder/api-paste.ini +++ b/etc/cinder/api-paste.ini @@ -5,6 +5,7 @@ [composite:osapi_volume] use = call:cinder.api:root_app_factory /: apiversions +/healthcheck: healthcheck /v2: openstack_volume_api_v2 /v3: openstack_volume_api_v3 @@ -63,3 +64,8 @@ paste.filter_factory = cinder.api.middleware.auth:CinderKeystoneContext.factory [filter:authtoken] paste.filter_factory = keystonemiddleware.auth_token:filter_factory + +[app:healthcheck] +paste.app_factory = oslo_middleware:Healthcheck.app_factory +backends = disable_by_file +disable_by_file_path = /etc/cinder/healthcheck_disable diff --git a/releasenotes/notes/healthcheck-449ed4292e6bfa22.yaml b/releasenotes/notes/healthcheck-449ed4292e6bfa22.yaml new file mode 100644 index 00000000000..09007b986a0 --- /dev/null +++ b/releasenotes/notes/healthcheck-449ed4292e6bfa22.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + The oslo.middleware /healthcheck is now activated by default in the Cinder + api-paste.ini. Operators can use it to configure HAproxy or the monitoring + of Cinder APIs. Edit the ``api-paste.ini`` file and remove any healthcheck + entries to disable this functionality.