Add --schema-override to pungi-config-validate script

Some composes might need extra validation to ensure they are following
certain strict rules - for example containing only signed packages or
packages only from particular Koji tag.

There is currently no way how to check that Pungi configuration fulfills
these extra requirements.

This commit adds new `--schema-override` option to
`pungi-config-validate` script which allows caller to specify path to
JSON schema overriding the default JSON schema and therefore limitting
it further.

For exmaple, to limit the `pkgset_source` to `koji`, one can use
following JSON schema override:

```
{
    "properties": {
        "pkgset_source": {
            "enum": ["koji"]
        }
    }
}
```

It is possible to use `--schema-override` multiple times to apply
multiple schema overrides.

Merges: https://pagure.io/pungi/pull-request/1341
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
Jan Kaluza 2020-02-03 12:43:27 +01:00 committed by Lubomír Sedlář
parent 6f23c7b8ba
commit ef33d00f5b
5 changed files with 86 additions and 5 deletions

View file

@ -13,6 +13,7 @@ from tests import helpers
HERE = os.path.abspath(os.path.dirname(__file__))
DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
SCHEMA_OVERRIDE = os.path.join(HERE, 'data/dummy-override.json')
class ConfigValidateScriptTest(helpers.PungiTestCase):
@ -24,3 +25,16 @@ class ConfigValidateScriptTest(helpers.PungiTestCase):
cli_main()
self.assertEqual('', stdout.getvalue())
self.assertEqual('', stderr.getvalue())
@mock.patch('sys.argv', new=[
'pungi-config-validate', DUMMY_CONFIG, "--schema-override",
SCHEMA_OVERRIDE])
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.exit')
def test_schema_override(self, exit, stdout, stderr):
cli_main()
self.assertTrue(stdout.getvalue().startswith(
"Failed validation in pkgset_source: 'repos' is not one of"))
self.assertEqual('', stderr.getvalue())
exit.assert_called_once_with(1)