Include deprecated_reason when deprecated_rule is set

Previously deprecated_reason was only included in the sample policy
file in the deprecated_for_removal case.  There's no reason users
wouldn't want to be able to provide an explanation for deprecated_rule
deprecations too.

Change-Id: I4036bf8efcd42ca4b1a35ae6940ac69af7fe205b
Closes-Bug: 1771416
This commit is contained in:
Ben Nemec 2018-05-15 20:18:53 +00:00
parent 48949f5e20
commit 90e6412210
2 changed files with 4 additions and 2 deletions

View File

@ -149,12 +149,13 @@ def _format_rule_default_yaml(default, include_help=True):
deprecated_text = (
'DEPRECATED\n"%(old_name)s":"%(old_check_str)s" has been '
'deprecated since %(since)s in favor of '
'"%(name)s":"%(check_str)s".'
'"%(name)s":"%(check_str)s".\n%(reason)s'
) % {'old_name': default.deprecated_rule.name,
'old_check_str': default.deprecated_rule.check_str,
'since': default.deprecated_since,
'name': default.name,
'check_str': default.check_str}
'check_str': default.check_str,
'reason': default.deprecated_reason}
text = (
'%(text)s%(deprecated_text)s\n"%(old_name)s": "rule:%(name)s"\n'

View File

@ -191,6 +191,7 @@ class GenerateSampleYAMLTestCase(base.PolicyBaseTestCase):
# DEPRECATED
# "foo:post_bar":"role:fizz" has been deprecated since N in favor of
# "foo:create_bar":"role:fizz".
# foo:post_bar is being removed in favor of foo:create_bar
"foo:post_bar": "rule:foo:create_bar"
'''
stdout = self._capture_stdout()