From 5831d4ae1e98db2366b73238ee79f5cdbc8d6687 Mon Sep 17 00:00:00 2001 From: Dominik Rumian Date: Thu, 12 Aug 2021 11:03:19 +0200 Subject: [PATCH] Better error message than 'KeyError' in pungi Jira: RHELCMP-6107 Signed-off-by: Dominik Rumian --- pungi/phases/gather/__init__.py | 25 ++++++++++++++++--------- tests/test_gather_phase.py | 8 ++++---- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pungi/phases/gather/__init__.py b/pungi/phases/gather/__init__.py index 01a2c5ef..64310259 100644 --- a/pungi/phases/gather/__init__.py +++ b/pungi/phases/gather/__init__.py @@ -36,8 +36,7 @@ from pungi.compose import get_ordered_variant_uids from pungi.module_util import Modulemd, collect_module_defaults from pungi.phases.base import PhaseBase from pungi.phases.createrepo import add_modular_metadata -from pungi.util import (get_arch_data, get_arch_variant_data, get_variant_data, - makedirs) +from pungi.util import get_arch_data, get_arch_variant_data, get_variant_data, makedirs from pungi.wrappers.scm import get_file_from_scm from ...wrappers.createrepo import CreaterepoWrapper @@ -97,11 +96,18 @@ class GatherPhase(PhaseBase): # check whether variants from configuration value # 'variant_as_lookaside' have same architectures for (requiring, required) in variant_as_lookaside: - if requiring in all_variants and required in all_variants and \ - sorted(all_variants[requiring].arches) \ - != sorted(all_variants[required].arches): - errors.append("variant_as_lookaside: variant \'%s\' doesn't have same " - "architectures as \'%s\'" % (requiring, required)) + if ( + requiring in all_variants + and required in all_variants + and not set(all_variants[requiring].arches).issubset( + set(all_variants[required].arches) + ) + ): + errors.append( + "variant_as_lookaside: architectures of variant '%s' " + "aren't subset of architectures of variant '%s'" + % (requiring, required) + ) if errors: raise ValueError("\n".join(errors)) @@ -664,8 +670,9 @@ def _make_lookaside_repo(compose, variant, arch, pkg_map, package_sets=None): pkg = pkg[len(path_prefix) :] package_list.add(pkg) except KeyError: - raise RuntimeError("Variant \'%s\' does not have architecture " - "\'%s\'!" % (variant, pkg_arch)) + raise RuntimeError( + "Variant '%s' does not have architecture " "'%s'!" % (variant, pkg_arch) + ) pkglist = compose.paths.work.lookaside_package_list(arch=arch, variant=variant) with open(pkglist, "w") as f: diff --git a/tests/test_gather_phase.py b/tests/test_gather_phase.py index 71c5a1ea..2725247f 100644 --- a/tests/test_gather_phase.py +++ b/tests/test_gather_phase.py @@ -1582,7 +1582,7 @@ class TestGatherPhase(helpers.PungiTestCase): phase = gather.GatherPhase(compose, pkgset_phase) phase.validate() - def test_validates_variants_architecture_mismatch(self): + def test_validates_variants_requiring_is_not_subset_of_required(self): pkgset_phase = mock.Mock() compose = helpers.DummyCompose( self.topdir, {"variant_as_lookaside": [("Everything", "Client")]} @@ -1590,12 +1590,12 @@ class TestGatherPhase(helpers.PungiTestCase): phase = gather.GatherPhase(compose, pkgset_phase) with self.assertRaises(ValueError) as ctx: phase.validate() - self.assertIn("'Everything' doesn't have", str(ctx.exception)) + self.assertIn("architectures of variant 'Client'", str(ctx.exception)) - def test_validates_variants_architecture_match(self): + def test_validates_variants_requiring_is_subset_of_required(self): pkgset_phase = mock.Mock() compose = helpers.DummyCompose( - self.topdir, {"variant_as_lookaside": [("Everything", "Everything")]} + self.topdir, {"variant_as_lookaside": [("Client", "Everything")]} ) phase = gather.GatherPhase(compose, pkgset_phase) phase.validate()