Add JSON Schema for configuration

The schema is written in Python to reduce duplication. When
configuration is loaded, the validation checks if it's correct and fills
in default values.

There is a custom extension to the schema to report deprecated options.

The config dependencies are implemented as a separate pass. While it's
technically possible to express the dependencies in the schema itself,
the error messages are not very helpful and it makes the schema much
harder to read.

Phases no longer define `config_options`. New options should be added to
the schema. Since the default values are populated automatically during
validation, there is no need to duplicate them into the code.

The `pungi-config-validate` script is updated to use the schema and
report errors even for deeply nested fields.

The dependencies are updated: pungi now depends on `python-jsonschema`
(which is already available in Fedora).

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-08-22 16:08:25 +02:00
parent 5534fda192
commit f9a6c8418f
53 changed files with 1423 additions and 903 deletions

View file

@ -11,7 +11,7 @@ import shutil
import errno
from pungi.util import get_arch_variant_data
from pungi import paths
from pungi import paths, checks
class PungiTestCase(unittest.TestCase):
@ -46,7 +46,8 @@ class DummyCompose(object):
),
)
self.topdir = topdir
self.conf = config
self.conf = load_config(PKGSET_REPOS, **config)
checks.validate(self.conf)
self.paths = paths.Paths(self)
self._logger = mock.Mock()
self.variants = {
@ -106,13 +107,32 @@ def copy_fixture(fixture_name, dest):
shutil.copy2(src, dest)
def union(*args):
"""Create a new dict as a union of all arguments."""
res = {}
for arg in args:
res.update(arg)
return res
def boom(*args, **kwargs):
raise Exception('BOOM')
PKGSET_REPOS = dict(
pkgset_source='repos',
pkgset_repos={},
)
BASE_CONFIG = dict(
release_short='test',
release_name='Test',
release_version='1.0',
release_is_layered=False,
variants_file='variants.xml',
runroot=False,
createrepo_checksum='sha256',
gather_method='deps',
gather_source='none',
sigkeys=[],
)
def load_config(data={}, **kwargs):
conf = dict()
conf.update(BASE_CONFIG)
conf.update(data)
conf.update(kwargs)
return conf