loader: Validate section keys
This stops silly typos making their way into release notes. Change-Id: I43d98cc75332677c604e53a5b7a21239505ab4a4 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Story: 1670421 Task: 6737
This commit is contained in:
parent
c4b517292e
commit
8a80087d92
|
@ -2,4 +2,4 @@
|
||||||
features:
|
features:
|
||||||
- |
|
- |
|
||||||
Release note file validation is improved. Files missing section information
|
Release note file validation is improved. Files missing section information
|
||||||
will now be correctly handled and rejected.
|
will now be correctly handled and rejected, as will invalid sections.
|
||||||
|
|
|
@ -139,6 +139,15 @@ class Loader(object):
|
||||||
section_name, filename,
|
section_name, filename,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
if section_name not in dict(self._config.sections):
|
||||||
|
# TODO(stephenfin): Make this an error in a future release
|
||||||
|
LOG.warning(
|
||||||
|
'The %s section of %s is not a recognized section. '
|
||||||
|
'It should be one of: %s. '
|
||||||
|
'This will be an error in a future release.',
|
||||||
|
section_name, filename,
|
||||||
|
', '.join(dict(self._config.sections)),
|
||||||
|
)
|
||||||
if isinstance(section_content, str):
|
if isinstance(section_content, str):
|
||||||
# A single string is OK, but wrap it with a list
|
# A single string is OK, but wrap it with a list
|
||||||
# so the rest of the code can treat the data model
|
# so the rest of the code can treat the data model
|
||||||
|
|
|
@ -90,6 +90,20 @@ class TestValidate(base.TestCase):
|
||||||
ldr.parse_note_file('note1', None)
|
ldr.parse_note_file('note1', None)
|
||||||
self.assertIn('instead of a string', self.logger.output)
|
self.assertIn('instead of a string', self.logger.output)
|
||||||
|
|
||||||
|
def test_invalid_note_with_unrecognized_key(self):
|
||||||
|
"""Test behavior when note contains an unrecognized section."""
|
||||||
|
note_bodies = yaml.safe_load(textwrap.dedent('''
|
||||||
|
foobar:
|
||||||
|
- |
|
||||||
|
This is an issue but we're using an unrecognized section key.
|
||||||
|
'''))
|
||||||
|
self.assertIsInstance(note_bodies, dict)
|
||||||
|
ldr = self._make_loader(note_bodies)
|
||||||
|
ldr.parse_note_file('note1', None)
|
||||||
|
self.assertIn(
|
||||||
|
'The foobar section of note1 is not a recognized section.',
|
||||||
|
self.logger.output)
|
||||||
|
|
||||||
def test_invalid_note_with_missing_key(self):
|
def test_invalid_note_with_missing_key(self):
|
||||||
"""Test behavior when note is not structured as a mapping.
|
"""Test behavior when note is not structured as a mapping.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue