summaryrefslogtreecommitdiff
path: root/oslo_policy
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-10-10 18:23:05 +0000
committerGerrit Code Review <review@openstack.org>2019-10-10 18:23:05 +0000
commit0f7e144d013155f27f74b0eb91b7ae0f1530a86b (patch)
tree38513071f83cf7b30ef06082c7e70dd1ec135a53 /oslo_policy
parentc70139727826023472e7cc9a58cd291c34574f1c (diff)
parent5d3aeb53a9f3686353e0740c1891bd0e66e90650 (diff)
downloadoslo-policy-0f7e144d013155f27f74b0eb91b7ae0f1530a86b.tar.gz
Merge "Suppress deprecation warnings in oslopolicy-list-redundant"
Diffstat (limited to 'oslo_policy')
-rw-r--r--oslo_policy/generator.py5
-rw-r--r--oslo_policy/tests/test_generator.py14
2 files changed, 17 insertions, 2 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py
index bd75389..9e283d9 100644
--- a/oslo_policy/generator.py
+++ b/oslo_policy/generator.py
@@ -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()
diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py
index 18c5406..a0beeae 100644
--- a/oslo_policy/tests/test_generator.py
+++ b/oslo_policy/tests/test_generator.py
@@ -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):