2016-08-22 14:08:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2016-09-22 08:28:01 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
from pungi import checks
|
|
|
|
from tests.helpers import load_config, PKGSET_REPOS
|
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class ConfigTestCase(unittest.TestCase):
|
|
|
|
def assertValidation(self, cfg, errors=[], warnings=[]):
|
|
|
|
actual_errors, actual_warnings = checks.validate(cfg)
|
|
|
|
self.assertItemsEqual(errors, actual_errors)
|
|
|
|
self.assertEqual(warnings, actual_warnings)
|
|
|
|
|
|
|
|
|
|
|
|
class PkgsetConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_validate_minimal_pkgset_koji(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='koji',
|
|
|
|
pkgset_koji_tag="f25",
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_validate_minimal_pkgset_repos(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='repos',
|
|
|
|
pkgset_repos={'x86_64': '/first', 'ppc64': '/second'},
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_pkgset_mismatch_repos(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='repos',
|
|
|
|
pkgset_koji_tag='f25',
|
|
|
|
pkgset_koji_inherit=False,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('pkgset_source', 'repos', 'pkgset_repos'),
|
|
|
|
checks.CONFLICTS.format('pkgset_source', 'repos', 'pkgset_koji_tag'),
|
|
|
|
checks.CONFLICTS.format('pkgset_source', 'repos', 'pkgset_koji_inherit')])
|
|
|
|
|
|
|
|
def test_pkgset_mismatch_koji(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='koji',
|
|
|
|
pkgset_repos={'whatever': '/foo'},
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('pkgset_source', 'koji', 'pkgset_koji_tag'),
|
|
|
|
checks.CONFLICTS.format('pkgset_source', 'koji', 'pkgset_repos')])
|
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class ReleaseConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_layered_without_base_product(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
release_is_layered=True
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('release_is_layered', 'True', 'base_product_name'),
|
|
|
|
checks.REQUIRES.format('release_is_layered', 'True', 'base_product_short'),
|
|
|
|
checks.REQUIRES.format('release_is_layered', 'True', 'base_product_version')])
|
|
|
|
|
|
|
|
def test_not_layered_with_base_product(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
base_product_name='Prod',
|
|
|
|
base_product_short='bp',
|
|
|
|
base_product_version='1.0',
|
|
|
|
base_product_type='updates',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.CONFLICTS.format('release_is_layered', 'False', 'base_product_name'),
|
|
|
|
checks.CONFLICTS.format('release_is_layered', 'False', 'base_product_short'),
|
|
|
|
checks.CONFLICTS.format('release_is_layered', 'False', 'base_product_type'),
|
|
|
|
checks.CONFLICTS.format('release_is_layered', 'False', 'base_product_version')])
|
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class RunrootConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_runroot_without_deps(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
runroot=True,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('runroot', 'True', 'koji_profile'),
|
|
|
|
checks.REQUIRES.format('runroot', 'True', 'runroot_tag'),
|
|
|
|
checks.REQUIRES.format('runroot', 'True', 'runroot_channel')])
|
|
|
|
|
|
|
|
def test_koji_settings_without_runroot(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
runroot=False,
|
|
|
|
koji_profile='koji',
|
|
|
|
runroot_tag='f25',
|
|
|
|
runroot_channel='compose',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.CONFLICTS.format('runroot', 'False', 'runroot_tag'),
|
|
|
|
checks.CONFLICTS.format('runroot', 'False', 'runroot_channel')])
|
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class BuildinstallConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_bootable_without_method(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
bootable=True,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
[checks.REQUIRES.format('bootable', 'True', 'buildinstall_method')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_non_bootable_with_method(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
bootable=False,
|
|
|
|
buildinstall_method='lorax',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
[checks.CONFLICTS.format('bootable', 'False', 'buildinstall_method')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_buildinstall_method_without_bootable(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
buildinstall_method='lorax',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
[checks.CONFLICTS.format('bootable', 'False', 'buildinstall_method')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_buildinstall_with_lorax_options(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
bootable=True,
|
|
|
|
buildinstall_method='buildinstall',
|
|
|
|
lorax_options=[('^Server$', {})]
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
[checks.CONFLICTS.format('buildinstall_method', 'buildinstall', 'lorax_options')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_lorax_with_lorax_options(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
bootable=True,
|
|
|
|
buildinstall_method='lorax',
|
|
|
|
lorax_options=[]
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_lorax_options_without_bootable_and_method(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
lorax_options=[('^Server$', {})],
|
|
|
|
buildinstall_kickstart='foo',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.CONFLICTS.format('buildinstall_method', 'None', 'lorax_options'),
|
2016-12-07 14:57:35 +00:00
|
|
|
checks.CONFLICTS.format('buildinstall_method', 'None', 'buildinstall_kickstart')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_deprecated(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
buildinstall_upgrade_image=True,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg, [],
|
2016-10-20 08:49:28 +00:00
|
|
|
[checks.REMOVED.format('buildinstall_upgrade_image', 'use lorax_options instead')]
|
2016-08-22 14:08:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class CreaterepoConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_validate_minimal_pkgset_koji(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='koji',
|
|
|
|
pkgset_koji_tag="f25",
|
|
|
|
product_id_allow_missing=True,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
[checks.CONFLICTS.format('product_id', 'None', 'product_id_allow_missing')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class GatherConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_source_comps_requires_comps(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='koji',
|
|
|
|
pkgset_koji_tag="f25",
|
|
|
|
gather_source='comps',
|
|
|
|
gather_source_mapping='foo'
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('gather_source', 'comps', 'comps_file'),
|
2016-12-07 14:57:35 +00:00
|
|
|
checks.CONFLICTS.format('gather_source', 'comps', 'gather_source_mapping')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_source_json_requires_mapping(self):
|
|
|
|
cfg = load_config(
|
|
|
|
pkgset_source='koji',
|
|
|
|
pkgset_koji_tag="f25",
|
|
|
|
gather_source='json',
|
|
|
|
comps_file='comps',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-08-22 14:08:25 +00:00
|
|
|
[checks.REQUIRES.format('gather_source', 'json', 'gather_source_mapping'),
|
2016-12-07 14:57:35 +00:00
|
|
|
checks.CONFLICTS.format('gather_source', 'json', 'comps_file')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class OSBSConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_validate(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
osbs={"^Server$": {
|
|
|
|
'url': 'http://example.com',
|
|
|
|
'target': 'f25-build',
|
|
|
|
}}
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_validate_bad_conf(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
osbs='yes please'
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertNotEqual(checks.validate(cfg), ([], []))
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class OstreeConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_validate(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
ostree=[
|
|
|
|
("^Atomic$", {
|
|
|
|
"x86_64": {
|
|
|
|
"treefile": "fedora-atomic-docker-host.json",
|
|
|
|
"config_url": "https://git.fedorahosted.org/git/fedora-atomic.git",
|
|
|
|
"source_repo_from": "Everything",
|
|
|
|
"ostree_repo": "/mnt/koji/compose/atomic/Rawhide/"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_validate_bad_conf(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
ostree='yes please'
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertNotEqual(checks.validate(cfg), ([], []))
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class OstreeInstallerConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_validate(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
ostree_installer=[
|
|
|
|
("^Atomic$", {
|
|
|
|
"x86_64": {
|
|
|
|
"source_repo_from": "Everything",
|
|
|
|
"release": None,
|
|
|
|
"installpkgs": ["fedora-productimg-atomic"],
|
|
|
|
"add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"],
|
|
|
|
"add_template_var": [
|
|
|
|
"ostree_osname=fedora-atomic",
|
|
|
|
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
|
|
|
|
],
|
|
|
|
"add_arch_template": ["/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl"],
|
2016-11-17 15:15:03 +00:00
|
|
|
"rootfs_size": "3",
|
2016-08-22 14:08:25 +00:00
|
|
|
"add_arch_template_var": [
|
|
|
|
"ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/",
|
|
|
|
"ostree_osname=fedora-atomic",
|
|
|
|
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_validate_bad_conf(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
ostree_installer=[
|
|
|
|
("^Atomic$", {
|
|
|
|
"x86_64": {
|
|
|
|
"source_repo_from": "Everything",
|
|
|
|
"release": None,
|
|
|
|
"installpkgs": ["fedora-productimg-atomic"],
|
|
|
|
"add_template": ["/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl"],
|
|
|
|
"add_template_var": [
|
|
|
|
"ostree_osname=fedora-atomic",
|
|
|
|
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
|
|
|
|
],
|
|
|
|
"add_arch_template": 15,
|
|
|
|
"add_arch_template_var": [
|
|
|
|
"ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/",
|
|
|
|
"ostree_osname=fedora-atomic",
|
|
|
|
"ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertNotEqual(checks.validate(cfg), ([], []))
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class LiveMediaConfigTestCase(ConfigTestCase):
|
2016-08-22 14:08:25 +00:00
|
|
|
def test_global_config_validation(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
live_media_ksurl='git://example.com/repo.git#HEAD',
|
|
|
|
live_media_target='f24',
|
|
|
|
live_media_release='RRR',
|
|
|
|
live_media_version='Rawhide',
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
def test_global_config_null_release(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
live_media_release=None,
|
|
|
|
)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg)
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class TestSuggestions(ConfigTestCase):
|
2016-08-19 08:09:40 +00:00
|
|
|
def test_with_a_typo(self):
|
2016-08-22 14:08:25 +00:00
|
|
|
cfg = load_config(PKGSET_REPOS,
|
|
|
|
product_pid=None)
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(cfg, [], [checks.UNKNOWN_SUGGEST.format('product_pid', 'product_id')])
|
2016-08-22 14:08:25 +00:00
|
|
|
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
class TestRegexValidation(ConfigTestCase):
|
2016-10-12 07:38:59 +00:00
|
|
|
def test_incorrect_regular_expression(self):
|
|
|
|
cfg = load_config(PKGSET_REPOS,
|
|
|
|
multilib=[('^*$', {'*': []})])
|
|
|
|
|
2016-12-07 14:57:35 +00:00
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
2016-10-12 07:38:59 +00:00
|
|
|
['Failed validation in multilib.0.0: incorrect regular '
|
2016-12-07 14:57:35 +00:00
|
|
|
'expression: nothing to repeat'],
|
|
|
|
[])
|
2016-10-12 07:38:59 +00:00
|
|
|
|
|
|
|
|
2017-01-26 08:19:12 +00:00
|
|
|
class RepoclosureTestCase(ConfigTestCase):
|
|
|
|
def test_invalid_backend(self):
|
|
|
|
cfg = load_config(
|
|
|
|
PKGSET_REPOS,
|
|
|
|
repoclosure_backend='fnd', # Intentionally with a typo
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertValidation(
|
|
|
|
cfg,
|
|
|
|
["Failed validation in repoclosure_backend: 'fnd' is not one of ['yum', 'dnf']"])
|
|
|
|
|
|
|
|
|
2016-08-22 14:08:25 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|