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>
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
|
|
import mock
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import six
|
|
|
|
from pungi.scripts.config_validate import cli_main
|
|
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):
|
|
|
|
@mock.patch('sys.argv', new=['pungi-config-validate', DUMMY_CONFIG])
|
|
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
|
def test_validate_dummy_config(self, stdout, stderr):
|
|
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)
|