Пример #1
0
 def test_components_different_chroots(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
     # https://bugzilla.redhat.com/show_bug.cgi?id=1444433
     # Test that we can pass a list of builds to the add_components,
     # that have no common chroots
     packages = [self.p1.name, self.p2.name, self.p3.name]
     filter_packages = [self.p1.name, self.p2.name]
     builds = [self.b1.id, self.b3.id]
     generator = ModulemdGenerator(config=self.config)
     generator.add_components(packages, filter_packages, builds)
Пример #2
0
 def test_profiles(self):
     profile_names = ["default", "debug"]
     profile_pkgs = [["pkg1", "pkg2"], ["pkg3"]]
     profiles = enumerate(zip(profile_names, profile_pkgs))
     generator = ModulemdGenerator()
     generator.add_profiles(profiles)
     assert set(generator.mmd.get_profiles().keys()) == set(profile_names)
     assert set(generator.mmd.get_profiles()["default"].peek_rpms().get()) == {"pkg1", "pkg2"}
     assert set(generator.mmd.get_profiles()["debug"].peek_rpms().get()) == {"pkg3"}
     assert len(generator.mmd.get_profiles()) == 2
Пример #3
0
    def test_components(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        packages = [self.p1.name, self.p2.name, self.p3.name]
        filter_packages = [self.p1.name, self.p2.name]
        builds = [self.b1.id, self.b3.id]
        generator = ModulemdGenerator(config=self.config)

        with mock.patch("coprs.logic.modules_logic.ModulemdGenerator.add_component") as add_component:
            generator.add_components(packages, filter_packages, builds)
            add_component.assert_called_with(self.p2.name, self.b3, self.b3.build_chroots[-1], mock.ANY, 1)
            assert add_component.call_count == 2
Пример #4
0
    def test_add_builds_batches(self, f_users, f_coprs, f_mock_chroots, f_builds, f_modules, f_db):
        pkg1 = Modulemd.ComponentRpm(name="foo", rationale="foo package")
        pkg2 = Modulemd.ComponentRpm(name="bar", rationale="bar package", buildorder=10)
        pkg3 = Modulemd.ComponentRpm(name="baz", rationale="baz package", buildorder=10)

        generator = ModulemdGenerator(name="testmodule", stream="master", version=123, summary="some summary")
        facade = ModuleBuildFacade(self.u1, self.c1, generator.generate(), "testmodule.yaml")
        facade.add_builds({"foo": pkg1, "bar": pkg2, "baz": pkg3}, self.m1)

        b1, b2, b3 = self.m1.builds
        assert b1.batch != b2.batch == b3.batch
        assert b2.batch.blocked_by == b1.batch
Пример #5
0
    def test_add_component(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        chroot = self.b1.build_chroots[0]
        generator = ModulemdGenerator(config=self.config)
        generator.add_component(self.b1.package_name, self.b1, chroot,
                                "A reason why package is in the module", buildorder=1)
        assert len(generator.mmd.get_rpm_components()) == 1

        component = generator.mmd.get_rpm_components()[self.b1.package_name]
        assert component.get_buildorder() == 1
        assert component.peek_name() == self.b1.package_name
        assert component.peek_rationale() == "A reason why package is in the module"

        with mock.patch("coprs.app.config", self.config):
            assert component.peek_repository().startswith("http://distgiturl.org")
            assert component.peek_repository().endswith(".git")
            assert chroot.dist_git_url.startswith(component.peek_repository())
        assert component.peek_ref() == chroot.git_hash
Пример #6
0
 def test_basic_mmd_attrs(self):
     generator = ModulemdGenerator(name="testmodule", stream="master",
                                   version=123, summary="Some testmodule summary")
     assert generator.mmd.get_name() == "testmodule"
     assert generator.mmd.get_stream() == "master"
     assert generator.mmd.get_version() == 123
     assert generator.mmd.get_summary() == "Some testmodule summary"
     assert generator.nsv == "testmodule-master-123"
Пример #7
0
    def test_platform_chroots(self, f_users, f_coprs, f_mock_chroots_many, f_builds, f_modules, f_db):
        fedora_chroots = [chroot.name for chroot in self.c1.mock_chroots if chroot.name.startswith("fedora")]

        # Test excluding platform chroots
        CoprChrootsLogic.update_from_names(self.u1, self.c1, fedora_chroots)
        generator = ModulemdGenerator(name="testmodule", stream="master", version=123, summary="some summary")
        generator.mmd.set_buildrequires({"platform": "-f22"})
        facade = ModuleBuildFacade(self.u1, self.c1, generator.generate(), "testmodule.yaml")
        assert {chroot.name for chroot in self.c1.active_chroots} == set(fedora_chroots)
        assert ("fedora-22-i386" not in facade.platform_chroots) and ("fedora-22-x86_64" in fedora_chroots)
        assert ("fedora-22-x86_64" not in facade.platform_chroots) and ("fedora-22-x86_64" in fedora_chroots)

        # Test setting platform chroots from scratch
        CoprChrootsLogic.update_from_names(self.u1, self.c1, fedora_chroots)
        generator = ModulemdGenerator(name="testmodule", stream="master", version=123, summary="some summary")
        generator.mmd.set_buildrequires({"platform": "f22"})
        facade = ModuleBuildFacade(self.u1, self.c1, generator.generate(), "testmodule.yaml")
        assert {chroot.name for chroot in self.c1.active_chroots} == set(fedora_chroots)
        assert set(facade.platform_chroots) == {"fedora-22-i386", "fedora-22-x86_64"}
Пример #8
0
 def test_generate(self):
     generator = ModulemdGenerator("testmodule", "master", 123, "Some testmodule summary", self.config)
     generator.add_api(["foo", "bar", "baz"])
     generator.add_filter(["foo", "bar"])
     yaml.load(generator.generate(), Loader=yaml.BaseLoader)
Пример #9
0
 def test_add_component_none_build_chroot(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
     # https://bugzilla.redhat.com/show_bug.cgi?id=1444433
     generator = ModulemdGenerator(config=self.config)
     generator.add_component(self.p1.name, self.b1, None, "Some reason")
Пример #10
0
 def test_filter(self):
     packages = {"foo", "bar", "baz"}
     generator = ModulemdGenerator()
     generator.add_filter(packages)
     assert set(generator.mmd.get_rpm_filter().get()) == packages
Пример #11
0
def build_module(copr, form):
    if not form.validate_on_submit():
        # WORKAROUND append those which are not in min_entries
        for i in range(2, len(form.profile_names)):
            form.profile_pkgs.append_entry()
        return render_create_module(copr,
                                    form,
                                    profiles=len(form.profile_names))

    summary = "Module from Copr repository: {}".format(copr.full_name)
    generator = ModulemdGenerator(str(copr.name),
                                  summary=summary,
                                  config=app.config)
    generator.add_filter(form.filter.data)
    generator.add_api(form.api.data)
    generator.add_profiles(
        enumerate(zip(form.profile_names.data, form.profile_pkgs.data)))
    generator.add_components(form.packages.data, form.filter.data,
                             form.builds.data)
    yaml = generator.generate()

    facade = None
    try:
        facade = ModuleBuildFacade(flask.g.user, copr, yaml)
        module = facade.submit_build()
        db.session.commit()

        flask.flash(
            "Modulemd yaml file successfully generated and submitted to be build as {}"
            .format(module.nsv), "success")
        return flask.redirect(url_for_copr_details(copr))

    except ValidationError as ex:
        flask.flash(ex.message, "error")
        return render_create_module(copr, form, len(form.profile_names))

    except sqlalchemy.exc.IntegrityError:
        flask.flash(
            "Module {}-{}-{} already exists".format(facade.modulemd.name,
                                                    facade.modulemd.stream,
                                                    facade.modulemd.version),
            "error")
        db.session.rollback()
        return render_create_module(copr, form, len(form.profile_names))