From 6b496dfde4655925e68311833d7766c88eaea0d5 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Oct 25 2018 14:01:36 +0000 Subject: Add tests for "Conflicts: module(name)" in MMDResolver. The test tests installation of multiple streams of single module. For example: - "app:1" requires "foo:1" and "gtk:1". - "foo:1" requires "bar:1". - "gtk:1" requires "bar:2". "bar:1" and "bar:2" cannot be installed in the same time and therefore there need to be conflict defined between them. --- diff --git a/module_build_service/mmd_resolver.py b/module_build_service/mmd_resolver.py index 536819a..9ed8a2b 100644 --- a/module_build_service/mmd_resolver.py +++ b/module_build_service/mmd_resolver.py @@ -332,7 +332,14 @@ class MMDResolver(object): log.debug("Adding module %s with requires: %r", solvable.name, requires) solvable.add_deparray(solv.SOLVABLE_REQUIRES, requires) - # Add "Conflicts: module(name)", because TODO, ask ignatenko. + # Add "Conflicts: module(name)". + # This is needed to prevent installation of multiple streams of single module. + # For example: + # - "app:1" requires "foo:1" and "gtk:1". + # - "foo:1" requires "bar:1". + # - "gtk:1" requires "bar:2". + # "bar:1" and "bar:2" cannot be installed in the same time and therefore + # there need to be conflict defined between them. solvable.add_deparray(solv.SOLVABLE_CONFLICTS, pool.Dep("module(%s)" % n)) solvables.append(solvable) diff --git a/tests/test_mmd_resolver.py b/tests/test_mmd_resolver.py index 58902e7..4c32457 100644 --- a/tests/test_mmd_resolver.py +++ b/tests/test_mmd_resolver.py @@ -260,3 +260,23 @@ class TestMMDResolver: for e in exp) assert expanded == expected + + def test_solve_stream_conflicts(self): + # app requires both gtk:1 and foo:1. + # gtk:1 requires bar:1 + # foo:1 requires bar:2. + # We cannot install both bar:1 and bar:2 in the same time. + # Therefore the solving should fail. + modules = ( + ("platform:f29:0:c0", {}), + ('gtk:1:1:c2', {'bar': ['1']}), + ('foo:1:1:c2', {'bar': ['2']}), + ('bar:1:0:c2', {'platform': ['f29']}), + ('bar:2:0:c2', {'platform': ['f29']}), + ) + for n, req in modules: + self.mmd_resolver.add_modules(self._make_mmd(n, req)) + + app = self._make_mmd("app:1:0", {'gtk': '1', 'foo': '1'}) + with pytest.raises(RuntimeError): + self.mmd_resolver.solve(app)