Пример #1
0
def test_import_mmd_dont_remove_dropped_virtual_streams_associated_with_other_modules(
):
    mmd = load_mmd(read_staged_data("formatted_testmodule"))
    # Add some virtual streams to this module metadata
    xmd = mmd.get_xmd()
    xmd["mbs"]["virtual_streams"] = ["f28", "f29", "f30"]
    mmd.set_xmd(xmd)
    import_mmd(db_session, mmd)

    # Import another module which has overlapping virtual streams
    another_mmd = load_mmd(
        read_staged_data("formatted_testmodule-more-components"))
    # Add some virtual streams to this module metadata
    xmd = another_mmd.get_xmd()
    xmd["mbs"]["virtual_streams"] = ["f29", "f30"]
    another_mmd.set_xmd(xmd)
    another_module_build, _ = import_mmd(db_session, another_mmd)

    # Now, remove f30 from mmd
    xmd = mmd.get_xmd()
    xmd["mbs"]["virtual_streams"] = ["f28", "f29"]
    mmd.set_xmd(xmd)

    # Reimport formatted_testmodule again
    module_build, _ = import_mmd(db_session, mmd)

    db_session.refresh(module_build)
    assert ["f28", "f29"] == sorted(item.name
                                    for item in module_build.virtual_streams)

    # The overlapped f30 should be still there.
    db_session.refresh(another_module_build)
    assert ["f29",
            "f30"] == sorted(item.name
                             for item in another_module_build.virtual_streams)
Пример #2
0
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_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"
Пример #4
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()
Пример #5
0
def submit_module_build_from_yaml(
    db_session, username, handle, params, stream=None, skiptests=False
):
    yaml_file = to_text_type(handle.read())
    mmd = load_mmd(yaml_file)
    dt = datetime.utcfromtimestamp(int(time.time()))
    if hasattr(handle, "filename"):
        def_name = str(os.path.splitext(os.path.basename(handle.filename))[0])
    elif not mmd.get_module_name():
        raise ValidationError(
            "The module's name was not present in the modulemd file. Please use the "
            '"module_name" parameter'
        )
    def_version = int(dt.strftime("%Y%m%d%H%M%S"))
    module_name = mmd.get_module_name() or def_name
    module_stream = stream or mmd.get_stream_name() or "master"
    if module_name != mmd.get_module_name() or module_stream != mmd.get_stream_name():
        # This is how you set the name and stream in the modulemd
        mmd = mmd.copy(module_name, module_stream)
    mmd.set_version(mmd.get_version() or def_version)
    if skiptests:
        buildopts = mmd.get_buildopts() or Modulemd.Buildopts()
        macros = buildopts.get_rpm_macros() or ""
        buildopts.set_rpm_macros(macros + "\n\n%__spec_check_pre exit 0\n")
        mmd.set_buildopts(buildopts)
    return submit_module_build(db_session, username, mmd, params)
Пример #6
0
def clean_database(add_platform_module=True, add_default_arches=True):
    """Initialize the test database

    This function is responsible for dropping all the data in the database and
    recreating all the tables from scratch.

    Please note that, this function relies on database objects managed by
    Flask-SQLAlchemy.
    """

    # Helpful for writing tests if any changes were made using the database
    # session but the test didn't commit or rollback.
    #
    # clean_database is usually called before a test run. So, it makes no sense
    # to keep any changes in the transaction made by previous test.
    db_session.remove()
    db_session.configure(bind=db.session.get_bind())

    db.drop_all()
    db.create_all()

    if add_default_arches:
        arch_obj = module_build_service.common.models.ModuleArch(name="x86_64")
        db.session.add(arch_obj)
        db.session.commit()

    if add_platform_module:
        mmd = load_mmd(read_staged_data("platform"))
        import_mmd(db.session, mmd)
Пример #7
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)
    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
Пример #9
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
Пример #10
0
    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))
Пример #11
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"}
Пример #12
0
    def test_get_build_arches_koji_tag_arches(self, cfg):
        mmd = load_mmd(read_staged_data("formatted_testmodule"))
        xmd = mmd.get_xmd()
        xmd["mbs"]["koji_tag_arches"] = ["ppc64", "ppc64le"]
        mmd.set_xmd(xmd)

        r = get_build_arches(mmd, conf)
        assert r == ["ppc64", "ppc64le"]
Пример #13
0
def test_import_mmd_multiple_dependencies():
    mmd = load_mmd(read_staged_data("formatted_testmodule"))
    mmd.add_dependencies(mmd.get_dependencies()[0].copy())

    expected_error = "The imported module's dependencies list should contain just one element"
    with pytest.raises(UnprocessableEntity) as e:
        import_mmd(db_session, mmd)
        assert str(e.value) == expected_error
Пример #14
0
def require_platform_and_default_arch_cls(require_empty_database_cls):
    """Provides clean database with platform module and default arch"""
    arch_obj = module_build_service.common.models.ModuleArch(name="x86_64")
    db_session.add(arch_obj)
    db_session.commit()

    mmd = load_mmd(read_staged_data("platform"))
    import_mmd(db_session, mmd)
Пример #15
0
 def test_get_build_arches_no_arch_set(self, ClientSession):
     """
     When no architecture is set in Koji tag, fallback to conf.arches.
     """
     session = ClientSession.return_value
     session.getTag.return_value = {"arches": ""}
     mmd = load_mmd(read_staged_data("formatted_testmodule"))
     r = get_build_arches(mmd, conf)
     assert set(r) == set(conf.arches)
    def test_get_generator_json(self, rpms_in_tag, machine, distro, pkg_res,
                                mock_Modulemd, popen, ClientSession, devel):
        """ Test generation of content generator json """
        mock_Modulemd.get_version.return_value = "2.3.1"
        koji_session = ClientSession.return_value
        koji_session.getUser.return_value = GET_USER_RV
        koji_session.getTag.return_value = {"arches": ""}
        distro.return_value = ("Fedora", "25", "Twenty Five")
        machine.return_value = "i686"
        pkg_res.return_value = Mock()
        pkg_res.return_value.version = "current-tested-version"
        rpm_mock = Mock()
        rpm_out = (
            b"rpm-name;1.0;r1;x86_64;(none);sigmd5:1;sigpgp:p;siggpg:g\n"
            b"rpm-name-2;2.0;r2;i686;1;sigmd5:2;sigpgp:p2;siggpg:g2")
        attrs = {
            "communicate.return_value": (rpm_out, "error"),
            "wait.return_value": 0
        }
        rpm_mock.configure_mock(**attrs)
        popen.return_value = rpm_mock

        tests_dir = path.abspath(path.dirname(__file__))
        rpm_in_tag_path = path.join(
            tests_dir, "test_get_generator_json_rpms_in_tag.json")
        with open(rpm_in_tag_path) as rpms_in_tag_file:
            rpms_in_tag.return_value = json.load(rpms_in_tag_file)

        expected_output_path = path.join(
            tests_dir, "test_get_generator_json_expected_output_with_log.json")
        with open(expected_output_path) as expected_output_file:
            expected_output = json.load(expected_output_file)

        # create the build.log
        build_logs.start(db_session, self.cg.module)
        build_logs.stop(self.cg.module)

        self.cg.devel = devel
        self.cg._load_koji_tag(koji_session)
        file_dir = self.cg._prepare_file_directory()
        ret = self.cg._get_content_generator_metadata(file_dir)
        rpms_in_tag.assert_called_once()
        if not devel:
            assert expected_output == ret
        else:
            # For devel, only check that the name has -devel suffix.
            assert ret["build"]["name"] == "nginx-devel"
            assert ret["build"]["extra"]["typeinfo"]["module"][
                "name"] == "nginx-devel"
            new_mmd = load_mmd(
                ret["build"]["extra"]["typeinfo"]["module"]["modulemd_str"])
            assert new_mmd.get_module_name().endswith("-devel")
            new_mmd = load_mmd_file("%s/modulemd.txt" % file_dir)
            assert new_mmd.get_module_name().endswith("-devel")

        # Ensure an anonymous Koji session works
        koji_session.krb_login.assert_not_called()
Пример #17
0
    def test_submit_build_static_context(self):
        """
        Test that we can now build modules with static contexts. The contexts are defined in
        the `xmd` property by the `contexts` property of the initial modulemd yaml file. The
        `contexts` is not pressent in the resulting module build. The generated contexts of a
        module is overridden by the static context defined by the user and the `mse` property
        is set to False.
        """

        yaml_str = """
document: modulemd
version: 2
data:
    name: app
    stream: test
    summary: "A test module"
    description: >
        "A test module stream"
    license:
        module: [ MIT ]
    dependencies:
        - buildrequires:
            platform: []
            gtk: []
          requires:
            platform: []
            gtk: []
    xmd:
        mbs_options:
            contexts:
                context1:
                    buildrequires:
                        platform: f28
                    requires:
                        platform: f28
                        gtk: 1
                context2:
                    buildrequires:
                        platform: f28
                    requires:
                        platform: f28
                        gtk: 2
        """
        mmd = load_mmd(yaml_str)

        builds = submit_module_build(db_session, "app", mmd, {})

        expected_context = ["context1", "context2"]

        assert len(builds) == 2

        for build in builds:
            assert build.context in expected_context
            mmd = build.mmd()
            xmd = mmd.get_xmd()
            assert "mbs_options" not in xmd
            assert xmd["mbs"]["static_context"]
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
Пример #19
0
 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")
Пример #20
0
def test_add_default_modules_not_linked(mock_get_dm):
    """
    Test that no default modules are added when they aren't linked from the base module.
    """
    clean_database()
    mmd = load_mmd(read_staged_data("formatted_testmodule.yaml"))
    assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"platform"}
    default_modules.add_default_modules(mmd)
    assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"platform"}
    mock_get_dm.assert_not_called()
Пример #21
0
    def test_get_build_arches_base_module_override(self):
        mmd = load_mmd(read_staged_data("formatted_testmodule"))
        xmd = mmd.get_xmd()
        mbs_options = xmd["mbs"] if "mbs" in xmd.keys() else {}
        mbs_options["buildrequires"] = {"platform": {"stream": "xx"}}
        xmd["mbs"] = mbs_options
        mmd.set_xmd(xmd)

        r = get_build_arches(mmd, conf)
        assert r == ["x86_64", "i686"]
def test_add_default_modules_platform_not_available(require_empty_database):
    """
    Test that an exception is raised when the platform module that is buildrequired is missing.

    This error should never occur in practice.
    """
    mmd = load_mmd(read_staged_data("formatted_testmodule.yaml"))

    expected_error = "Failed to retrieve the module platform:f28:3:00000000 from the database"
    with pytest.raises(RuntimeError, match=expected_error):
        default_modules.add_default_modules(mmd)
Пример #23
0
def test_import_mmd_minimal_xmd_from_local_repository():
    mmd = load_mmd(read_staged_data("formatted_testmodule"))
    xmd = mmd.get_xmd()
    xmd["mbs"] = {}
    xmd["mbs"]["koji_tag"] = "repofile:///etc/yum.repos.d/fedora-modular.repo"
    xmd["mbs"]["mse"] = True
    xmd["mbs"]["commit"] = "unknown"
    mmd.set_xmd(xmd)

    build, msgs = import_mmd(db_session, mmd, False)
    assert build.name == mmd.get_module_name()
Пример #24
0
    def resolve_profiles(self, mmd, keys):
        """
        :param mmd: Modulemd.ModuleStream instance of module
        :param keys: list of modulemd installation profiles to include in
                     the result.
        :return: Dictionary with keys set according to `keys` param and values
                 set to union of all components defined in all installation
                 profiles matching the key using the buildrequires.

        If there are some modules loaded by load_local_builds(...), these
        local modules will be considered when returning the profiles.

        https://pagure.io/fm-orchestrator/issue/181
        """

        results = {}
        for key in keys:
            results[key] = set()
        for module_name, module_info in mmd.get_xmd(
        )["mbs"]["buildrequires"].items():
            local_modules = models.ModuleBuild.local_modules(
                self.db_session, module_name, module_info["stream"])
            if local_modules:
                local_module = local_modules[0]
                log.info("Using local module %r to resolve profiles.",
                         local_module)
                dep_mmd = local_module.mmd()
                for key in keys:
                    profile = dep_mmd.get_profile(key)
                    if profile:
                        results[key] |= set(profile.get_rpms())
                continue

            # Find the dep in the built modules in MBS
            modules = self._get_modules(
                module_name,
                module_info["stream"],
                module_info["version"],
                module_info["context"],
                strict=True,
            )

            for module in modules:
                yaml = module["modulemd"]
                dep_mmd = load_mmd(yaml)
                # Take note of what rpms are in this dep's profile.
                for key in keys:
                    profile = dep_mmd.get_profile(key)
                    if profile:
                        results[key] |= set(profile.get_rpms())

        # Return the union of all rpms in all profiles of the given keys.
        return results
Пример #25
0
def test_import_mmd_no_xmd_buildrequires():
    mmd = load_mmd(read_staged_data("formatted_testmodule"))
    xmd = mmd.get_xmd()
    del xmd["mbs"]["buildrequires"]
    mmd.set_xmd(xmd)

    expected_error = (
        "The imported module buildrequires other modules, but the metadata in the "
        'xmd["mbs"]["buildrequires"] dictionary is missing entries')
    with pytest.raises(UnprocessableEntity) as e:
        import_mmd(db_session, mmd)
        assert str(e.value) == expected_error
Пример #26
0
 def get_modulemd_by_koji_tag(self, tag):
     resp = requests_session.get(self.mbs_prod_url,
                                 params={
                                     "koji_tag": tag,
                                     "verbose": True
                                 })
     data = resp.json()
     if data["items"]:
         modulemd = data["items"][0]["modulemd"]
         return load_mmd(modulemd)
     else:
         return None
Пример #27
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
def test_handle_collisions_with_base_module_rpms(mock_grft, mock_get_session):
    """
    Test that handle_collisions_with_base_module_rpms will add conflicts for NEVRAs in the
    modulemd.
    """
    mmd = load_mmd(read_staged_data("formatted_testmodule.yaml"))
    xmd = mmd.get_xmd()
    xmd["mbs"]["buildrequires"]["platform"]["koji_tag"] = "module-el-build"
    xmd["mbs"]["buildrequires"]["python"] = {"koji_tag": "module-python27"}
    xmd["mbs"]["buildrequires"]["bash"] = {"koji_tag": "module-bash"}
    mmd.set_xmd(xmd)

    bm_rpms = {
        "bash-completion-1:2.7-5.el8.noarch",
        "bash-0:4.4.19-7.el8.aarch64",
        "python2-tools-0:2.7.16-11.el8.aarch64",
        "python2-tools-0:2.7.16-11.el8.x86_64",
        "python3-ldap-0:3.1.0-4.el8.aarch64",
        "python3-ldap-0:3.1.0-4.el8.x86_64",
    }
    non_bm_rpms = {
        "bash-0:4.4.20-1.el8.aarch64",
        "python2-tools-0:2.7.18-1.module+el8.1.0+3568+bbd875cb.aarch64",
        "python2-tools-0:2.7.18-1.module+el8.1.0+3568+bbd875cb.x86_64",
    }
    mock_grft.side_effect = [bm_rpms, non_bm_rpms]

    default_modules.handle_collisions_with_base_module_rpms(
        mmd, ["aarch64", "x86_64"])

    mock_get_session.assert_called_once()
    xmd_mbs = mmd.get_xmd()["mbs"]
    assert set(xmd_mbs["ursine_rpms"]) == {
        "bash-0:4.4.19-7.el8.aarch64",
        "python2-tools-0:2.7.16-11.el8.aarch64",
        "python2-tools-0:2.7.16-11.el8.x86_64",
    }
    assert mock_grft.call_count == 2
    # We can't check the calls directly because the second argument is a set converted to a list,
    # so the order can't be determined ahead of time.
    first_call = mock_grft.mock_calls[0][1]
    assert first_call[0] == mock_get_session.return_value
    assert first_call[1] == ["module-el-build"]
    assert first_call[2] == ["aarch64", "x86_64"]

    second_call = mock_grft.mock_calls[1][1]
    assert second_call[0] == mock_get_session.return_value
    assert set(second_call[1]) == {"module-bash", "module-python27"}
    assert second_call[2] == ["aarch64", "x86_64"]
Пример #29
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)
Пример #30
0
def test_import_mmd_base_module(stream, disttag_marking, error_msg):
    clean_database(add_platform_module=False)
    mmd = load_mmd(read_staged_data("platform"))
    mmd = mmd.copy(mmd.get_module_name(), stream)

    if disttag_marking:
        xmd = mmd.get_xmd()
        xmd["mbs"]["disttag_marking"] = disttag_marking
        mmd.set_xmd(xmd)

    if error_msg:
        with pytest.raises(UnprocessableEntity, match=error_msg):
            import_mmd(db_session, mmd)
    else:
        import_mmd(db_session, mmd)