Suppress deprecation warnings in policy enforer

As we are in the middle of the migration to new secure RBAC policies
and we have a lot of deprecated default rules, our log in e.g.
functional tests has a lot of messages about deprecated rules.

So lets suppress those deprecation warnings in the tests to make our
test outputs smaller.

Related blueprint: secure-rbac-roles

Change-Id: Iab3966bad81b469eccf1050f0e0e48b9e2573750
This commit is contained in:
Slawek Kaplonski 2021-01-11 13:38:59 +01:00 committed by Sean Mooney
parent f21b8950f8
commit c68df5aeec
2 changed files with 11 additions and 2 deletions

View File

@ -68,12 +68,21 @@ def register_rules(enforcer):
enforcer.register_defaults(itertools.chain(*policies))
def init(conf=cfg.CONF, policy_file=None):
def init(conf=cfg.CONF, policy_file=None, suppress_deprecation_warnings=False):
"""Init an instance of the Enforcer class."""
global _ENFORCER
if not _ENFORCER:
_ENFORCER = policy.Enforcer(conf, policy_file=policy_file)
# TODO(slaweq) Explictly disable the warnings for policies
# changing their default check_str. During policy-defaults-refresh
# work, all the policy defaults have been changed and warning for
# each policy started filling the logs limit for various tool.
# Once we move to new defaults only world then we can enable these
# warning again.
_ENFORCER.suppress_default_change_warnings = True
if suppress_deprecation_warnings:
_ENFORCER.suppress_deprecation_warnings = True
register_rules(_ENFORCER)
_ENFORCER.load_rules(True)

View File

@ -394,7 +394,7 @@ class BaseTestCase(DietTestCase):
# Give a private copy of the directory to each test.
self.useFixture(fixture.PluginDirectoryFixture())
policy.init()
policy.init(suppress_deprecation_warnings=True)
self.addCleanup(policy.reset)
self.addCleanup(resource_registry.unregister_all_resources)
self.addCleanup(db_api.sqla_remove_all)