Browse Source

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
changes/38/805038/2
Takashi Kajinami 5 months ago
parent
commit
ce217a287c
  1. 18
      doc/source/admin/configuring.rst
  2. 13
      etc/magnum/api-paste.ini
  3. 16
      magnum/api/__init__.py
  4. 13
      magnum/tests/unit/api/controllers/auth-paste.ini
  5. 13
      magnum/tests/unit/api/controllers/auth-root-access.ini
  6. 13
      magnum/tests/unit/api/controllers/auth-v1-access.ini
  7. 2
      magnum/tests/unit/api/controllers/test_root.py

18
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

13
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

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

13
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

13
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

13
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

2
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:

Loading…
Cancel
Save