gather: Relax validations on variant_as_lookaside

Instead of validating both variants exist, let's just check the
existence of only the variant that is being used as a lookaside.

If the configuration says Foo depends on Bar, the error is reported only
if Foo exists but Bar does not. Any other situation is silently ignored.

JIRA: COMPOSE-3393
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-05-20 10:02:36 +02:00
parent cbe8457377
commit 283bae11da
2 changed files with 34 additions and 4 deletions

View File

@ -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))

View File

@ -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):