From d071de9c2bc49ecfd37cde5592ad8c928c89e92c Mon Sep 17 00:00:00 2001 From: Anusha Unnam Date: Wed, 8 Mar 2017 17:04:04 +0000 Subject: [PATCH] Seperate each policy rule with new line Changed generator code to add new line at the end of each policy, so that it would be easier to read. This change is required for implementing this spec https://review.openstack.org/#/c/433010/ blueprint policy-docs Change-Id: Ie85516b2741c94bab6e9bcd65f92ce38cb250fc6 --- oslo_policy/generator.py | 2 +- oslo_policy/tests/test_generator.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py index c4d4ee39..c1df6255 100644 --- a/oslo_policy/generator.py +++ b/oslo_policy/generator.py @@ -110,7 +110,7 @@ def _format_rule_default_yaml(default, include_help=True): {'name': default.name, 'check_str': default.check_str}) if include_help: - text = ('%(help)s\n%(text)s' % + text = ('%(help)s\n%(text)s\n' % {'help': _format_help_text(default.description), 'text': text}) return text diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py index 0ae61be3..6316d2cf 100644 --- a/oslo_policy/tests/test_generator.py +++ b/oslo_policy/tests/test_generator.py @@ -88,13 +88,17 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase): expected = '''# Basic admin check "admin": "is_admin:True" + # This is a long description to check that line wrapping functions # properly "owner": "project_id:%(project_id)s" + # "shared": "field:networks:shared=True" + # "admin_or_owner": "rule:admin or rule:owner" + ''' output_file = self.get_config_file_fullname('policy.yaml') with mock.patch('stevedore.named.NamedExtensionManager', @@ -121,13 +125,17 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase): expected = '''# Basic admin check "admin": "is_admin:True" + # This is a long description to check that line wrapping functions # properly "owner": "project_id:%(project_id)s" + # "shared": "field:networks:shared=True" + # "admin_or_owner": "rule:admin or rule:owner" + ''' stdout = self._capture_stdout() with mock.patch('stevedore.named.NamedExtensionManager', @@ -159,6 +167,7 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase): # # This is a description to check that empty line has no white spaces. "admin": "is_admin:True" + ''' output_file = self.get_config_file_fullname('policy.yaml') with mock.patch('stevedore.named.NamedExtensionManager',