def test__get_base_module_mmds_virtual_streams(self, virtual_streams): """Ensure the correct results are returned without duplicates.""" init_data(data_size=1, multiple_stream_versions=True) mmd = load_mmd(read_staged_data("testmodule_v2")) deps = mmd.get_dependencies()[0] new_deps = Modulemd.Dependencies() for stream in deps.get_runtime_streams("platform"): new_deps.add_runtime_stream("platform", stream) new_deps.add_buildtime_stream("platform", "f29.2.0") mmd.remove_dependencies(deps) mmd.add_dependencies(new_deps) make_module_in_db("platform:lp29.1.1:12:c11", virtual_streams=virtual_streams) mmds = get_base_module_mmds(db_session, mmd) if virtual_streams == ["f29"]: expected = { "platform:f29.0.0", "platform:f29.1.0", "platform:f29.2.0", "platform:lp29.1.1" } else: expected = { "platform:f29.0.0", "platform:f29.1.0", "platform:f29.2.0" } # Verify no duplicates were returned before doing set operations assert len(mmds["ready"]) == len(expected) # Verify the expected ones were returned actual = set() for mmd_ in mmds["ready"]: actual.add("{}:{}".format(mmd_.get_module_name(), mmd_.get_stream_name())) assert actual == expected
def test_add_default_modules_request_failed(mock_get_dm): """ Test that an exception is raised when the call to _get_default_modules failed. """ clean_database() make_module_in_db("python:3:12345:1") make_module_in_db("nodejs:11:2345:2") mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform = ModuleBuild.get_build_from_nsvc( db_session, "platform", xmd_brs["platform"]["stream"], xmd_brs["platform"]["version"], xmd_brs["platform"]["context"], ) assert platform platform_mmd = platform.mmd() platform_xmd = mmd.get_xmd() platform_xmd["mbs"]["use_default_modules"] = True platform_mmd.set_xmd(platform_xmd) platform.modulemd = mmd_to_str(platform_mmd) db_session.commit() expected_error = "some error" mock_get_dm.side_effect = ValueError(expected_error) with pytest.raises(ValueError, match=expected_error): default_modules.add_default_modules(mmd)
def test_add_default_modules(mock_get_dm, mock_hc, require_platform_and_default_arch): """ Test that default modules present in the database are added, and the others are ignored. """ mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform = ModuleBuild.get_build_from_nsvc( db_session, "platform", xmd_brs["platform"]["stream"], xmd_brs["platform"]["version"], xmd_brs["platform"]["context"], ) assert platform platform_mmd = platform.mmd() platform_xmd = mmd.get_xmd() platform_xmd["mbs"]["use_default_modules"] = True platform_mmd.set_xmd(platform_xmd) platform.modulemd = mmd_to_str(platform_mmd) dependencies = [{ "requires": { "platform": ["f28"] }, "buildrequires": { "platform": ["f28"] } }] make_module_in_db("python:3:12345:1", base_module=platform, dependencies=dependencies) make_module_in_db("nodejs:11:2345:2", base_module=platform, dependencies=dependencies) db_session.commit() mock_get_dm.return_value = { "nodejs": "11", "python": "3", "ruby": "2.6", } defaults_added = default_modules.add_default_modules(mmd) # Make sure that the default modules were added. ruby:2.6 will be ignored since it's not in # the database assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == { "nodejs", "platform", "python" } mock_get_dm.assert_called_once_with( "f28", "https://pagure.io/releng/fedora-module-defaults.git", ) assert "ursine_rpms" not in mmd.get_xmd()["mbs"] assert defaults_added is True
def test_add_default_modules_compatible_platforms(mock_get_dm): """ Test that default modules built against compatible base module streams are added. """ clean_database(add_platform_module=False) # Create compatible base modules. mmd = load_mmd(read_staged_data("platform")) for stream in ["f27", "f28"]: mmd = mmd.copy("platform", stream) # Set the virtual stream to "fedora" to make these base modules compatible. xmd = mmd.get_xmd() xmd["mbs"]["virtual_streams"] = ["fedora"] xmd["mbs"]["use_default_modules"] = True mmd.set_xmd(xmd) import_mmd(db_session, mmd) mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform_f27 = ModuleBuild.get_build_from_nsvc( db_session, "platform", "f27", "3", "00000000") assert platform_f27 # Create python default module which requires platform:f27 and therefore cannot be used # as default module for platform:f28. dependencies = [ {"requires": {"platform": ["f27"]}, "buildrequires": {"platform": ["f27"]}}] make_module_in_db("python:3:12345:1", base_module=platform_f27, dependencies=dependencies) # Create nodejs default module which requries any platform stream and therefore can be used # as default module for platform:f28. dependencies[0]["requires"]["platform"] = [] make_module_in_db("nodejs:11:2345:2", base_module=platform_f27, dependencies=dependencies) db_session.commit() mock_get_dm.return_value = { "nodejs": "11", "python": "3", "ruby": "2.6", } defaults_added = default_modules.add_default_modules(mmd) # Make sure that the default modules were added. ruby:2.6 will be ignored since it's not in # the database assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"nodejs", "platform"} mock_get_dm.assert_called_once_with( "f28", "https://pagure.io/releng/fedora-module-defaults.git", ) assert defaults_added is True
def test_greenwave_check_gating(self, mock_requests, policies_satisfied): resp_status = 200 policies_content = { "policies": [ { "decision_context": "test_dec_context", "product_versions": ["ver1", "ver3"], "rules": [], "subject_type": "some-module" } ] } responses = [Mock() for i in range(3)] for r in responses: r.status_code = resp_status responses[0].json.return_value = policies_content responses[1].json.return_value = {"policies_satisfied": False} responses[2].json.return_value = {"policies_satisfied": policies_satisfied} mock_requests.get.return_value = responses[0] mock_requests.post.side_effect = responses[1:] fake_build = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": {"platform": ["el8"]}, "buildrequires": {"platform": ["el8"]}, }], ) result = greenwave.check_gating(fake_build) assert result == policies_satisfied
def _build_srpm(self, execute_cmd, mkdtemp): module_build = make_module_in_db( "{name}:{stream}:{version}:{context}".format(**self.module_nsvc), xmd=self.xmd) mkdtemp.return_value = self.tmp_srpm_build_dir return KojiModuleBuilder.get_disttag_srpm("disttag", module_build)
def test_generate_expanded_mmds_static_context(self): """ Tests if generate_expanded_mmds will not change the context of a module if provided with a static one. """ module_deps = [{ "requires": { "gtk": ["1"], "foo": ["1"] }, "buildrequires": { "platform": ["f28"], "gtk": ["1"], "foo": ["1"] }, }] self._generate_default_modules() module_build = make_module_in_db("app:1:0:static", module_deps) mmds = generate_expanded_mmds(db_session, module_build.mmd(), static_context=True) assert type(mmds) is list assert len(mmds) == 1 current_context = mmds[0].get_context() assert current_context == "static"
def test_transform_from_done_to_ready(self, ClientSession, publish): clean_database() # This build should be queried and transformed to ready state module_build = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) module_build.transition(db_session, conf, BUILD_STATES["done"], "Move to done directly for running test.") db_session.commit() # Assert this call below first_publish_call = call( "module.state.change", module_build.json(db_session, show_tasks=False), conf, "mbs", ) ClientSession.return_value.getBuild.return_value = { "extra": { "typeinfo": { "module": { "module_build_service_id": module_build.id } } } } msg = { "msg_id": "msg-id-1", "topic": "org.fedoraproject.prod.greenwave.decision.update", "msg": { "decision_context": "test_dec_context", "policies_satisfied": True, "subject_identifier": "pkg-0.1-1.c1", }, } hub = Mock(config={"validate_signatures": False}) consumer = MBSConsumer(hub) consumer.consume(msg) db_session.add(module_build) # Load module build again to check its state is moved correctly db_session.refresh(module_build) assert BUILD_STATES["ready"] == module_build.state publish.assert_has_calls([ first_publish_call, call("module.state.change", module_build.json(db_session, show_tasks=False), conf, "mbs"), ])
def test_generate_expanded_mmds_static_context_used_mse(self): xmd = { "mbs": {}, "mbs_options": { "contexts": { "context1": { "buildrequires": { "platform": "f28" }, "requires": { "gtk": "-f28" }, } } } } module_build = make_module_in_db("app:1:0:c1", xmd=xmd) with pytest.raises(ValidationError) as ex: generate_mmds_from_static_contexts(module_build.mmd()) err_msg = ex.value.args[0] assert "gtk" in err_msg assert "requires" in err_msg assert "context1" in err_msg assert "-f28" in err_msg
def test_generate_expanded_mmds_buildrequires(self, module_deps, stream_ambigous, expected_xmd, expected_buildrequires): self._generate_default_modules() module_build = make_module_in_db("app:1:0:c1", module_deps) # Check that generate_expanded_mmds raises an exception if stream is ambigous # and also that it does not raise an exception otherwise. if stream_ambigous: with pytest.raises(StreamAmbigous): generate_expanded_mmds(db_session, module_build.mmd(), raise_if_stream_ambigous=True) else: generate_expanded_mmds(db_session, module_build.mmd(), raise_if_stream_ambigous=True) # Check that if stream is ambigous and we define the stream, it does not raise # an exception. if stream_ambigous: default_streams = {} for ns in list(expected_buildrequires)[0]: name, stream = ns.split(":") default_streams[name] = stream generate_expanded_mmds( db_session, module_build.mmd(), raise_if_stream_ambigous=True, default_streams=default_streams, ) mmds = generate_expanded_mmds(db_session, module_build.mmd()) buildrequires_per_mmd_xmd = set() buildrequires_per_mmd_buildrequires = set() for mmd in mmds: xmd = mmd.get_xmd() br_nsvcs = [] for name, detail in xmd["mbs"]["buildrequires"].items(): br_nsvcs.append(":".join([ name, detail["stream"], detail["version"], detail["context"] ])) buildrequires_per_mmd_xmd.add(frozenset(br_nsvcs)) assert len(mmd.get_dependencies()) == 1 buildrequires = set() dep = mmd.get_dependencies()[0] for req_name in dep.get_buildtime_modules(): for req_stream in dep.get_buildtime_streams(req_name): buildrequires.add(":".join([req_name, req_stream])) buildrequires_per_mmd_buildrequires.add(frozenset(buildrequires)) assert buildrequires_per_mmd_xmd == expected_xmd assert buildrequires_per_mmd_buildrequires == expected_buildrequires
def test_generate_expanded_mmds_static_context_no_contexts(self): module_build = make_module_in_db("app:1:0:c1", xmd={ "mbs": {}, "mbs_options": {} }) with pytest.raises(ValidationError): generate_mmds_from_static_contexts(module_build.mmd())
def test_buildroot_add_repos(self, write_config, load_config, patched_open, base_module_repofiles): import_fake_base_module("platform:f29:1:000000") platform = ModuleBuild.get_last_build_in_stream( db_session, "platform", "f29") module_deps = [{ "requires": { "platform": ["f29"] }, "buildrequires": { "platform": ["f29"] }, }] foo = make_module_in_db("foo:1:1:1", module_deps) app = make_module_in_db("app:1:1:1", module_deps) patched_open.side_effect = [ mock.mock_open(read_data="[fake]\nrepofile 1\n").return_value, mock.mock_open(read_data="[fake]\nrepofile 2\n").return_value, mock.mock_open(read_data="[fake]\nrepofile 3\n").return_value, ] builder = MockModuleBuilder(db_session, "user", app, conf, "module-app", []) dependencies = { "repofile://": [platform.mmd()], "repofile:///etc/yum.repos.d/foo.repo": [foo.mmd(), app.mmd()], } builder.buildroot_add_repos(dependencies) assert "repofile 1" in builder.yum_conf assert "repofile 2" in builder.yum_conf assert "repofile 3" in builder.yum_conf assert set(builder.enabled_modules) == {"foo:1", "app:1"}
def test_send_messages_after_several_state_transitions(mock_publish, require_empty_database): """ Ensure all module build state change messages are sent after multiple ModuleBuild.transitions are committed at once """ build = make_module_in_db("testmodule:1:2:c3") build.transition(db_session, conf, models.BUILD_STATES["wait"]) build.transition(db_session, conf, models.BUILD_STATES["done"]) assert 0 == mock_publish.call_count db_session.commit() assert 2 == mock_publish.call_count
def test_greenwave_query_decision(self, mock_requests): resp_status = 200 resp_content = { "applicable_policies": ["osci_compose_modules"], "policies_satisfied": True, "satisfied_requirements": [{ "result_id": 7336633, "testcase": "test-ci.test-module.tier1", "type": "test-result-passed" }, { "result_id": 7336650, "testcase": "test-ci.test-module.tier2", "type": "test-result-passed" }], "summary": "All required tests passed", "unsatisfied_requirements": [] } response = Mock() response.json.return_value = resp_content response.status_code = resp_status mock_requests.post.return_value = response fake_build = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) got_response = greenwave.query_decision(fake_build, prod_version="xxxx-8") assert got_response == resp_content assert json.loads(mock_requests.post.call_args_list[0][1]["data"]) == { "decision_context": "test_dec_context", "product_version": "xxxx-8", "subject_type": "some-module", "subject_identifier": "pkg-0.1-1.c1" } assert mock_requests.post.call_args_list[0][1]["headers"] == { "Content-Type": "application/json" } assert mock_requests.post.call_args_list[0][1]["url"] == \ "https://greenwave.example.local/api/v1.0/decision"
def test_generate_expanded_mmds_requires(self, module_deps, expected): self._generate_default_modules() module_build = make_module_in_db("app:1:0:c1", module_deps) mmds = generate_expanded_mmds(db_session, module_build.mmd()) requires_per_mmd = set() for mmd in mmds: assert len(mmd.get_dependencies()) == 1 mmd_requires = set() dep = mmd.get_dependencies()[0] for req_name in dep.get_runtime_modules(): for req_stream in dep.get_runtime_streams(req_name): mmd_requires.add(":".join([req_name, req_stream])) requires_per_mmd.add(frozenset(mmd_requires)) assert requires_per_mmd == expected
def test_generate_expanded_mmds_context(self): self._generate_default_modules() module_build = make_module_in_db( "app:1:0:c1", [{ "requires": { "gtk": ["1", "2"] }, "buildrequires": { "platform": ["f28"], "gtk": ["1", "2"] }, }], ) mmds = generate_expanded_mmds(db_session, module_build.mmd()) contexts = {mmd.get_context() for mmd in mmds} assert {"e1e005fb", "ce132a1e"} == contexts
def test_generate_expanded_mmds_static_context_missing_requires(self): xmd = { "mbs": {}, "mbs_options": { "contexts": { "context1": { "buildrequires": { "platform": ["f28"] } } } } } module_build = make_module_in_db("app:1:0:c1", xmd=xmd) with pytest.raises(ValidationError): generate_mmds_from_static_contexts(module_build.mmd())
def test_monitor_state_changing_success(succ_cnt, failed_cnt): clean_database(add_platform_module=False, add_default_arches=False) b = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) b.transition(db_session, conf, models.BUILD_STATES["wait"]) b.transition(db_session, conf, models.BUILD_STATES["build"]) b.transition(db_session, conf, models.BUILD_STATES["done"]) db_session.commit() succ_cnt.assert_called_once() failed_cnt.assert_not_called()
def test_poll_greenwave(self, mock_gw, create_builder, dbg, greenwave_result): module_build1 = models.ModuleBuild.get_by_id(db_session, 1) module_build1.state = models.BUILD_STATES["ready"] module_build2 = models.ModuleBuild.get_by_id(db_session, 2) module_build2.state = models.BUILD_STATES["done"] module_build3 = models.ModuleBuild.get_by_id(db_session, 3) module_build3.state = models.BUILD_STATES["init"] module_build4 = make_module_in_db("foo:1:1:1", {}) module_build4.state = models.BUILD_STATES["done"] module_build4.scratch = True db_session.commit() mock_gw.return_value = greenwave_result producer.poll_greenwave() mock_gw.assert_called_once() modules = models.ModuleBuild.by_state(db_session, "ready") if greenwave_result: assert len(modules) == 2 assert {m.id for m in modules} == {1, 2} else: assert len(modules) == 1 assert modules[0].id == 1 modules = models.ModuleBuild.by_state(db_session, "done") assert len(modules) == 2 for module in modules: assert module.id in [2, 4] if module.id == 2: assert re.match("Gating failed.*", module.state_reason) else: assert module.state_reason is None
def test_monitor_state_changing_failure(succ_cnt, failed_cnt, require_empty_database): failure_type = "user" b = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) b.transition(db_session, conf, models.BUILD_STATES["wait"]) b.transition(db_session, conf, models.BUILD_STATES["build"]) b.transition(db_session, conf, models.BUILD_STATES["failed"], failure_type=failure_type) db_session.commit() succ_cnt.assert_not_called() failed_cnt.assert_called_once_with(reason=failure_type)
def test_submit_build_new_mse_build(self, generate_expanded_mmds): """ Tests that finished build can be resubmitted in case the resubmitted build adds new MSE build (it means there are new expanded buildrequires). """ build = make_module_in_db("foo:stream:0:c1") assert build.state == models.BUILD_STATES["ready"] mmd1 = build.mmd() mmd2 = build.mmd() mmd2.set_context("c2") generate_expanded_mmds.return_value = [mmd1, mmd2] # Create a copy of mmd1 without xmd.mbs, since that will cause validate_mmd to fail mmd1_copy = mmd1.copy() mmd1_copy.set_xmd({}) builds = submit_module_build(db_session, "foo", mmd1_copy, {}) ret = {b.mmd().get_context(): b.state for b in builds} assert ret == {"c1": models.BUILD_STATES["ready"], "c2": models.BUILD_STATES["init"]} assert builds[0].siblings(db_session) == [builds[1].id] assert builds[1].siblings(db_session) == [builds[0].id]
def test_get_modulemds(self, ClientSession): koji_session = ClientSession.return_value # Ensure to to get build tag for further query of ursine content. # For this test, the build tag is tag-4-build koji_session.getExternalRepoList.return_value = [{ "external_repo_name": "tag-1.0-external-repo", "url": "http://example.com/repos/tag-4-build/latest/$arch/", }] # Ensure to return module tags from ursine content of fake build tag # specified in above external repo's url. def mock_getFullInheritance(tag): if tag == "tag-4-build": return [ { "name": "tag-1.0-build" }, # Below two modules should be returned and whose modulemd # should be also queried from database. { "name": "module-name1-s-2020-c" }, { "name": "module-name2-s-2021-c" }, ] raise ValueError("{} is not handled by test.".format(tag)) koji_session.getFullInheritance.side_effect = mock_getFullInheritance # Defaults to DB resolver, so create fake module builds and store them # into database to ensure they can be queried. # # Switched to call function make_session to create a # SQLAlchemy database session. Calling db.session causes failure to # read attributes from a ModuleBuild object at following line calling # mmd(). The error is ModuleBuild object is not bound to a Session. # From the behavior of following code, the reason of the error is # mixing use of db.session and make_session, the latter one is called # from function ``get_modulemds_from_ursine_content``. mmd_name1s2020c = make_module_in_db( "name1:s:2020:c", xmd={"mbs": { "koji_tag": "module-name1-s-2020-c" }}, ) mmd_name2s2021c = make_module_in_db( "name2:s:2021:c", xmd={"mbs": { "koji_tag": "module-name2-s-2021-c" }}, ) koji_tag = "tag" # It's ok to use arbitrary tag name. with patch.object(conf, "koji_external_repo_url_prefix", new="http://example.com/"): modulemds = ursine.get_modulemds_from_ursine_content(koji_tag) test_nsvcs = [item.get_nsvc() for item in modulemds] test_nsvcs.sort() expected_nsvcs = [ mmd_name1s2020c.mmd().get_nsvc(), mmd_name2s2021c.mmd().get_nsvc() ] expected_nsvcs.sort() koji_session.getExternalRepoList.assert_called_once_with(koji_tag) assert expected_nsvcs == test_nsvcs
def _generate_default_modules(self): """ Generates gtk:1, gtk:2, foo:1 and foo:2 modules requiring the platform:f28 and platform:f29 modules. """ platform_f28 = make_module_in_db("platform:f28:0:c10") platform_f29 = make_module_in_db("platform:f29:0:c11") f28_deps = [{ "requires": { "platform": ["f28"] }, "buildrequires": { "platform": ["f28"] }, }] f29_deps = [{ "requires": { "platform": ["f29"] }, "buildrequires": { "platform": ["f29"] }, }] make_module_in_db("gtk:1:0:c2", f28_deps, base_module=platform_f28) make_module_in_db("gtk:1:0:c3", f29_deps, base_module=platform_f29) make_module_in_db("gtk:2:0:c4", f28_deps, base_module=platform_f28) make_module_in_db("gtk:2:0:c5", f29_deps, base_module=platform_f29) make_module_in_db("foo:1:0:c2", f28_deps, base_module=platform_f28) make_module_in_db("foo:1:0:c3", f29_deps, base_module=platform_f29) make_module_in_db("foo:2:0:c4", f28_deps, base_module=platform_f28) make_module_in_db("foo:2:0:c5", f29_deps, base_module=platform_f29) make_module_in_db("app:1:0:c6", f29_deps, base_module=platform_f29)
def _generate_default_modules_recursion(self): """ Generates the gtk:1 module requiring foo:1 module requiring bar:1 and lorem:1 modules which require base:f29 module requiring platform:f29 module :). """ base_module = make_module_in_db("platform:f29:0:c11") make_module_in_db("gtk:1:0:c2", [{ "requires": { "foo": ["unknown"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("gtk:1:1:c2", [{ "requires": { "foo": ["1"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("foo:1:0:c2", [{ "requires": { "bar": ["unknown"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("foo:1:1:c2", [{ "requires": { "bar": ["1"], "lorem": ["1"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("bar:1:0:c2", [{ "requires": { "base": ["unknown"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("bar:1:1:c2", [{ "requires": { "base": ["f29"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("lorem:1:0:c2", [{ "requires": { "base": ["unknown"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("lorem:1:1:c2", [{ "requires": { "base": ["f29"] }, "buildrequires": {} }], base_module=base_module) make_module_in_db("base:f29:0:c3", [{ "requires": { "platform": ["f29"] }, "buildrequires": {} }], base_module=base_module)
def _generate_default_modules_modules_multiple_stream_versions(self): """ Generates the gtk:1 module requiring foo:1 module requiring bar:1 and lorem:1 modules which require base:f29 module requiring platform:f29 module :). """ f29_dep = [{ "requires": { "platform": ["f29"] }, "buildrequires": { "platform": ["f29"] } }] f290000 = make_module_in_db("platform:f29.0.0:0:c11", virtual_streams=["f29"]) make_module_in_db("gtk:1:0:c2", f29_dep, base_module=f290000) f290100 = make_module_in_db("platform:f29.1.0:0:c11", virtual_streams=["f29"]) make_module_in_db("gtk:1:1:c2", f29_dep, base_module=f290100) make_module_in_db("gtk:1:2:c2", f29_dep, base_module=f290100) f290200 = make_module_in_db("platform:f29.2.0:0:c11", virtual_streams=["f29"]) make_module_in_db("gtk:1:3:c2", f29_dep, base_module=f290200)
def test_get_required_modules_stream_versions(self, module_deps, expected): module_build = make_module_in_db("app:1:0:c1", module_deps) self._generate_default_modules_modules_multiple_stream_versions() nsvcs = self._get_mmds_required_by_module_recursively( module_build, db_session) assert set(nsvcs) == set(expected)
def test_generate_mmds_from_static_context(self): self._generate_default_modules() module_build = make_module_in_db("app:1:0:c1", dependencies=[{ "requires": { "gtk": ["1", "2"] }, "buildrequires": { "platform": ["f28"], "gtk": ["1", "2"] } }], xmd={ "mbs": {}, "mbs_options": { "contexts": { "context1": { "requires": { "gtk": "1" }, "buildrequires": { "platform": "f28", "gtk": "1", } }, "context2": { "requires": { "gtk": "2" }, "buildrequires": { "platform": "f28", "gtk": "2", }, } } } }) mmds = generate_mmds_from_static_contexts(module_build.mmd()) expected_contexts = ["context1", "context2"] expected_deps = { "context1": { "buildrequires": { "platform": ["f28"], "gtk": ["1"], }, "requires": { "gtk": ["1"], }, }, "context2": { "buildrequires": { "platform": ["f28"], "gtk": ["2"], }, "requires": { "gtk": ["2"], }, }, } assert type(mmds) is list assert len(mmds) == 2 for mmd in mmds: current_context = mmd.get_context() current_xmd = mmd.get_xmd() assert current_context in expected_contexts assert "contexts" not in current_xmd deps = mmd.get_dependencies() assert len(deps) == 1 buildrequires = deps[0].get_buildtime_modules() for module in buildrequires: current_stream = deps[0].get_buildtime_streams(module) assert len(current_stream) == 1 assert expected_deps[current_context]["buildrequires"][ module] == current_stream requires = deps[0].get_runtime_modules() for module in requires: current_stream = deps[0].get_runtime_streams(module) assert len(current_stream) == 1 assert expected_deps[current_context]["requires"][ module] == current_stream
def test_generate_expanded_mmds_static_context_empty_xmd(self): module_build = make_module_in_db("app:1:0:c1", xmd={}) mmd = module_build.mmd() mmd.set_xmd({}) with pytest.raises(ValidationError): generate_mmds_from_static_contexts(mmd)