summaryrefslogtreecommitdiff
path: root/oslo_policy/tests
diff options
context:
space:
mode:
authorLance Bragstad <lbragstad@gmail.com>2019-07-25 16:28:01 +0000
committerBen Nemec <bnemec@redhat.com>2019-07-25 19:17:33 +0000
commit9641e5ca0d758376fb7f7f5156056d5206d71046 (patch)
tree3debc74165a27eb4baebb53b5f36c3b7e00fb4b2 /oslo_policy/tests
parentb7da7a92ad558947d6a133800f6049578e450b6a (diff)
downloadoslo-policy-9641e5ca0d758376fb7f7f5156056d5206d71046.tar.gz
Only alias when policy names change
Previously, oslo.policy would generate policy files with aliased names in the event the name was changing for backwards compatibility. This isn't needed if the name isn't changing and only the check string is changing. This patch adds a conditional to the generator logic that only aliases the old name to the new name if the name is changing. Otherwise, it only outputs comments about the deprecation. Co-Authored-By: Ben Nemec <bnemec@redhat.com> Change-Id: I89ff60354e4751a5096832023441d2e6166db92a
Diffstat (limited to 'oslo_policy/tests')
-rw-r--r--oslo_policy/tests/test_generator.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py
index ab0940a..18c5406 100644
--- a/oslo_policy/tests/test_generator.py
+++ b/oslo_policy/tests/test_generator.py
@@ -239,6 +239,49 @@ class GenerateSampleYAMLTestCase(base.PolicyBaseTestCase):
)
self.assertEqual(expected, stdout.getvalue())
+ def test_deprecated_policies_with_same_name(self):
+ deprecated_rule = policy.DeprecatedRule(
+ name='foo:create_bar',
+ check_str='role:old'
+ )
+ new_rule = policy.RuleDefault(
+ name='foo:create_bar',
+ check_str='role:fizz',
+ description='Create a bar.',
+ deprecated_rule=deprecated_rule,
+ deprecated_reason=(
+ 'role:fizz is a more sane default for foo:create_bar'
+ ),
+ deprecated_since='N'
+ )
+ opts = {'rules': [new_rule]}
+
+ extensions = []
+ for name, opts in opts.items():
+ ext = stevedore.extension.Extension(name=name, entry_point=None,
+ plugin=None, obj=opts)
+ extensions.append(ext)
+ test_mgr = stevedore.named.NamedExtensionManager.make_test_instance(
+ extensions=extensions, namespace=['rules'])
+
+ expected = '''# Create a bar.
+#"foo:create_bar": "role:fizz"
+
+# DEPRECATED "foo:create_bar":"role:old" has been deprecated since N
+# in favor of "foo:create_bar":"role:fizz". role:fizz is a more sane
+# default for foo:create_bar
+'''
+ stdout = self._capture_stdout()
+ with mock.patch('stevedore.named.NamedExtensionManager',
+ return_value=test_mgr) as mock_ext_mgr:
+ generator._generate_sample(['rules'], output_file=None)
+ mock_ext_mgr.assert_called_once_with(
+ 'oslo.policy.policies', names=['rules'],
+ on_load_failure_callback=generator.on_load_failure_callback,
+ invoke_on_load=True
+ )
+ self.assertEqual(expected, stdout.getvalue())
+
def _test_formatting(self, description, expected):
rule = [policy.RuleDefault('admin', 'is_admin:True',
description=description)]