Esempio n. 1
0
    def test_get_reusable_component_different_arches(self, set_database_arch,
                                                     set_current_arch):
        second_module_build = models.ModuleBuild.get_by_id(db_session, 3)

        if set_current_arch:  # set architecture for current build
            mmd = second_module_build.mmd()
            component = mmd.get_rpm_component("tangerine")
            component.reset_arches()
            component.add_restricted_arch("i686")
            second_module_build.modulemd = mmd_to_str(mmd)
            db_session.commit()

        if set_database_arch:  # set architecture for build in database
            second_module_changed_component = models.ComponentBuild.from_component_name(
                db_session, "tangerine", 2)
            mmd = second_module_changed_component.module_build.mmd()
            component = mmd.get_rpm_component("tangerine")
            component.reset_arches()
            component.add_restricted_arch("i686")
            second_module_changed_component.module_build.modulemd = mmd_to_str(
                mmd)
            db_session.commit()

        tangerine = get_reusable_component(second_module_build, "tangerine")
        assert bool(tangerine is None) != bool(
            set_current_arch == set_database_arch)
    def _add_test_rpm(
        self,
        nevra,
        srpm_nevra,
        multilib=None,
        koji_srpm_nevra=None,
        excludearch=None,
        exclusivearch=None,
        license=None,
    ):
        """
        Helper method to add test RPM to ModuleBuild used by KojiContentGenerator
        and also to Koji tag used to generate the Content Generator build.

        :param str nevra: NEVRA of the RPM to add.
        :param str srpm_nevra: NEVRA of SRPM the added RPM is built from.
        :param list multilib: List of architecture for which the multilib should be turned on.
        :param str koji_srpm_nevra: If set, overrides the `srpm_nevra` in Koji tag. This is
            needed to test the case when the built "src" package has different name than
            the package in Koji. This is for example case of software collections where
            the name in `srpm_nevra` is "httpd" but `koji_srpm_nevra` name
            would be "httpd24-httpd".
        :param list excludearch: List of architectures this package is excluded from.
        :param list exclusivearch: List of architectures this package is exclusive for.
        :param str license: License of this RPM.
        """
        srpm_name = kobo.rpmlib.parse_nvra(srpm_nevra)["name"]

        parsed_nevra = kobo.rpmlib.parse_nvra(nevra)
        parsed_nevra["payloadhash"] = "hash"
        if koji_srpm_nevra:
            parsed_nevra["srpm_nevra"] = koji_srpm_nevra
            parsed_nevra["srpm_name"] = kobo.rpmlib.parse_nvra(
                koji_srpm_nevra)["name"]
        else:
            parsed_nevra["srpm_nevra"] = srpm_nevra
            parsed_nevra["srpm_name"] = srpm_name
        parsed_nevra["excludearch"] = excludearch or []
        parsed_nevra["exclusivearch"] = exclusivearch or []
        parsed_nevra["license"] = license or ""
        self.cg.rpms.append(parsed_nevra)
        self.cg.rpms_dict[nevra] = parsed_nevra

        mmd = self.cg.module.mmd()
        if srpm_name not in mmd.get_rpm_component_names():
            component = Modulemd.ComponentRpm.new(srpm_name)
            component.set_rationale("foo")

            if multilib:
                for arch in multilib:
                    component.add_multilib_arch(arch)

            mmd.add_component(component)
            self.cg.module.modulemd = mmd_to_str(mmd)
            self.cg.modulemd = mmd_to_str(mmd)
Esempio n. 3
0
    def test_import_builds_from_local_dnf_repos(self, patched_open):
        with mock.patch("dnf.Base") as dnf_base:
            repo = mock.MagicMock()
            repo.repofile = "/etc/yum.repos.d/foo.repo"
            mmd = load_mmd(read_staged_data("formatted_testmodule"))
            repo.get_metadata_content.return_value = mmd_to_str(mmd)
            base = dnf_base.return_value
            base.repos = {"reponame": repo}
            patched_open.return_value.readlines.return_value = (
                "FOO=bar", "PLATFORM_ID=platform:x")

            import_builds_from_local_dnf_repos()

            base.read_all_repos.assert_called_once()
            repo.load.assert_called_once()
            repo.get_metadata_content.assert_called_once_with("modules")

            module_build = models.ModuleBuild.get_build_from_nsvc(
                db_session, "testmodule", "master", 20180205135154, "9c690d0e")
            assert module_build
            assert module_build.koji_tag == "repofile:///etc/yum.repos.d/foo.repo"

            module_build = models.ModuleBuild.get_build_from_nsvc(
                db_session, "platform", "x", 1, "000000")
            assert module_build
def test_get_rpm_release_metadata_br_stream_override(mock_admmn):
    """
    Test that when a module buildrequires a module in conf.allowed_privileged_module_names,
    and that module has the xmd.mbs.disttag_marking field set, it should influence the disttag.
    """
    scheduler_init_data(1)
    metadata_mmd = load_mmd(read_staged_data("build_metadata_module"))
    import_mmd(db_session, metadata_mmd)

    build_one = models.ModuleBuild.get_by_id(db_session, 2)
    mmd = build_one.mmd()
    deps = mmd.get_dependencies()[0]
    deps.add_buildtime_stream("build", "product1.2")
    xmd = mmd.get_xmd()
    xmd["mbs"]["buildrequires"]["build"] = {
        "filtered_rpms": [],
        "ref": "virtual",
        "stream": "product1.2",
        "version": "1",
        "context": "00000000",
    }
    mmd.set_xmd(xmd)
    build_one.modulemd = mmd_to_str(mmd)
    db_session.add(build_one)
    db_session.commit()

    release = utils.get_rpm_release(db_session, build_one)
    assert release == "module+product12+2+814cfa39"
Esempio n. 5
0
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)
Esempio n. 6
0
    def _finalize_mmd(self, arch):
        """
        Finalizes the modulemd:
            - Fills in the list of built RPMs respecting filters, whitelist and multilib.

        :param str arch: Name of arch to generate the final modulemd for.
        :rtype: str
        :return: Finalized modulemd string.
        """
        mmd = self._sanitize_mmd(self.module.mmd())
        if self.devel:
            # Set the new name
            mmd = mmd.copy(mmd.get_module_name() + "-devel")

            # Depend on the actual module
            for dep in mmd.get_dependencies():
                dep.add_runtime_stream(mmd.get_module_name(), mmd.get_stream_name())

            # Delete API and profiles
            for rpm in mmd.get_rpm_api():
                mmd.remove_rpm_api(rpm)
            mmd.clear_profiles()

        # Set the "Arch" field in mmd.
        mmd.set_arch(pungi.arch.tree_arch_to_yum_arch(arch))
        # Fill in the list of built RPMs.
        mmd = self._fill_in_rpms_list(mmd, arch)

        return mmd_to_str(mmd)
Esempio n. 7
0
    def test_get_reusable_component_different_buildrequires_stream(
            self, rebuild_strategy):
        first_module_build = models.ModuleBuild.get_by_id(db_session, 2)
        first_module_build.rebuild_strategy = rebuild_strategy
        db_session.commit()

        second_module_build = models.ModuleBuild.get_by_id(db_session, 3)
        mmd = second_module_build.mmd()
        xmd = mmd.get_xmd()
        xmd["mbs"]["buildrequires"]["platform"]["stream"] = "different"
        deps = Modulemd.Dependencies()
        deps.add_buildtime_stream("platform", "different")
        deps.add_runtime_stream("platform", "different")
        mmd.clear_dependencies()
        mmd.add_dependencies(deps)

        mmd.set_xmd(xmd)
        second_module_build.modulemd = mmd_to_str(mmd)
        second_module_build.build_context = \
            models.ModuleBuild.contexts_from_mmd(second_module_build.modulemd).build_context
        second_module_build.rebuild_strategy = rebuild_strategy
        db_session.commit()

        plc_rv = get_reusable_component(second_module_build,
                                        "perl-List-Compare")
        pt_rv = get_reusable_component(second_module_build, "perl-Tangerine")
        tangerine_rv = get_reusable_component(second_module_build, "tangerine")

        assert plc_rv is None
        assert pt_rv is None
        assert tangerine_rv is None
Esempio n. 8
0
    def test_submit_module_build_from_yaml_with_skiptests(self, mock_submit):
        """
        Tests local module build from a yaml file with the skiptests option

        Args:
            mock_submit (MagickMock): mocked function submit_module_build, which we then
                inspect if it was called with correct arguments
        """
        module_dir = tempfile.mkdtemp()
        module = models.ModuleBuild.get_by_id(db_session, 3)
        mmd = module.mmd()
        modulemd_yaml = mmd_to_str(mmd)
        modulemd_file_path = path.join(module_dir, "testmodule.yaml")

        username = "******"
        stream = "dev"

        with io.open(modulemd_file_path, "w", encoding="utf-8") as fd:
            fd.write(modulemd_yaml)

        with open(modulemd_file_path, "rb") as fd:
            handle = FileStorage(fd)
            submit_module_build_from_yaml(
                db_session, username, handle, {}, stream=stream, skiptests=True)
            mock_submit_args = mock_submit.call_args[0]
            username_arg = mock_submit_args[1]
            mmd_arg = mock_submit_args[2]
            assert mmd_arg.get_stream_name() == stream
            assert "\n\n%__spec_check_pre exit 0\n" in mmd_arg.get_buildopts().get_rpm_macros()
            assert username_arg == username
        rmtree(module_dir)
Esempio n. 9
0
    def test_get_module_build_dependencies_recursive(
            self, reuse_component_init_data):
        """
        Tests that the buildrequires are returned when it is two layers deep
        """
        # Add testmodule2 that requires testmodule
        module = models.ModuleBuild.get_by_id(db_session, 3)
        mmd = module.mmd()
        # Rename the module
        mmd = mmd.copy("testmodule2")
        mmd.set_version(20180123171545)
        deps = Modulemd.Dependencies()
        deps.add_runtime_stream("testmodule", "master")
        mmd.add_dependencies(deps)
        xmd = mmd.get_xmd()
        xmd["mbs"]["requires"]["testmodule"] = {
            "filtered_rpms": [],
            "ref": "620ec77321b2ea7b0d67d82992dda3e1d67055b4",
            "stream": "master",
            "version": "20180205135154",
        }
        mmd.set_xmd(xmd)
        module.modulemd = mmd_to_str(mmd)
        module.name = "testmodule2"
        module.version = str(mmd.get_version())
        module.koji_tag = "module-ae2adf69caf0e1b6"

        db_session.commit()

        resolver = mbs_resolver.GenericResolver.create(db_session,
                                                       conf,
                                                       backend="db")
        result = resolver.get_module_build_dependencies(
            "testmodule2", "master", "20180123171545", "c40c156c").keys()
        assert set(result) == {"module-f28-build"}
Esempio n. 10
0
    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()
Esempio n. 11
0
    def test_get_reusable_component_different_arch_in_batch(
            self, changed_component, reuse_component):
        """
        Test that we get the correct reuse behavior for the changed-and-after strategy. Changes
        to the architectures in earlier batches should prevent reuse, but such changes to later
        batches should not.
        For context, see https://pagure.io/fm-orchestrator/issue/1298
        """
        if changed_component == reuse_component:
            # we're only testing the cases where these are different
            # this case is already covered by test_get_reusable_component_different_arches
            return

        second_module_build = models.ModuleBuild.get_by_id(db_session, 3)

        # update arch for changed component
        mmd = second_module_build.mmd()
        component = mmd.get_rpm_component(changed_component)
        component.reset_arches()
        component.add_restricted_arch("i686")
        second_module_build.modulemd = mmd_to_str(mmd)
        db_session.commit()

        changed_component = models.ComponentBuild.from_component_name(
            db_session, changed_component, second_module_build.id)
        reuse_component = models.ComponentBuild.from_component_name(
            db_session, reuse_component, second_module_build.id)

        reuse_result = get_reusable_component(second_module_build,
                                              reuse_component.package)
        # Changing the arch of a component should prevent reuse only when the changed component
        # is in a batch earlier than the component being considered for reuse.
        assert bool(reuse_result is None) == bool(
            reuse_component.batch > changed_component.batch)
    def test_init_called_twice(self):
        build = self.init_basic(db_session)
        old_component_builds = len(build.component_builds)
        old_mmd = load_mmd(build.modulemd)

        build.state = 4
        db_session.commit()
        build = self.init_basic(db_session)
        db_session.refresh(build)

        assert build.state == 1
        assert old_component_builds == len(build.component_builds)

        new_mmd = load_mmd(build.modulemd)
        # Compare only lengths, because `mmd_to_str` can shuffle the fields randomly.
        assert len(mmd_to_str(old_mmd)) == len(mmd_to_str(new_mmd))
Esempio n. 13
0
    def test_get_buildrequired_modulemds(self):
        mmd = load_mmd(tests.read_staged_data("platform"))
        mmd = mmd.copy(mmd.get_module_name(), "f30.1.3")

        import_mmd(db_session, mmd)
        platform_f300103 = db_session.query(ModuleBuild).filter_by(stream="f30.1.3").one()
        mmd = tests.make_module("testmodule:master:20170109091357:123")
        build = ModuleBuild(
            name="testmodule",
            stream="master",
            version=20170109091357,
            state=5,
            build_context="dd4de1c346dcf09ce77d38cd4e75094ec1c08ec3",
            runtime_context="ec4de1c346dcf09ce77d38cd4e75094ec1c08ef7",
            context="7c29193d",
            koji_tag="module-testmodule-master-20170109091357-7c29193d",
            scmurl="https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79",
            batch=3,
            owner="Dr. Pepper",
            time_submitted=datetime(2018, 11, 15, 16, 8, 18),
            time_modified=datetime(2018, 11, 15, 16, 19, 35),
            rebuild_strategy="changed-and-after",
            modulemd=mmd_to_str(mmd),
        )
        build.buildrequires.append(platform_f300103)
        db_session.add(build)
        db_session.commit()

        resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="db")
        result = resolver.get_buildrequired_modulemds(
            "testmodule", "master", platform_f300103.mmd())
        nsvcs = {m.get_nsvc() for m in result}
        assert nsvcs == {"testmodule:master:20170109091357:123"}
Esempio n. 14
0
    def test_get_reusable_component_different_buildrequires(self):
        second_module_build = models.ModuleBuild.get_by_id(db_session, 3)
        mmd = second_module_build.mmd()
        mmd.get_dependencies()[0].add_buildtime_stream("some_module", "master")
        xmd = mmd.get_xmd()
        xmd["mbs"]["buildrequires"] = {
            "some_module": {
                "ref": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
                "stream": "master",
                "version": "20170123140147",
            }
        }
        mmd.set_xmd(xmd)
        second_module_build.modulemd = mmd_to_str(mmd)
        second_module_build.build_context = models.ModuleBuild.calculate_build_context(
            xmd["mbs"]["buildrequires"])
        db_session.commit()

        plc_rv = get_reusable_component(second_module_build,
                                        "perl-List-Compare")
        assert plc_rv is None

        pt_rv = get_reusable_component(second_module_build, "perl-Tangerine")
        assert pt_rv is None

        tangerine_rv = get_reusable_component(second_module_build, "tangerine")
        assert tangerine_rv is None
Esempio n. 15
0
    def test_tagging_already_tagged_artifacts(self, blocklist,
                                              mock_get_session):
        """
        Tests that buildroot_add_artifacts and tag_artifacts do not try to
        tag already tagged artifacts
        """
        module_build = module_build_service.common.models.ModuleBuild.get_by_id(
            db_session, 2)

        if blocklist:
            mmd = module_build.mmd()
            xmd = mmd.get_xmd()
            xmd["mbs_options"] = {"blocked_packages": ["foo", "bar", "new"]}
            mmd.set_xmd(xmd)
            module_build.modulemd = mmd_to_str(mmd)
            db_session.commit()

        builder = FakeKojiModuleBuilder(
            db_session=db_session,
            owner=module_build.owner,
            module=module_build,
            config=conf,
            tag_name="module-nginx-1.2",
            components=[],
        )

        builder.module_tag = {"name": "module-foo", "id": 1}
        builder.module_build_tag = {"name": "module-foo-build", "id": 2}

        # Set listTagged to return test data
        tagged = [{
            "nvr": "foo-1.0-1.module_e0095747"
        }, {
            "nvr": "bar-1.0-1.module_e0095747"
        }]
        builder.koji_session.listTagged.return_value = tagged

        # Try to tag one artifact which is already tagged and one new ...
        to_tag = ["foo-1.0-1.module_e0095747", "new-1.0-1.module_e0095747"]
        builder.buildroot_add_artifacts(to_tag)

        if blocklist:
            # "foo" and "new" packages should be unblocked before tagging.
            expected_calls = [
                mock.call("module-foo-build", "foo"),
                mock.call("module-foo-build", "new"),
            ]
        else:
            expected_calls = []
        assert builder.koji_session.packageListUnblock.mock_calls == expected_calls

        # ... only new one should be added.
        builder.koji_session.tagBuild.assert_called_once_with(
            builder.module_build_tag["id"], "new-1.0-1.module_e0095747")

        # Try the same for tag_artifacts(...).
        builder.koji_session.tagBuild.reset_mock()
        builder.tag_artifacts(to_tag)
        builder.koji_session.tagBuild.assert_called_once_with(
            builder.module_tag["id"], "new-1.0-1.module_e0095747")
    def test_get_arch_mmd_output_components(self, patched_open):
        mmd = self.cg.module.mmd()
        mmd.add_rpm_artifact("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64")
        mmd_data = mmd_to_str(mmd).encode("utf-8")

        patched_open.return_value = mock_open(read_data=mmd_data).return_value

        self.cg.rpms = [{
            "name": "dhcp",
            "version": "4.3.5",
            "release": "5.module_2118aef6",
            "arch": "x86_64",
            "epoch": "12",
            "payloadhash": "hash",
        }]

        self.cg.rpms_dict = {
            "dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64": {
                "name": "dhcp",
                "version": "4.3.5",
                "release": "5.module_2118aef6",
                "arch": "x86_64",
                "epoch": "12",
                "payloadhash": "hash",
            }
        }

        ret = self.cg._get_arch_mmd_output("./fake-dir", "x86_64")
        assert ret == {
            "arch":
            "x86_64",
            "buildroot_id":
            1,
            "checksum":
            "5fbad2ef9b6c5496bdce4368ca3182d6",
            "checksum_type":
            "md5",
            "components": [{
                u"arch": "x86_64",
                u"epoch": "12",
                u"name": "dhcp",
                u"release": "5.module_2118aef6",
                u"sigmd5": "hash",
                u"type": u"rpm",
                u"version": "4.3.5",
            }],
            "extra": {
                "typeinfo": {
                    "module": {}
                }
            },
            "filename":
            "modulemd.x86_64.txt",
            "filesize":
            316,
            "type":
            "file",
        }
Esempio n. 17
0
    def test_get_buildrequired_modulemds_kojiresolver(self, mock_session):
        """
        Test that MBSResolver uses KojiResolver as input when KojiResolver is enabled for
        the base module.
        """
        mock_session.get.return_value = Mock(ok=True)
        mock_session.get.return_value.json.return_value = {
            "items": [
                {
                    "name": "nodejs",
                    "stream": "10",
                    "version": 2,
                    "context": "c1",
                    "modulemd":
                    mmd_to_str(tests.make_module("nodejs:10:2:c1"), ),
                },
            ],
            "meta": {
                "next": None
            },
        }

        resolver = mbs_resolver.GenericResolver.create(db_session,
                                                       conf,
                                                       backend="mbs")

        platform = db_session.query(
            module_build_service.common.models.ModuleBuild).filter_by(
                id=1).one()
        platform_mmd = platform.mmd()
        platform_xmd = platform_mmd.get_xmd()
        platform_xmd["mbs"]["koji_tag_with_modules"] = "module-f29-build"
        platform_mmd.set_xmd(platform_xmd)

        with patch.object(resolver, "get_buildrequired_koji_builds"
                          ) as get_buildrequired_koji_builds:
            get_buildrequired_koji_builds.return_value = [{
                "build_id":
                124,
                "name":
                "nodejs",
                "version":
                "10",
                "release":
                "2.c1",
                "tag_name":
                "foo-test"
            }]
            result = resolver.get_buildrequired_modulemds(
                "nodejs", "10", platform_mmd)
            get_buildrequired_koji_builds.assert_called_once()

        assert 1 == len(result)
        mmd = result[0]
        assert "nodejs" == mmd.get_module_name()
        assert "10" == mmd.get_stream_name()
        assert 2 == mmd.get_version()
        assert "c1" == mmd.get_context()
Esempio n. 18
0
    def _get_fixed_mmd(self):
        if self.devel:
            mmd = self.module.mmd()
            mmd = mmd.copy(mmd.get_module_name() + "-devel")
            ret = mmd_to_str(mmd)
        else:
            ret = self.mmd

        return ret
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 setup_method(self, test_method):
     self.fn = module_build_service.scheduler.handlers.modules.init
     testmodule_yml_path = read_staged_data("testmodule_init")
     mmd = load_mmd(testmodule_yml_path)
     # Set the name and stream
     mmd = mmd.copy("testmodule", "1")
     scmurl = "git://pkgs.domain.local/modules/testmodule?#620ec77"
     clean_database()
     ModuleBuild.create(db_session, conf, "testmodule", "1", 3,
                        mmd_to_str(mmd), scmurl, "mprahl")
Esempio n. 21
0
    def _create_test_modules(self, koji_tag_with_modules="foo-test"):
        mmd = load_mmd(tests.read_staged_data("platform"))
        mmd = mmd.copy(mmd.get_module_name(), "f30.1.3")

        import_mmd(db_session, mmd)
        platform = db_session.query(ModuleBuild).filter_by(
            stream="f30.1.3").one()

        if koji_tag_with_modules:
            platform = db_session.query(ModuleBuild).filter_by(
                stream="f30.1.3").one()
            platform_mmd = platform.mmd()
            platform_xmd = platform_mmd.get_xmd()
            platform_xmd["mbs"][
                "koji_tag_with_modules"] = koji_tag_with_modules
            platform_mmd.set_xmd(platform_xmd)
            platform.modulemd = mmd_to_str(platform_mmd)

        for context in ["7c29193d", "7c29193e"]:
            mmd = tests.make_module("testmodule:master:20170109091357:" +
                                    context)
            build = ModuleBuild(
                name="testmodule",
                stream="master",
                version=20170109091357,
                state=5,
                build_context="dd4de1c346dcf09ce77d38cd4e75094ec1c08ec3",
                runtime_context="ec4de1c346dcf09ce77d38cd4e75094ec1c08ef7",
                context=context,
                koji_tag="module-testmodule-master-20170109091357-" + context,
                scmurl=
                "https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79",
                batch=3,
                owner="Dr. Pepper",
                time_submitted=datetime(2018, 11, 15, 16, 8, 18),
                time_modified=datetime(2018, 11, 15, 16, 19, 35),
                rebuild_strategy="changed-and-after",
                modulemd=mmd_to_str(mmd),
            )
            build.buildrequires.append(platform)
            db_session.add(build)
        db_session.commit()
Esempio n. 22
0
    def test_get_buildrequired_modulemds(self, mock_session):
        resolver = mbs_resolver.GenericResolver.create(db_session,
                                                       conf,
                                                       backend="mbs")
        mock_session.get.return_value = Mock(ok=True)
        mock_session.get.return_value.json.return_value = {
            "items": [
                {
                    "name": "nodejs",
                    "stream": "10",
                    "version": 1,
                    "context": "c1",
                    "modulemd":
                    mmd_to_str(tests.make_module("nodejs:10:1:c1"), ),
                },
                {
                    "name": "nodejs",
                    "stream": "10",
                    "version": 2,
                    "context": "c1",
                    "modulemd":
                    mmd_to_str(tests.make_module("nodejs:10:2:c1"), ),
                },
            ],
            "meta": {
                "next": None
            },
        }

        platform = db_session.query(
            module_build_service.common.models.ModuleBuild).filter_by(
                id=1).one()
        result = resolver.get_buildrequired_modulemds("nodejs", "10",
                                                      platform.mmd())

        assert 1 == len(result)
        mmd = result[0]
        assert "nodejs" == mmd.get_module_name()
        assert "10" == mmd.get_stream_name()
        assert 1 == mmd.get_version()
        assert "c1" == mmd.get_context()
Esempio n. 23
0
    def test_get_module_build_dependencies_empty_buildrequires(
            self, mock_session, testmodule_mmd_9c690d0e):

        mmd = load_mmd(testmodule_mmd_9c690d0e)
        # Wipe out the dependencies
        for deps in mmd.get_dependencies():
            mmd.remove_dependencies(deps)
        xmd = mmd.get_xmd()
        xmd["mbs"]["buildrequires"] = {}
        mmd.set_xmd(xmd)

        mock_res = Mock()
        mock_res.ok.return_value = True
        mock_res.json.side_effect = [{
            "items": [{
                "name": "testmodule",
                "stream": "master",
                "version": "20180205135154",
                "context": "9c690d0e",
                "modulemd": mmd_to_str(mmd),
                "build_deps": [],
            }],
            "meta": {
                "next": None
            },
        }]

        mock_session.get.return_value = mock_res

        expected = set()

        resolver = mbs_resolver.GenericResolver.create(db_session,
                                                       conf,
                                                       backend="mbs")
        result = resolver.get_module_build_dependencies(
            "testmodule", "master", "20180205135154", "9c690d0e").keys()
        mbs_url = conf.mbs_url
        expected_query = {
            "name": "testmodule",
            "stream": "master",
            "version": "20180205135154",
            "context": "9c690d0e",
            "verbose": True,
            "order_desc_by": "version",
            "page": 1,
            "per_page": 10,
            "state": ["ready"],
        }
        mock_session.get.assert_called_once_with(mbs_url,
                                                 params=expected_query)
        assert set(result) == expected
Esempio n. 24
0
    def test_get_reusable_component_different_rpm_macros(self):
        second_module_build = models.ModuleBuild.get_by_id(db_session, 3)
        mmd = second_module_build.mmd()
        buildopts = Modulemd.Buildopts()
        buildopts.set_rpm_macros("%my_macro 1")
        mmd.set_buildopts(buildopts)
        second_module_build.modulemd = mmd_to_str(mmd)
        db_session.commit()

        plc_rv = get_reusable_component(second_module_build, "perl-List-Compare")
        assert plc_rv is None

        pt_rv = get_reusable_component(second_module_build, "perl-Tangerine")
        assert pt_rv is None
Esempio n. 25
0
    def test_record_component_builds_component_exists_already(
            self, mocked_scm):
        mocked_scm.return_value.commit = "620ec77321b2ea7b0d67d82992dda3e1d67055b4"
        mocked_scm.return_value.get_latest.side_effect = [
            "4ceea43add2366d8b8c5a622a2fb563b625b9abf",
            "fbed359411a1baa08d4a88e0d12d426fbf8f602c",
            "dbed259411a1baa08d4a88e0d12d426fbf8f6037",
            "4ceea43add2366d8b8c5a622a2fb563b625b9abf",
            # To simulate that when a module is resubmitted, some ref of
            # its components is changed, which will cause MBS stops
            # recording component to database and raise an error.
            "abcdefg",
            "dbed259411a1baa08d4a88e0d12d426fbf8f6037",
        ]

        original_mmd = load_mmd(read_staged_data("testmodule"))

        # Set the module name and stream
        mmd = original_mmd.copy("testmodule", "master")
        module_build = module_build_service.common.models.ModuleBuild()
        module_build.name = "testmodule"
        module_build.stream = "master"
        module_build.version = 20170109091357
        module_build.state = models.BUILD_STATES["init"]
        module_build.scmurl = \
            "https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79"
        module_build.batch = 1
        module_build.owner = "Tom Brady"
        module_build.time_submitted = datetime(2017, 2, 15, 16, 8, 18)
        module_build.time_modified = datetime(2017, 2, 15, 16, 19, 35)
        module_build.rebuild_strategy = "changed-and-after"
        module_build.modulemd = mmd_to_str(mmd)
        db_session.add(module_build)
        db_session.commit()

        format_mmd(mmd, module_build.scmurl)
        record_component_builds(mmd, module_build)
        db_session.commit()

        mmd = original_mmd.copy("testmodule", "master")

        from module_build_service.common.errors import ValidationError
        with pytest.raises(
                ValidationError,
                match=
                r"Component build .+ of module build .+ already exists in database"
        ):
            format_mmd(mmd, module_build.scmurl)
            record_component_builds(mmd, module_build)
def test_get_rpm_release_platform_stream_override():
    scheduler_init_data(1)

    # Set the disttag_marking override on the platform
    platform = (db_session.query(models.ModuleBuild).filter_by(
        name="platform", stream="f28").first())
    platform_mmd = platform.mmd()
    platform_xmd = platform_mmd.get_xmd()
    platform_xmd["mbs"]["disttag_marking"] = "fedora28"
    platform_mmd.set_xmd(platform_xmd)
    platform.modulemd = mmd_to_str(platform_mmd)
    db_session.add(platform)
    db_session.commit()

    build_one = models.ModuleBuild.get_by_id(db_session, 2)
    release = utils.get_rpm_release(db_session, build_one)
    assert release == "module+fedora28+2+814cfa39"
 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_prepare_file_directory_modulemd_src(self, mocked_scm):
     FakeSCM(
         mocked_scm,
         "testmodule",
         "testmodule_init.yaml",
         "620ec77321b2ea7b0d67d82992dda3e1d67055b4",
     )
     mmd = self.cg.module.mmd()
     mmd.set_xmd({
         "mbs": {
             "commit": "foo",
             "scmurl": "git://localhost/modules/foo.git#master"
         }
     })
     self.cg.module.modulemd = mmd_to_str(mmd)
     file_dir = self.cg._prepare_file_directory()
     with io.open(path.join(file_dir, "modulemd.src.txt"),
                  encoding="utf-8") as mmd:
         assert len(mmd.read()) == 1339
    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
Esempio n. 30
0
    def test_record_component_builds_duplicate_components(self, mocked_scm):
        # Mock for format_mmd to get components' latest ref
        mocked_scm.return_value.commit = "620ec77321b2ea7b0d67d82992dda3e1d67055b4"
        mocked_scm.return_value.get_latest.side_effect = [
            "4ceea43add2366d8b8c5a622a2fb563b625b9abf",
            "fbed359411a1baa08d4a88e0d12d426fbf8f602c",
        ]

        mmd = load_mmd(read_staged_data("testmodule"))
        mmd = mmd.copy("testmodule-variant", "master")
        module_build = module_build_service.common.models.ModuleBuild()
        module_build.name = "testmodule-variant"
        module_build.stream = "master"
        module_build.version = 20170109091357
        module_build.state = models.BUILD_STATES["init"]
        module_build.scmurl = \
            "https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79"
        module_build.batch = 1
        module_build.owner = "Tom Brady"
        module_build.time_submitted = datetime(2017, 2, 15, 16, 8, 18)
        module_build.time_modified = datetime(2017, 2, 15, 16, 19, 35)
        module_build.rebuild_strategy = "changed-and-after"
        module_build.modulemd = mmd_to_str(mmd)
        db_session.add(module_build)
        db_session.commit()
        # Rename the the modulemd to include
        mmd = mmd.copy("testmodule")
        # Remove perl-Tangerine and tangerine from the modulemd to include so only one
        # component conflicts
        mmd.remove_rpm_component("perl-Tangerine")
        mmd.remove_rpm_component("tangerine")

        error_msg = (
            'The included module "testmodule" in "testmodule-variant" have '
            "the following conflicting components: perl-List-Compare")
        format_mmd(mmd, module_build.scmurl)
        with pytest.raises(UnprocessableEntity) as e:
            record_component_builds(mmd,
                                    module_build,
                                    main_mmd=module_build.mmd())

        assert str(e.value) == error_msg