def test_resolve_requires_siblings(self, require_platform_and_default_arch): resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="db") mmd = load_mmd(tests.read_staged_data("formatted_testmodule")) for i in range(3): build = tests.module_build_from_modulemd(mmd_to_str(mmd)) build.context = "f6e2ae" + str(i) build.build_context = "f6e2aeec7576196241b9afa0b6b22acf2b6873d" + str( i) build.runtime_context = "bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c" + str( i) build.state = models.BUILD_STATES["ready"] db_session.add(build) db_session.commit() build_one = ModuleBuild.get_by_id(db_session, 2) nsvc = ":".join([ build_one.name, build_one.stream, build_one.version, build_one.context ]) result = resolver.resolve_requires([nsvc]) assert result == { "testmodule": { "stream": build_one.stream, "version": build_one.version, "context": build_one.context, "ref": "65a7721ee4eff44d2a63fb8f3a8da6e944ab7f4d", "koji_tag": None } } db_session.commit()
def init_basic(self, db_session, get_build_arches, hcwbmr, rscm, mocked_scm, built_rpms): FakeSCM( mocked_scm, "testmodule", "testmodule_init.yaml", "620ec77321b2ea7b0d67d82992dda3e1d67055b4", ) built_rpms.return_value = [ "foo-0:2.4.48-3.el8+1308+551bfa71", "foo-debuginfo-0:2.4.48-3.el8+1308+551bfa71", "bar-0:2.5.48-3.el8+1308+551bfa71", "bar-debuginfo-0:2.5.48-3.el8+1308+551bfa71", "x-0:2.5.48-3.el8+1308+551bfa71", "x-debuginfo-0:2.5.48-3.el8+1308+551bfa71", ] platform_build = ModuleBuild.get_by_id(db_session, 1) mmd = platform_build.mmd() for rpm in mmd.get_rpm_filters(): mmd.remove_rpm_filter(rpm) mmd.add_rpm_filter("foo") mmd.add_rpm_filter("bar") platform_build.modulemd = mmd_to_str(mmd) db_session.commit() self.fn(msg_id="msg-id-1", module_build_id=2, module_build_state="init") build = ModuleBuild.get_by_id(db_session, 2) # Make sure the module entered the wait state assert build.state == 1, build.state # Make sure format_mmd was run properly xmd_mbs = build.mmd().get_xmd()["mbs"] assert xmd_mbs["buildrequires"]["platform"]["filtered_rpms"] == [ "foo-0:2.4.48-3.el8+1308+551bfa71", "bar-0:2.5.48-3.el8+1308+551bfa71", ] hcwbmr.assert_called_once() return build
def test_set_cg_build_koji_tag( self, cfg, generic_resolver, resolver, create_builder, dbg, koji_cg_tag_build, expected_cg_koji_build_tag, ): """ Test that build.cg_build_koji_tag is set. """ base_mmd = Modulemd.ModuleStreamV2.new("base-runtime", "f27") koji_session = mock.MagicMock() koji_session.newRepo.return_value = 123456 builder = mock.MagicMock() builder.koji_session = koji_session builder.module_build_tag = {"name": "module-123-build"} builder.get_disttag_srpm.return_value = "some srpm disttag" builder.build.return_value = ( 1234, koji.BUILD_STATES["BUILDING"], "", "module-build-macros-1-1", ) create_builder.return_value = builder resolver = mock.MagicMock() resolver.backend = "db" resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357" resolver.get_module_build_dependencies.return_value = { "module-bootstrap-tag": [base_mmd] } with patch.object( module_build_service.scheduler.handlers.modules.conf, "koji_cg_tag_build", new=koji_cg_tag_build, ): generic_resolver.create.return_value = resolver module_build_service.scheduler.handlers.modules.wait( msg_id="msg-id-1", module_build_id=2, module_build_state="some state") module_build = ModuleBuild.get_by_id(db_session, 2) assert module_build.cg_build_koji_tag == expected_cg_koji_build_tag
def test_init_scm_not_available(self, get_build_arches, mocked_scm): FakeSCM( mocked_scm, "testmodule", "testmodule.yaml", "620ec77321b2ea7b0d67d82992dda3e1d67055b4", get_latest_raise=True, get_latest_error=RuntimeError("Failed in mocked_scm_get_latest")) self.fn(msg_id="msg-id-1", module_build_id=2, module_build_state="init") build = ModuleBuild.get_by_id(db_session, 2) # Make sure the module entered the failed state # since the git server is not available assert build.state == 4, build.state
def test_init_includedmodule(self, get_build_arches, mocked_scm, mocked_mod_allow_repo): FakeSCM(mocked_scm, "includedmodules", ["testmodule_init.yaml"]) includedmodules_yml_path = read_staged_data("includedmodules") mmd = load_mmd(includedmodules_yml_path) # Set the name and stream mmd = mmd.copy("includedmodules", "1") scmurl = "git://pkgs.domain.local/modules/includedmodule?#da95886" ModuleBuild.create(db_session, conf, "includemodule", "1", 3, mmd_to_str(mmd), scmurl, "mprahl") self.fn(msg_id="msg-id-1", module_build_id=3, module_build_state="init") build = ModuleBuild.get_by_id(db_session, 3) assert build.state == 1 assert build.name == "includemodule" batches = {} for comp_build in build.component_builds: batches[comp_build.package] = comp_build.batch assert batches["perl-List-Compare"] == 2 assert batches["perl-Tangerine"] == 2 assert batches["foo"] == 2 assert batches["tangerine"] == 3 assert batches["file"] == 4 # Test that the RPMs are properly merged in xmd xmd_rpms = { "perl-List-Compare": { "ref": "4f26aeafdb" }, "perl-Tangerine": { "ref": "4f26aeafdb" }, "tangerine": { "ref": "4f26aeafdb" }, "foo": { "ref": "93dea37599" }, "file": { "ref": "a2740663f8" }, } assert build.mmd().get_xmd()["mbs"]["rpms"] == xmd_rpms
def test_init_when_get_latest_raises(self, get_build_arches, mocked_scm, mocked_from_module_event): FakeSCM( mocked_scm, "testmodule", "testmodule.yaml", "7035bd33614972ac66559ac1fdd019ff6027ad22", get_latest_raise=True, ) build = ModuleBuild.get_by_id(db_session, 2) mocked_from_module_event.return_value = build self.fn(msg_id="msg-id-1", module_build_id=2, module_build_state="init") # Query the database again to make sure the build object is updated db_session.refresh(build) # Make sure the module entered the failed state assert build.state == 4, build.state assert "Failed to get the latest commit for" in build.state_reason
def get_corresponding_module_build(nvr): """Find corresponding module build from database and return :param str nvr: module build NVR. This is the subject_identifier included inside ``greenwave.decision.update`` message. :return: the corresponding module build object. For whatever the reason, if the original module build id cannot be found from the Koji build of ``nvr``, None will be returned. :rtype: :class:`ModuleBuild` or None """ koji_session = get_session(conf, login=False) build_info = koji_session.getBuild(nvr) if build_info is None: return None try: module_build_id = build_info["extra"]["typeinfo"]["module"][ "module_build_service_id"] except KeyError: # If any of the keys is not present, the NVR is not the one for # handling Greenwave event. return None return ModuleBuild.get_by_id(db_session, module_build_id)