2016-04-01 07:26:41 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import argparse
|
2017-08-03 12:42:40 +00:00
|
|
|
import json
|
2016-04-01 07:26:41 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2017-09-07 13:54:56 +00:00
|
|
|
import six
|
|
|
|
|
2016-04-01 07:26:41 +00:00
|
|
|
here = sys.path[0]
|
|
|
|
if here != '/usr/bin':
|
|
|
|
# Git checkout
|
|
|
|
sys.path[0] = os.path.dirname(here)
|
|
|
|
|
2016-08-22 14:08:25 +00:00
|
|
|
import pungi.checks
|
2017-09-07 13:54:56 +00:00
|
|
|
import pungi.compose
|
2016-08-11 08:21:35 +00:00
|
|
|
import pungi.paths
|
2016-08-22 14:08:25 +00:00
|
|
|
import pungi.phases
|
2017-09-07 13:54:56 +00:00
|
|
|
import pungi.wrappers.scm
|
2017-02-17 12:44:11 +00:00
|
|
|
import pungi.util
|
2018-06-12 10:48:58 +00:00
|
|
|
from pungi.wrappers.variants import VariantsXmlParser, VariantsValidationError
|
2019-06-21 07:44:48 +00:00
|
|
|
from pungi_utils import config_utils
|
2016-04-01 07:26:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ValidationCompose(pungi.compose.Compose):
|
2016-08-11 08:21:35 +00:00
|
|
|
def __init__(self, conf, has_old, topdir):
|
|
|
|
self.topdir = topdir
|
2016-04-01 07:26:41 +00:00
|
|
|
self.conf = conf
|
|
|
|
self._logger = None
|
|
|
|
self.just_phases = []
|
|
|
|
self.skip_phases = []
|
|
|
|
self.has_old_composes = has_old
|
2016-08-11 08:21:35 +00:00
|
|
|
self.paths = pungi.paths.Paths(self)
|
2017-09-07 13:54:56 +00:00
|
|
|
self.variants = {}
|
2019-06-20 11:59:07 +00:00
|
|
|
self.all_variants = {}
|
2016-04-01 07:26:41 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def old_composes(self):
|
|
|
|
return '/dummy' if self.has_old_composes else None
|
|
|
|
|
2016-08-11 08:21:35 +00:00
|
|
|
@property
|
|
|
|
def compose_id(self):
|
|
|
|
return 'Dummy-1.0-20160811.t.0'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def compose_type(self):
|
|
|
|
return 'test'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def compose_date(self):
|
|
|
|
return '20160811'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def compose_respin(self):
|
|
|
|
return '0'
|
|
|
|
|
2016-04-01 07:26:41 +00:00
|
|
|
|
2017-09-07 13:54:56 +00:00
|
|
|
def read_variants(compose, config):
|
|
|
|
with pungi.util.temp_dir() as tmp_dir:
|
|
|
|
scm_dict = compose.conf["variants_file"]
|
|
|
|
if isinstance(scm_dict, six.string_types) and scm_dict[0] != '/':
|
|
|
|
config_dir = os.path.dirname(config)
|
|
|
|
scm_dict = os.path.join(config_dir, scm_dict)
|
|
|
|
files = pungi.wrappers.scm.get_file_from_scm(scm_dict, tmp_dir)
|
|
|
|
tree_arches = compose.conf.get("tree_arches")
|
|
|
|
tree_variants = compose.conf.get("tree_variants")
|
|
|
|
with open(os.path.join(tmp_dir, files[0]), "r") as file_obj:
|
|
|
|
parser = VariantsXmlParser(file_obj, tree_arches, tree_variants)
|
|
|
|
compose.variants = parser.parse()
|
|
|
|
|
2018-04-20 07:07:18 +00:00
|
|
|
for variant in compose.variants.values():
|
|
|
|
compose.all_variants[variant.uid] = variant
|
|
|
|
for child in variant.get_variants():
|
|
|
|
compose.all_variants[child.uid] = child
|
|
|
|
|
2017-09-07 13:54:56 +00:00
|
|
|
|
2019-06-21 07:44:48 +00:00
|
|
|
def run(config, topdir, has_old, offline, defined_variables):
|
|
|
|
# Load default values for undefined variables. This is useful for
|
|
|
|
# validating templates that are supposed to be filled in later with
|
|
|
|
# pungi-config-dump.
|
|
|
|
try:
|
|
|
|
defaults_file = os.path.join(
|
|
|
|
os.path.dirname(config), ".pungi-config-validate.json"
|
|
|
|
)
|
|
|
|
with open(defaults_file) as f:
|
|
|
|
defined_variables.update(json.load(f))
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
# Load actual configuration
|
|
|
|
conf = pungi.util.load_config(config, defined_variables)
|
|
|
|
# Remove the dummy variables used for defaults.
|
2019-06-25 13:13:16 +00:00
|
|
|
config_utils.remove_unknown(conf, defined_variables)
|
2016-04-01 07:26:41 +00:00
|
|
|
|
2018-11-21 09:56:22 +00:00
|
|
|
errors, warnings = pungi.checks.validate(conf, offline=offline)
|
2016-10-20 08:49:28 +00:00
|
|
|
if errors or warnings:
|
|
|
|
for error in errors + warnings:
|
2016-08-22 14:08:25 +00:00
|
|
|
print(error)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-06-12 10:48:58 +00:00
|
|
|
errors = []
|
2016-08-11 08:21:35 +00:00
|
|
|
compose = ValidationCompose(conf, has_old, topdir)
|
2017-09-07 13:54:56 +00:00
|
|
|
try:
|
|
|
|
read_variants(compose, config)
|
2018-06-12 10:48:58 +00:00
|
|
|
except VariantsValidationError as exc:
|
|
|
|
errors.extend(str(exc).splitlines())
|
2019-06-20 11:59:07 +00:00
|
|
|
except RuntimeError as exc:
|
|
|
|
print("WARNING: Failed to load variants: %s" % exc)
|
2016-04-01 07:26:41 +00:00
|
|
|
|
|
|
|
pkgset_phase = pungi.phases.PkgsetPhase(compose)
|
2018-05-04 06:41:23 +00:00
|
|
|
buildinstall_phase = pungi.phases.BuildinstallPhase(compose)
|
2016-04-01 07:26:41 +00:00
|
|
|
phases = [
|
|
|
|
pungi.phases.InitPhase(compose),
|
2018-05-04 06:41:23 +00:00
|
|
|
buildinstall_phase,
|
2016-04-01 07:26:41 +00:00
|
|
|
pkgset_phase,
|
|
|
|
pungi.phases.GatherPhase(compose, pkgset_phase),
|
|
|
|
pungi.phases.ExtraFilesPhase(compose, pkgset_phase),
|
|
|
|
pungi.phases.CreaterepoPhase(compose),
|
2018-05-07 08:47:48 +00:00
|
|
|
pungi.phases.OstreeInstallerPhase(compose, buildinstall_phase),
|
2016-04-01 07:26:41 +00:00
|
|
|
pungi.phases.OSTreePhase(compose),
|
|
|
|
pungi.phases.ProductimgPhase(compose, pkgset_phase),
|
2018-05-04 06:41:23 +00:00
|
|
|
pungi.phases.CreateisoPhase(compose, buildinstall_phase),
|
2018-05-09 13:39:36 +00:00
|
|
|
pungi.phases.ExtraIsosPhase(compose),
|
2016-04-01 07:26:41 +00:00
|
|
|
pungi.phases.LiveImagesPhase(compose),
|
|
|
|
pungi.phases.LiveMediaPhase(compose),
|
|
|
|
pungi.phases.ImageBuildPhase(compose),
|
|
|
|
pungi.phases.ImageChecksumPhase(compose),
|
|
|
|
pungi.phases.TestPhase(compose),
|
|
|
|
]
|
|
|
|
|
|
|
|
for phase in phases:
|
|
|
|
if phase.skip():
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
phase.validate()
|
|
|
|
except ValueError as ex:
|
|
|
|
for i in str(ex).splitlines():
|
|
|
|
errors.append("%s: %s" % (phase.name.upper(), i))
|
|
|
|
|
|
|
|
return errors
|
|
|
|
|
|
|
|
|
2017-08-03 12:42:40 +00:00
|
|
|
class DumpSchemaAction(argparse.Action):
|
|
|
|
def __call__(self, parser, ns, values, option_string=None):
|
|
|
|
json.dump(pungi.checks.make_schema(), sys.stdout,
|
|
|
|
sort_keys=True, indent=4)
|
|
|
|
print('')
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
2016-04-01 07:26:41 +00:00
|
|
|
def main(args=None):
|
|
|
|
parser = argparse.ArgumentParser()
|
2017-08-03 12:42:40 +00:00
|
|
|
parser.add_argument('--dump-schema', nargs=0, action=DumpSchemaAction,
|
|
|
|
help='print JSON Schema of configuration and exit')
|
2016-04-01 07:26:41 +00:00
|
|
|
parser.add_argument('config', metavar='CONFIG',
|
|
|
|
help='configuration file to validate')
|
|
|
|
parser.add_argument('--old-composes', action='store_true',
|
|
|
|
help='indicate if pungi-koji will be run with --old-composes option')
|
2018-11-21 09:56:22 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--offline",
|
|
|
|
action="store_true",
|
|
|
|
help="Do not validate git references in URLs",
|
|
|
|
)
|
2019-06-21 07:44:48 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-e",
|
|
|
|
"--define",
|
|
|
|
action="append",
|
|
|
|
default=[],
|
|
|
|
metavar="VAR=VALUE",
|
|
|
|
type=config_utils.validate_definition,
|
|
|
|
help=(
|
|
|
|
"Define a variable on command line and inject it into the config file. "
|
|
|
|
"Can be used multiple times."
|
|
|
|
),
|
|
|
|
)
|
2016-04-01 07:26:41 +00:00
|
|
|
opts = parser.parse_args(args)
|
2019-06-21 07:44:48 +00:00
|
|
|
defines = config_utils.extract_defines(opts.define)
|
2016-04-01 07:26:41 +00:00
|
|
|
|
2017-02-17 12:44:11 +00:00
|
|
|
with pungi.util.temp_dir() as topdir:
|
2019-06-21 07:44:48 +00:00
|
|
|
errors = run(opts.config, topdir, opts.old_composes, opts.offline, defines)
|
2016-04-01 07:26:41 +00:00
|
|
|
|
|
|
|
for msg in errors:
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
return bool(errors)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if main():
|
|
|
|
sys.exit(1)
|