Merge "Suppress deprecation warnings in oslopolicy-list-redundant"

This commit is contained in:
Zuul 2019-10-10 18:23:05 +00:00 committed by Gerrit Code Review
commit 0f7e144d01
3 changed files with 23 additions and 2 deletions

View File

@ -315,6 +315,11 @@ def _list_redundant(namespace):
in a policy file and operators should consider removing them.
"""
enforcer = _get_enforcer(namespace)
# NOTE(bnemec): We don't want to see policy deprecation warnings in the
# output of this tool. They tend to overwhelm the output that the user
# actually cares about, and checking for deprecations isn't the purpose of
# this tool.
enforcer.suppress_deprecation_warnings = True
# Ensure that files have been parsed
enforcer.load_rules()

View File

@ -564,7 +564,8 @@ class ListRedundantTestCase(base.PolicyBaseTestCase):
def setUp(self):
super(ListRedundantTestCase, self).setUp()
def test_matched_rules(self):
@mock.patch('warnings.warn')
def test_matched_rules(self, mock_warn):
extensions = []
for name, opts in OPTS.items():
ext = stevedore.extension.Extension(name=name, entry_point=None,
@ -587,7 +588,13 @@ class ListRedundantTestCase(base.PolicyBaseTestCase):
enforcer.register_default(
policy.RuleDefault('owner', 'project_id:%(project_id)s'))
# register a new opt
enforcer.register_default(policy.RuleDefault('foo', 'role:foo'))
deprecated_rule = policy.DeprecatedRule('old_foo', 'role:bar')
enforcer.register_default(
policy.RuleDefault('foo', 'role:foo',
deprecated_rule=deprecated_rule,
deprecated_reason='reason',
deprecated_since='T')
)
# Mock out stevedore to return the configured enforcer
ext = stevedore.extension.Extension(name='testing', entry_point=None,
@ -618,6 +625,9 @@ class ListRedundantTestCase(base.PolicyBaseTestCase):
self.assertEqual('"owner"', opt1[0])
self.assertEqual('"project_id:%(project_id)s"', opt1[1])
self.assertFalse(mock_warn.called,
'Deprecation warnings not suppressed.')
class UpgradePolicyTestCase(base.PolicyBaseTestCase):
def setUp(self):

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Deprecated policy warnings are now suppressed in the
``oslopolicy-list-redundant`` tool so that they don't overwhelm the
relevant output.