From e8151070c052c2a26037cdad3ad3330899ff334b Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 31 Jul 2019 18:28:16 -0700 Subject: [PATCH] Suppress policy deprecation warnings in unit tests Since the WSGI app is reinitialized pretty much for every unit test, and we have deprecated so many policies, we get hundreds of megabytes of deprecation warnings in the unit test logs. This is unnecessary for unit tests, a noisy hindrance to developers, and causes a high failure rate in our CI due to the huge logs. This change fixes the issue for the unit tests by adding warnings filters for DeprecationWarnings and UserWarnings from oslo.policy and oslo.context. This does not solve the issue that deployers see a lot of noise in their logs. However, since production servers aren't reinitializing the WSGI app quite so often, it's a less severe issue. Related-bug: #1836568 Change-Id: Iaa7eae03bde7ab43a8c5a5886686f834cf7ec620 Depends-on: https://review.opendev.org/673932 --- keystone/common/rbac_enforcer/enforcer.py | 4 ++++ keystone/tests/unit/ksfixtures/policy.py | 1 + lower-constraints.txt | 2 +- requirements.txt | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/keystone/common/rbac_enforcer/enforcer.py b/keystone/common/rbac_enforcer/enforcer.py index 8b22e21bd6..defae6c754 100644 --- a/keystone/common/rbac_enforcer/enforcer.py +++ b/keystone/common/rbac_enforcer/enforcer.py @@ -45,6 +45,8 @@ class RBACEnforcer(object): __shared_state__ = {} __ENFORCER = None ACTION_STORE_ATTR = 'keystone:RBAC:action_name' + # FOR TESTS ONLY + suppress_deprecation_warnings = False def __init__(self): # NOTE(morgan): All Enforcer Instances use the same shared state; @@ -92,6 +94,8 @@ class RBACEnforcer(object): # The raw oslo-policy enforcer object if self.__ENFORCER is None: self.__ENFORCER = common_policy.Enforcer(CONF) + if self.suppress_deprecation_warnings: + self.__ENFORCER.suppress_deprecation_warnings = True self.register_rules(self.__ENFORCER) return self.__ENFORCER diff --git a/keystone/tests/unit/ksfixtures/policy.py b/keystone/tests/unit/ksfixtures/policy.py index e6dbf0c7b7..2adfe6a0a4 100644 --- a/keystone/tests/unit/ksfixtures/policy.py +++ b/keystone/tests/unit/ksfixtures/policy.py @@ -29,4 +29,5 @@ class Policy(fixtures.Fixture): opts.set_defaults(self._config_fixture.conf) self._config_fixture.config(group='oslo_policy', policy_file=self._policy_file) + policy._ENFORCER.suppress_deprecation_warnings = True self.addCleanup(policy.reset) diff --git a/lower-constraints.txt b/lower-constraints.txt index 307e9246d3..8c78350ef5 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -34,7 +34,7 @@ oslo.i18n==3.15.3 oslo.log==3.44.0 oslo.messaging==5.29.0 oslo.middleware==3.31.0 -oslo.policy==1.43.1 +oslo.policy==2.3.0 oslo.serialization==2.18.0 oslo.upgradecheck==0.1.0 oslo.utils==3.33.0 diff --git a/requirements.txt b/requirements.txt index b46f3cfe40..d33a948748 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,7 +29,7 @@ oslo.db>=4.27.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.44.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 -oslo.policy>=1.43.1 # Apache-2.0 +oslo.policy>=2.3.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0