Merge "policy: Suppress policy deprecation warnings"

This commit is contained in:
Zuul 2021-02-03 18:35:25 +00:00 committed by Gerrit Code Review
commit cf3e2d5785
2 changed files with 23 additions and 3 deletions

View File

@ -33,11 +33,29 @@ def reset():
_ENFORCER = None
def init(conf):
"""Init an Enforcer class. Sets the _ENFORCER global."""
def init(
conf: cfg.ConfigOpts,
suppress_deprecation_warnings: bool = False,
):
"""Init an Enforcer class. Sets the _ENFORCER global.
:param conf: A ConfigOpts object to load configuration from.
:param suppress_deprecation_warnings: **Test only** Suppress policy
deprecation warnings to avoid polluting logs.
"""
global _ENFORCER
if not _ENFORCER:
_enforcer = policy.Enforcer(conf)
# NOTE(gmann): Explictly disable the warnings for policies changing
# their default check_str. During the policy-defaults-refresh work, all
# the policy defaults have been changed and warnings for each policy
# started filling the logs limit for various tool.
# Once we move to new defaults only world then we can enable these
# warnings again.
_enforcer.suppress_default_change_warnings = True
_enforcer.suppress_deprecation_warnings = suppress_deprecation_warnings
_enforcer.register_defaults(policies.list_rules())
_enforcer.load_rules()
_ENFORCER = _enforcer

View File

@ -32,7 +32,9 @@ class PolicyFixture(fixtures.Fixture):
policy_file = paths.state_path_def('etc/placement/policy.yaml')
self.conf_fixture.config(group='oslo_policy', policy_file=policy_file)
placement_policy.reset()
placement_policy.init(self.conf_fixture.conf)
placement_policy.init(
self.conf_fixture.conf,
suppress_deprecation_warnings=True)
self.addCleanup(placement_policy.reset)
@staticmethod