diff options
author | Ghanshyam Mann <gmann@ghanshyammann.com> | 2019-12-31 02:48:47 +0000 |
---|---|---|
committer | Matt Riedemann <mriedem.os@gmail.com> | 2020-01-07 17:58:09 +0000 |
commit | b0a0a7e00aeb5afc5758377dc925f2536f4a79c1 (patch) | |
tree | 7c51d45d268d2abcaa72f89ffbe5ceea62e7c8a2 | |
parent | 65aae518f81c2754e30429a3547c5cf62a3cf598 (diff) | |
download | nova-b0a0a7e00aeb5afc5758377dc925f2536f4a79c1.tar.gz |
Fix the suppress of policy deprecation warnings
oslo.policy log the deprected policy warning while loading the
policy rule. Flag to suppress the warning was set after load_rule()
was called.
Moving the setting of suppress_deprecation_warnings flag before
load_rule method is called.
Closes-Bug: #1858652
Change-Id: I3f30df8f0fdf76d763ee4770af074a2f4f400ee8
-rw-r--r-- | nova/policy.py | 7 | ||||
-rw-r--r-- | nova/tests/unit/policy_fixture.py | 7 |
2 files changed, 9 insertions, 5 deletions
diff --git a/nova/policy.py b/nova/policy.py index 1117b08d42..90f6376400 100644 --- a/nova/policy.py +++ b/nova/policy.py @@ -49,7 +49,8 @@ def reset(): _ENFORCER = None -def init(policy_file=None, rules=None, default_rule=None, use_conf=True): +def init(policy_file=None, rules=None, default_rule=None, use_conf=True, + suppress_deprecation_warnings=False): """Init an Enforcer class. :param policy_file: Custom policy file to use, if none is specified, @@ -59,6 +60,8 @@ def init(policy_file=None, rules=None, default_rule=None, use_conf=True): :param default_rule: Default rule to use, CONF.default_rule will be used if none is specified. :param use_conf: Whether to load rules from config file. + :param suppress_deprecation_warnings: Whether to suppress the + deprecation warnings. """ global _ENFORCER @@ -70,6 +73,8 @@ def init(policy_file=None, rules=None, default_rule=None, use_conf=True): rules=rules, default_rule=default_rule, use_conf=use_conf) + if suppress_deprecation_warnings: + _ENFORCER.suppress_deprecation_warnings = True register_rules(_ENFORCER) _ENFORCER.load_rules() diff --git a/nova/tests/unit/policy_fixture.py b/nova/tests/unit/policy_fixture.py index 0ed681141f..fee3d61641 100644 --- a/nova/tests/unit/policy_fixture.py +++ b/nova/tests/unit/policy_fixture.py @@ -50,11 +50,10 @@ class RealPolicyFixture(fixtures.Fixture): self._prepare_policy() CONF.set_override('policy_file', self.policy_file, group='oslo_policy') nova.policy.reset() - nova.policy.init() # NOTE(gmann): Logging all the deprecation warning for every unit - # test will overflow the log files and leads to error. Suppress - # the deprecation warning for tests only. - nova.policy._ENFORCER.suppress_deprecation_warnings = True + # test will overflow the log files. Suppress the deprecation warnings + # for tests. + nova.policy.init(suppress_deprecation_warnings=True) self.addCleanup(nova.policy.reset) def set_rules(self, rules, overwrite=True): |