init: Warn when variants mentions non-existing comps group

When variants XML lists a group that does not match any known group in
input comps, report a warning. This is not necessarily a problem in
itself, but having this information in the log can help debug problems.

Relates: #585
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-03-31 08:44:18 +02:00
parent 621f1e2247
commit b5efb67ff1
3 changed files with 47 additions and 3 deletions

View File

@ -100,6 +100,9 @@ def write_arch_comps(compose, arch):
compose.paths.work.comps(arch="global")]) compose.paths.work.comps(arch="global")])
UNMATCHED_GROUP_MSG = 'Variant %s.%s requires comps group %s which does not match anything in input comps file'
def write_variant_comps(compose, arch, variant): def write_variant_comps(compose, arch, variant):
comps_file = compose.paths.work.comps(arch=arch, variant=variant) comps_file = compose.paths.work.comps(arch=arch, variant=variant)
msg = "Writing comps file (arch: %s, variant: %s): %s" % (arch, variant, comps_file) msg = "Writing comps file (arch: %s, variant: %s): %s" % (arch, variant, comps_file)
@ -121,7 +124,9 @@ def write_variant_comps(compose, arch, variant):
"--output=%s" % comps_file, compose.paths.work.comps(arch="global")]) "--output=%s" % comps_file, compose.paths.work.comps(arch="global")])
comps = CompsWrapper(comps_file) comps = CompsWrapper(comps_file)
comps.filter_groups(variant.groups) unmatched = comps.filter_groups(variant.groups)
for grp in unmatched:
compose.log_warning(UNMATCHED_GROUP_MSG % (variant.uid, arch, grp))
if compose.conf["comps_filter_environments"]: if compose.conf["comps_filter_environments"]:
comps.filter_environments(variant.environments) comps.filter_environments(variant.environments)
comps.write_comps() comps.write_comps()

View File

@ -333,6 +333,17 @@ class CompsWrapper(object):
if key in to_remove: if key in to_remove:
del self.comps._groups[key] del self.comps._groups[key]
# Sanity check to report warnings on unused group_dicts
unmatched = set()
for group_dict in group_dicts:
matcher = fnmatch.fnmatch if group_dict["glob"] else lambda x, y: x == y
for group_obj in self.comps.groups:
if matcher(group_obj.groupid, group_dict["name"]):
break
else:
unmatched.add(group_dict["name"])
return unmatched
def filter_packages(self, pkglist): def filter_packages(self, pkglist):
rv = [] rv = []
for group_obj in self.comps.get_groups(): for group_obj in self.comps.get_groups():

View File

@ -201,6 +201,8 @@ class TestWriteVariantComps(PungiTestCase):
compose = DummyCompose(self.topdir, {}) compose = DummyCompose(self.topdir, {})
compose.DEBUG = False compose.DEBUG = False
variant = compose.variants['Server'] variant = compose.variants['Server']
comps = CompsWrapper.return_value
comps.filter_groups.return_value = []
init.write_variant_comps(compose, 'x86_64', variant) init.write_variant_comps(compose, 'x86_64', variant)
@ -211,12 +213,38 @@ class TestWriteVariantComps(PungiTestCase):
self.topdir + '/work/global/comps/comps-global.xml'])]) self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list, self.assertEqual(CompsWrapper.call_args_list,
[mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) [mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')])
comps = CompsWrapper.return_value self.assertEqual(comps.filter_groups.call_args_list, [mock.call(variant.groups)])
self.assertEqual(comps.filter_groups.mock_calls, [mock.call(variant.groups)])
self.assertEqual(comps.filter_environments.mock_calls, self.assertEqual(comps.filter_environments.mock_calls,
[mock.call(variant.environments)]) [mock.call(variant.environments)])
self.assertEqual(comps.write_comps.mock_calls, [mock.call()]) self.assertEqual(comps.write_comps.mock_calls, [mock.call()])
@mock.patch('pungi.phases.init.run')
@mock.patch('pungi.phases.init.CompsWrapper')
def test_run_report_unmatched(self, CompsWrapper, run):
compose = DummyCompose(self.topdir, {})
compose.DEBUG = False
variant = compose.variants['Server']
comps = CompsWrapper.return_value
comps.filter_groups.return_value = ['foo', 'bar']
init.write_variant_comps(compose, 'x86_64', variant)
self.assertEqual(run.mock_calls,
[mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts',
'--keep-empty-group=conflicts-server',
'--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list,
[mock.call(self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')])
self.assertEqual(comps.filter_groups.call_args_list, [mock.call(variant.groups)])
self.assertEqual(comps.filter_environments.mock_calls,
[mock.call(variant.environments)])
self.assertEqual(comps.write_comps.mock_calls, [mock.call()])
self.assertEqual(
compose.log_warning.call_args_list,
[mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'foo')),
mock.call(init.UNMATCHED_GROUP_MSG % ('Server', 'x86_64', 'bar'))])
@mock.patch('pungi.phases.init.run') @mock.patch('pungi.phases.init.run')
@mock.patch('pungi.phases.init.CompsWrapper') @mock.patch('pungi.phases.init.CompsWrapper')
def test_run_in_debug(self, CompsWrapper, run): def test_run_in_debug(self, CompsWrapper, run):