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.

Closes-Bug: #1937901
Change-Id: Id41e0313a481bea4e2bb14c69f2ad8a2070aa9be
This commit is contained in:
Takashi Kajinami 2021-07-23 20:53:24 +09:00 committed by Cyril Roelandt
parent 084c8a32f5
commit fa9450d5b5
5 changed files with 159 additions and 59 deletions

View File

@ -1697,19 +1697,21 @@ To enable the health check middleware, it must occur in the beginning of the
application pipeline. application pipeline.
The health check middleware should be placed in your The health check middleware should be placed in your
``glance-api-paste.ini`` in a section titled ``[filter:healthcheck]``. ``glance-api-paste.ini`` in a section titled ``[app:healthcheck]``.
It should look like this:: It should look like this::
[filter:healthcheck] [app:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file backends = disable_by_file
disable_by_file_path = /etc/glance/healthcheck_disable disable_by_file_path = /etc/glance/healthcheck_disable
A ready-made application pipeline including this filter is defined e.g. in A ready-made composite including this application is defined e.g. in
the ``glance-api-paste.ini`` file, looking like so:: the ``glance-api-paste.ini`` file, looking like so::
[pipeline:glance-api] [composite:glance-api]
pipeline = healthcheck versionnegotiation osprofiler unauthenticated-context rootapp paste.composite_factory = glance.api:root_app_factory
/: apiv2app
/healthcheck: healthcheck
For more information see For more information see
`oslo.middleware <https://docs.openstack.org/oslo.middleware/latest/reference/api.html#oslo_middleware.Healthcheck>`_. `oslo.middleware <https://docs.openstack.org/oslo.middleware/latest/reference/api.html#oslo_middleware.Healthcheck>`_.

View File

@ -1,26 +1,56 @@
# Use this pipeline for no auth or image caching - DEFAULT # Use this composite for no auth or image caching - DEFAULT
[pipeline:glance-api] [composite:glance-api]
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context rootapp paste.composite_factory = glance.api:root_app_factory
/: api
/healthcheck: healthcheck
# Use this pipeline for image caching and no auth [pipeline:api]
[pipeline:glance-api-caching] pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context rootapp
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context cache rootapp
# Use this pipeline for caching w/ management interface but no auth # Use this composite for image caching and no auth
[pipeline:glance-api-cachemanagement] [composite:glance-api-caching]
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context cache cachemanage rootapp paste.composite_factory = glance.api:root_app_factory
/: api-caching
/healthcheck: healthcheck
# Use this pipeline for keystone auth [pipeline:api-caching]
[pipeline:glance-api-keystone] pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context cache rootapp
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler authtoken context rootapp
# Use this pipeline for keystone auth with image caching # Use this composite for caching w/ management interface but no auth
[pipeline:glance-api-keystone+caching] [composite:glance-api-cachemanagement]
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler authtoken context cache rootapp paste.composite_factory = glance.api:root_app_factory
/: api-cachemanagement
/healthcheck: healthcheck
# Use this pipeline for keystone auth with caching and cache management [pipeline:api-cachemanagement]
[pipeline:glance-api-keystone+cachemanagement] pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler unauthenticated-context cache cachemanage rootapp
pipeline = cors healthcheck http_proxy_to_wsgi versionnegotiation osprofiler authtoken context cache cachemanage rootapp
# Use this composite for keystone auth
[composite:glance-api-keystone]
paste.composite_factory = glance.api:root_app_factory
/: api-keystone
/healthcheck: healthcheck
[pipeline:api-keystone]
pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler authtoken context rootapp
# Use this composite for keystone auth with image caching
[composite:glance-api-keystone+caching]
paste.composite_factory = glance.api:root_app_factory
/: api-keystone+caching
/healthcheck: healthcheck
[pipeline:api-keystone+caching]
pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler authtoken context cache rootapp
# Use this composite for keystone auth with caching and cache management
[composite:glance-api-keystone+cachemanagement]
paste.composite_factory = glance.api:root_app_factory
/: api-keystone+cachemanagement
/healthcheck: healthcheck
[pipeline:api-keystone+cachemanagement]
pipeline = cors http_proxy_to_wsgi versionnegotiation osprofiler authtoken context cache cachemanage rootapp
[composite:rootapp] [composite:rootapp]
paste.composite_factory = glance.api:root_app_factory paste.composite_factory = glance.api:root_app_factory
@ -33,8 +63,8 @@ paste.app_factory = glance.api.versions:create_resource
[app:apiv2app] [app:apiv2app]
paste.app_factory = glance.api.v2.router:API.factory paste.app_factory = glance.api.v2.router:API.factory
[filter:healthcheck] [app:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file backends = disable_by_file
disable_by_file_path = /etc/glance/healthcheck_disable disable_by_file_path = /etc/glance/healthcheck_disable

View File

@ -468,23 +468,35 @@ default_store = %(default_store)s
[import_filtering_opts] [import_filtering_opts]
allowed_ports = [] allowed_ports = []
""" """
self.paste_conf_base = """[pipeline:glance-api] self.paste_conf_base = """[composite:glance-api]
paste.composite_factory = glance.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = pipeline =
cors cors
healthcheck
versionnegotiation versionnegotiation
gzip gzip
unauthenticated-context unauthenticated-context
rootapp rootapp
[pipeline:glance-api-caching] [composite:glance-api-caching]
pipeline = cors healthcheck versionnegotiation gzip context paste.composite_factory = glance.api:root_app_factory
cache rootapp /: api-caching
/healthcheck: healthcheck
[pipeline:glance-api-cachemanagement] [pipeline:api-caching]
pipeline = cors versionnegotiation gzip context cache rootapp
[composite:glance-api-cachemanagement]
paste.composite_factory = glance.api:root_app_factory
/: api-cachemanagement
/healthcheck: healthcheck
[pipeline:api-cachemanagement]
pipeline = pipeline =
cors cors
healthcheck
versionnegotiation versionnegotiation
gzip gzip
unauthenticated-context unauthenticated-context
@ -492,11 +504,21 @@ pipeline =
cache_manage cache_manage
rootapp rootapp
[pipeline:glance-api-fakeauth] [composite:glance-api-fakeauth]
pipeline = cors healthcheck versionnegotiation gzip fakeauth context rootapp paste.composite_factory = glance.api:root_app_factory
/: api-fakeauth
/healthcheck: healthcheck
[pipeline:glance-api-noauth] [pipeline:api-fakeauth]
pipeline = cors healthcheck versionnegotiation gzip context rootapp pipeline = cors versionnegotiation gzip fakeauth context rootapp
[composite:glance-api-noauth]
paste.composite_factory = glance.api:root_app_factory
/: api-noauth
/healthcheck: healthcheck
[pipeline:api-noauth]
pipeline = cors versionnegotiation gzip context rootapp
[composite:rootapp] [composite:rootapp]
paste.composite_factory = glance.api:root_app_factory paste.composite_factory = glance.api:root_app_factory
@ -509,8 +531,8 @@ paste.app_factory = glance.api.versions:create_resource
[app:apiv2app] [app:apiv2app]
paste.app_factory = glance.api.v2.router:API.factory paste.app_factory = glance.api.v2.router:API.factory
[filter:healthcheck] [app:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file backends = disable_by_file
disable_by_file_path = %(disable_path)s disable_by_file_path = %(disable_path)s
@ -643,23 +665,35 @@ allowed_ports = []
[os_glance_staging_store] [os_glance_staging_store]
filesystem_store_datadir=%(staging_dir)s filesystem_store_datadir=%(staging_dir)s
""" """
self.paste_conf_base = """[pipeline:glance-api] self.paste_conf_base = """[composite:glance-api]
paste.composite_factory = glance.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = pipeline =
cors cors
healthcheck
versionnegotiation versionnegotiation
gzip gzip
unauthenticated-context unauthenticated-context
rootapp rootapp
[pipeline:glance-api-caching] [composite:glance-api-caching]
pipeline = cors healthcheck versionnegotiation gzip unauthenticated-context paste.composite_factory = glance.api:root_app_factory
cache rootapp /: api-caching
/healthcheck: healthcheck
[pipeline:glance-api-cachemanagement] [pipeline:api-caching]
pipeline = cors versionnegotiation gzip unauthenticated-context cache rootapp
[composite:glance-api-cachemanagement]
paste.composite_factory = glance.api:root_app_factory
/: api-cachemanagement
/healthcheck: healthcheck
[pipeline:api-cachemanagement]
pipeline = pipeline =
cors cors
healthcheck
versionnegotiation versionnegotiation
gzip gzip
unauthenticated-context unauthenticated-context
@ -667,11 +701,21 @@ pipeline =
cache_manage cache_manage
rootapp rootapp
[pipeline:glance-api-fakeauth] [composite:glance-api-fakeauth]
pipeline = cors healthcheck versionnegotiation gzip fakeauth context rootapp paste.composite_factory = glance.api:root_app_factory
/: api-fakeauth
/healthcheck: healthcheck
[pipeline:glance-api-noauth] [pipeline:api-fakeauth]
pipeline = cors healthcheck versionnegotiation gzip context rootapp pipeline = cors versionnegotiation gzip fakeauth context rootapp
[composite:glance-api-noauth]
paste.composite_factory = glance.api:root_app_factory
/: api-noauth
/healthcheck: healthcheck
[pipeline:api-noauth]
pipeline = cors versionnegotiation gzip context rootapp
[composite:rootapp] [composite:rootapp]
paste.composite_factory = glance.api:root_app_factory paste.composite_factory = glance.api:root_app_factory
@ -684,8 +728,8 @@ paste.app_factory = glance.api.versions:create_resource
[app:apiv2app] [app:apiv2app]
paste.app_factory = glance.api.v2.router:API.factory paste.app_factory = glance.api.v2.router:API.factory
[filter:healthcheck] [app:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file backends = disable_by_file
disable_by_file_path = %(disable_path)s disable_by_file_path = %(disable_path)s

View File

@ -31,13 +31,25 @@ from glance.tests import utils as test_utils
TESTING_API_PASTE_CONF = """ TESTING_API_PASTE_CONF = """
[pipeline:glance-api] [composite:glance-api]
paste.composite_factory = glance.api:root_app_factory
/: api
[pipeline: api]
pipeline = versionnegotiation gzip unauthenticated-context rootapp pipeline = versionnegotiation gzip unauthenticated-context rootapp
[pipeline:glance-api-caching] [composite:glance-api-caching]
paste.composite_factory = glance.api:root_app_factory
/: api-caching
[pipeline: api-caching]
pipeline = versionnegotiation gzip unauthenticated-context cache rootapp pipeline = versionnegotiation gzip unauthenticated-context cache rootapp
[pipeline:glance-api-cachemanagement] [composite:glance-api-cachemanagement]
paste.composite_factory = glance.api:root_app_factory
/: api-cachemanagement
[pipeline: api-cachemanagement]
pipeline = pipeline =
versionnegotiation versionnegotiation
gzip gzip
@ -46,10 +58,18 @@ pipeline =
cache_manage cache_manage
rootapp rootapp
[pipeline:glance-api-fakeauth] [composite:glance-api-fakeauth]
paste.composite_factory = glance.api:root_app_factory
/: api-fakeauth
[pipeline: api-fakeauth]
pipeline = versionnegotiation gzip fakeauth context rootapp pipeline = versionnegotiation gzip fakeauth context rootapp
[pipeline:glance-api-noauth] [composite:glance-api-noauth]
paste.composite_factory = glance.api:root_app_factory
/: api-noauth
[pipeline: api-noauth]
pipeline = versionnegotiation gzip context rootapp pipeline = versionnegotiation gzip context rootapp
[composite:rootapp] [composite:rootapp]

View File

@ -66,7 +66,7 @@ class TestPasteApp(test_utils.BaseTestCase):
app = config.load_paste_app('glance-api') app = config.load_paste_app('glance-api')
self.assertIsInstance(app, expected_app_type) self.assertIsInstance(app['/'], expected_app_type)
def test_load_paste_app(self): def test_load_paste_app(self):
expected_middleware = oslo_middleware.CORS expected_middleware = oslo_middleware.CORS
@ -78,7 +78,11 @@ class TestPasteApp(test_utils.BaseTestCase):
expected_middleware, make_paste_file=False) expected_middleware, make_paste_file=False)
def test_load_paste_app_with_paste_flavor(self): def test_load_paste_app_with_paste_flavor(self):
pipeline = ('[pipeline:glance-api-incomplete]\n' pipeline = ('[composite:glance-api-incomplete]\n'
'paste.composite_factory = glance.api:root_app_factory\n'
'/: api-incomplete\n'
'/healthcheck: healthcheck\n'
'[pipeline:api-incomplete]\n'
'pipeline = context rootapp') 'pipeline = context rootapp')
expected_middleware = context.ContextMiddleware expected_middleware = context.ContextMiddleware
self._do_test_load_paste_app(expected_middleware, self._do_test_load_paste_app(expected_middleware,