From 94617a71761710544cf9505ffda5b6403a645a7e Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 9 Aug 2018 13:32:10 -0400 Subject: [PATCH] placement: ignore policy scope check failures if not enforcing scope Rather than spam the placement API logs with scope check warnings from oslo.policy when placement isn't configured for scope type enforcement, ignore those warnings. Note that the same warnings filter in the placement WarningsFixture is left intact because the configuration defaults setting code in wsgi.py which allows the warning filter to be set in deploy.py, is not run by the functional tests. In future changes this will be resolved by unifying configuration handling. Closes-Bug: #1786498 Related-Bug: #1784663 Change-Id: I34e4e550c9c31a654308e555210588156418f9e3 --- nova/api/openstack/placement/deploy.py | 7 +++++++ nova/api/openstack/placement/wsgi.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/nova/api/openstack/placement/deploy.py b/nova/api/openstack/placement/deploy.py index 28dde5c164b6..76de333ebb96 100644 --- a/nova/api/openstack/placement/deploy.py +++ b/nova/api/openstack/placement/deploy.py @@ -81,6 +81,13 @@ def deploy(conf): if middleware: application = middleware(application) + # NOTE(mriedem): Ignore scope check UserWarnings from oslo.policy. + if not conf.oslo_policy.enforce_scope: + import warnings + warnings.filterwarnings('ignore', + message="Policy .* failed scope check", + category=UserWarning) + return application diff --git a/nova/api/openstack/placement/wsgi.py b/nova/api/openstack/placement/wsgi.py index c17e2103b3c0..3a58fe5ef9ba 100644 --- a/nova/api/openstack/placement/wsgi.py +++ b/nova/api/openstack/placement/wsgi.py @@ -20,6 +20,7 @@ import os.path from oslo_log import log as logging from oslo_middleware import cors +from oslo_policy import opts as policy_opts from oslo_utils import importutils import pbr.version @@ -65,6 +66,10 @@ def _parse_args(argv, default_config_files): _set_middleware_defaults() + # This is needed so we can check [oslo_policy]/enforce_scope in the + # deploy module. + policy_opts.set_defaults(conf.CONF) + conf.CONF(argv[1:], project='nova', version=version_info.version_string(), default_config_files=default_config_files)