From b5efb67ff195b1f8c4ff7f7e0ac769a9a79e991e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 31 Mar 2017 08:44:18 +0200 Subject: [PATCH] init: Warn when variants mentions non-existing comps group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pungi/phases/init.py | 7 ++++++- pungi/wrappers/comps.py | 11 +++++++++++ tests/test_initphase.py | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/pungi/phases/init.py b/pungi/phases/init.py index 1b5c2d5f..cbda4949 100644 --- a/pungi/phases/init.py +++ b/pungi/phases/init.py @@ -100,6 +100,9 @@ def write_arch_comps(compose, arch): 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): comps_file = compose.paths.work.comps(arch=arch, variant=variant) 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")]) 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"]: comps.filter_environments(variant.environments) comps.write_comps() diff --git a/pungi/wrappers/comps.py b/pungi/wrappers/comps.py index 165bda3b..6ce0c22f 100644 --- a/pungi/wrappers/comps.py +++ b/pungi/wrappers/comps.py @@ -333,6 +333,17 @@ class CompsWrapper(object): if key in to_remove: 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): rv = [] for group_obj in self.comps.get_groups(): diff --git a/tests/test_initphase.py b/tests/test_initphase.py index c5faf258..95bd6f45 100644 --- a/tests/test_initphase.py +++ b/tests/test_initphase.py @@ -201,6 +201,8 @@ class TestWriteVariantComps(PungiTestCase): compose = DummyCompose(self.topdir, {}) compose.DEBUG = False variant = compose.variants['Server'] + comps = CompsWrapper.return_value + comps.filter_groups.return_value = [] init.write_variant_comps(compose, 'x86_64', variant) @@ -211,12 +213,38 @@ class TestWriteVariantComps(PungiTestCase): 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')]) - comps = CompsWrapper.return_value - self.assertEqual(comps.filter_groups.mock_calls, [mock.call(variant.groups)]) + 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()]) + @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.CompsWrapper') def test_run_in_debug(self, CompsWrapper, run):