config: Improve config validation for anyOf and oneOf

Instead of just saying that there is a problem, give all possible
reasons.

JIRA: COMPOSE-3636
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-06-25 12:50:07 +02:00
parent acd3c19618
commit 4e59c7595e
2 changed files with 10 additions and 3 deletions

View File

@ -200,6 +200,9 @@ def validate(config, offline=False):
else: else:
errors.append('Failed validation in %s: %s' % ( errors.append('Failed validation in %s: %s' % (
'.'.join([str(x) for x in error.path]), error.message)) '.'.join([str(x) for x in error.path]), error.message))
if error.validator in ("anyOf", "oneOf"):
for suberror in error.context:
errors.append(" Possible reason: %s" % suberror.message)
return (errors + _validate_requires(schema, config, CONFIG_DEPS), return (errors + _validate_requires(schema, config, CONFIG_DEPS),
warnings) warnings)

View File

@ -270,9 +270,13 @@ class OSBSThreadTest(helpers.PungiTestCase):
config['osbs'] = { config['osbs'] = {
'^Server$': cfg '^Server$': cfg
} }
self.assertEqual( errors, warnings = checks.validate(config, offline=True)
(['Failed validation in osbs.^Server$: %r is not valid under any of the given schemas' % cfg], []), self.assertIn(
checks.validate(config, offline=True)) "Failed validation in osbs.^Server$: %r is not valid under any of the given schemas" % cfg,
errors,
)
self.assertIn(" Possible reason: %r is a required property" % key, errors)
self.assertEqual([], warnings)
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
def test_minimal_run(self, KojiWrapper): def test_minimal_run(self, KojiWrapper):