Merge "Remove erroneous newline in sample generation"

This commit is contained in:
Zuul 2018-06-04 07:19:23 +00:00 committed by Gerrit Code Review
commit 7a50c85a38
3 changed files with 46 additions and 2 deletions

View File

@ -136,8 +136,7 @@ def _format_rule_default_yaml(default, include_help=True):
if default.deprecated_for_removal:
text = (
'# DEPRECATED\n# "%(name)s" has been deprecated since '
'%(since)s.\n%(reason)s\n%(text)s\n'
'"%(name)s": "%(check_str)s"'
'%(since)s.\n%(reason)s\n%(text)s'
) % {'name': default.name,
'check_str': default.check_str,
'since': default.deprecated_since,

View File

@ -160,6 +160,45 @@ class GenerateSampleYAMLTestCase(base.PolicyBaseTestCase):
self.assertEqual(expected, stdout.getvalue())
def test_policies_deprecated_for_removal(self):
rule = policy.RuleDefault(
name='foo:post_bar',
check_str='role:fizz',
description='Create a bar.',
deprecated_for_removal=True,
deprecated_reason='This policy is not used anymore',
deprecated_since='N'
)
opts = {'rules': [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 = '''# DEPRECATED
# "foo:post_bar" has been deprecated since N.
# This policy is not used anymore
# Create a bar.
#"foo:post_bar": "role:fizz"
'''
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_deprecated_policies_are_aliased_to_new_names(self):
deprecated_rule = policy.DeprecatedRule(
name='foo:post_bar',

View File

@ -0,0 +1,6 @@
---
fixes:
- |
[`bug 1771442 <https://bugs.launchpad.net/oslo.policy/+bug/1771442>`_]
Policy rules that are deprecated for removal are now properly formatted
when rendering sample policy files for documentation.