From ce217a287c11cef13e755fc5f2373acd066c726d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 18 Aug 2021 23:42:41 +0900 Subject: [PATCH] Deploy healthcheck middleware as app instead of filter Using the healthcheck middleware as a filter is deprecated and the middleware should be used as an application[1]. [1] 6feaa13610c450c8486f969703768db5319b4846 This change updates definition and usage of the healthcheck middleware accordingly to avoid the following deprecation warning. DeprecationWarning: Using function/method 'Healthcheck.factory()' is deprecated: The healthcheck middleware must now be configured as an application, not as a filter. Change-Id: Ie81140d3b03c315f0a057d2f59754ee14dac539c --- doc/source/admin/configuring.rst | 18 ++++++++++-------- etc/magnum/api-paste.ini | 13 +++++++++---- magnum/api/__init__.py | 16 ++++++++++++++++ .../tests/unit/api/controllers/auth-paste.ini | 13 +++++++++---- .../unit/api/controllers/auth-root-access.ini | 13 +++++++++---- .../unit/api/controllers/auth-v1-access.ini | 13 +++++++++---- magnum/tests/unit/api/controllers/test_root.py | 2 +- 7 files changed, 63 insertions(+), 25 deletions(-) diff --git a/doc/source/admin/configuring.rst b/doc/source/admin/configuring.rst index 4c4c74744c..27721b34b7 100644 --- a/doc/source/admin/configuring.rst +++ b/doc/source/admin/configuring.rst @@ -35,20 +35,22 @@ Healthcheck Middleware This piece of middleware creates an endpoint that allows a load balancer to probe if the API endpoint should be available at the node or not. -The healthcheck middleware should be placed early in the pipeline. Which -is located in your ``api-paste.ini`` under a section called -``[filter:healthcheck]``. It should look like this:: +The healthcheck middleware should be deployed as a paste application +application. Which is located in your ``api-paste.ini`` under a section called +``[app:healthcheck]``. It should look like this:: - [filter:healthcheck] - paste.filter_factory = oslo_middleware:Healthcheck.factory + [app:healthcheck] + paste.app_factory = oslo_middleware:Healthcheck.app_factory backends = disable_by_file disable_by_file_path = /etc/magnum/healthcheck_disable -The main pipeline using this filter should look something like this also +The main pipeline using this application should look something like this also defined in the ``api-paste.ini``:: - [pipeline:main] - pipeline = cors healthcheck request_id authtoken api_v1 + [composite:main] + paste.composite_factory = magnum.api:root_app_factory + /: api + /healthcheck: healthcheck If you wish to disable a middleware without taking it out of the pipeline, you can create a file under the file path defined by diff --git a/etc/magnum/api-paste.ini b/etc/magnum/api-paste.ini index d1f56fb7f4..5001149ae2 100644 --- a/etc/magnum/api-paste.ini +++ b/etc/magnum/api-paste.ini @@ -1,5 +1,10 @@ -[pipeline:main] -pipeline = cors healthcheck http_proxy_to_wsgi request_id osprofiler authtoken api_v1 +[composite:main] +paste.composite_factory = magnum.api:root_app_factory +/: api +/healthcheck: healthcheck + +[pipeline:api] +pipeline = cors http_proxy_to_wsgi request_id osprofiler authtoken api_v1 [app:api_v1] paste.app_factory = magnum.api.app:app_factory @@ -18,8 +23,8 @@ paste.filter_factory = oslo_middleware:RequestId.factory paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = magnum -[filter:healthcheck] -paste.filter_factory = oslo_middleware:Healthcheck.factory +[app:healthcheck] +paste.app_factory = oslo_middleware:Healthcheck.app_factory backends = disable_by_file disable_by_file_path = /etc/magnum/healthcheck_disable diff --git a/magnum/api/__init__.py b/magnum/api/__init__.py index e69de29bb2..05f7b7aff8 100644 --- a/magnum/api/__init__.py +++ b/magnum/api/__init__.py @@ -0,0 +1,16 @@ +# 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. +import paste.urlmap + + +def root_app_factory(loader, global_conf, **local_conf): + return paste.urlmap.urlmap_factory(loader, global_conf, **local_conf) diff --git a/magnum/tests/unit/api/controllers/auth-paste.ini b/magnum/tests/unit/api/controllers/auth-paste.ini index 0964f0ee01..ac7ad86f6d 100644 --- a/magnum/tests/unit/api/controllers/auth-paste.ini +++ b/magnum/tests/unit/api/controllers/auth-paste.ini @@ -1,5 +1,10 @@ -[pipeline:main] -pipeline = cors healthcheck request_id authtoken api_v1 +[composite:main] +paste.composite_factory = magnum.api:root_app_factory +/: api +/healthcheck: healthcheck + +[pipeline:api] +pipeline = cors request_id authtoken api_v1 [app:api_v1] paste.app_factory = magnum.api.app:app_factory @@ -14,7 +19,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = magnum -[filter:healthcheck] -paste.filter_factory = oslo_middleware:Healthcheck.factory +[app:healthcheck] +paste.app_factory = oslo_middleware:Healthcheck.app_factory backends = disable_by_file disable_by_file_path = /tmp/magnum_healthcheck_disable diff --git a/magnum/tests/unit/api/controllers/auth-root-access.ini b/magnum/tests/unit/api/controllers/auth-root-access.ini index c8475c6d30..206c739ef0 100644 --- a/magnum/tests/unit/api/controllers/auth-root-access.ini +++ b/magnum/tests/unit/api/controllers/auth-root-access.ini @@ -1,5 +1,10 @@ -[pipeline:main] -pipeline = cors healthcheck request_id authtoken api_v1 +[composite:main] +paste.composite_factory = magnum.api:root_app_factory +/: api +/healthcheck: healthcheck + +[pipeline:api] +pipeline = cors request_id authtoken api_v1 [app:api_v1] paste.app_factory = magnum.api.app:app_factory @@ -15,7 +20,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = magnum -[filter:healthcheck] -paste.filter_factory = oslo_middleware:Healthcheck.factory +[app:healthcheck] +paste.app_factory = oslo_middleware:Healthcheck.app_factory backends = disable_by_file disable_by_file_path = /tmp/magnum_healthcheck_disable diff --git a/magnum/tests/unit/api/controllers/auth-v1-access.ini b/magnum/tests/unit/api/controllers/auth-v1-access.ini index 604bec1647..67e6885786 100644 --- a/magnum/tests/unit/api/controllers/auth-v1-access.ini +++ b/magnum/tests/unit/api/controllers/auth-v1-access.ini @@ -1,5 +1,10 @@ -[pipeline:main] -pipeline = cors healthcheck request_id authtoken api_v1 +[composite:main] +paste.composite_factory = magnum.api:root_app_factory +/: api +/healthcheck: healthcheck + +[pipeline:api] +pipeline = cors request_id authtoken api_v1 [app:api_v1] paste.app_factory = magnum.api.app:app_factory @@ -15,7 +20,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = magnum -[filter:healthcheck] -paste.filter_factory = oslo_middleware:Healthcheck.factory +[app:healthcheck] +paste.app_factory = oslo_middleware:Healthcheck.app_factory backends = disable_by_file disable_by_file_path = /tmp/magnum_healthcheck_disable diff --git a/magnum/tests/unit/api/controllers/test_root.py b/magnum/tests/unit/api/controllers/test_root.py index 9f2fa22c94..e187715016 100644 --- a/magnum/tests/unit/api/controllers/test_root.py +++ b/magnum/tests/unit/api/controllers/test_root.py @@ -195,7 +195,7 @@ class TestHeathcheck(api_base.FunctionalTest): # Read current file and create new one config = ConfigParser.RawConfigParser() config.read(self.get_path(paste_ini)) - config.set('filter:healthcheck', + config.set('app:healthcheck', 'disable_by_file_path', self.tempdir + "/disable") with open(self.tempdir + "/paste.ini", 'wt') as configfile: