diff --git a/pungi/phases/gather/__init__.py b/pungi/phases/gather/__init__.py index 58f5919f..3a6a3992 100644 --- a/pungi/phases/gather/__init__.py +++ b/pungi/phases/gather/__init__.py @@ -79,10 +79,13 @@ class GatherPhase(PhaseBase): # check whether variants from configuration value 'variant_as_lookaside' are correct variant_as_lookaside = self.compose.conf.get("variant_as_lookaside", []) - for variant_pair in variant_as_lookaside: - for variant_uid in variant_pair: - if variant_uid not in self.compose.all_variants: - errors.append("Variant uid '%s' does't exists in 'variant_as_lookaside'" % variant_uid) + all_variants = self.compose.all_variants + for (requiring, required) in variant_as_lookaside: + if requiring in all_variants and required not in all_variants: + errors.append( + "variant_as_lookaside: variant %r doesn't exist but is required by %r" + % (required, requiring) + ) if errors: raise ValueError('\n'.join(errors)) diff --git a/tests/test_gather_phase.py b/tests/test_gather_phase.py index 122e30ca..e7c3c0b0 100644 --- a/tests/test_gather_phase.py +++ b/tests/test_gather_phase.py @@ -879,6 +879,33 @@ class TestGatherPhase(helpers.PungiTestCase): with open(rpms_file) as fh: self.assertEqual(fh.read(), "hello") + def test_validates_wrong_requiring_variant(self): + pkgset_phase = mock.Mock() + compose = helpers.DummyCompose( + self.topdir, {"variant_as_lookaside": [("foo", "Server")]} + ) + phase = gather.GatherPhase(compose, pkgset_phase) + phase.validate() + + def test_validates_wrong_required_variant(self): + pkgset_phase = mock.Mock() + compose = helpers.DummyCompose( + self.topdir, {"variant_as_lookaside": [("Server", "foo")]} + ) + phase = gather.GatherPhase(compose, pkgset_phase) + with self.assertRaises(ValueError) as ctx: + phase.validate() + + self.assertIn("'foo' doesn't exist", str(ctx.exception)) + + def test_validates_both_requires_missing(self): + pkgset_phase = mock.Mock() + compose = helpers.DummyCompose( + self.topdir, {"variant_as_lookaside": [("foo", "bar")]} + ) + phase = gather.GatherPhase(compose, pkgset_phase) + phase.validate() + class TestGetPackagesToGather(helpers.PungiTestCase): def setUp(self):