예제 #1
0
def edit_project(ownername, projectname):
    copr = get_copr(ownername, projectname)
    data = rename_fields(get_form_compatible_data())
    form = forms.CoprModifyForm(data, meta={'csrf': False})

    if not form.validate_on_submit():
        raise BadRequest(form.errors)
    validate_chroots(get_input_dict(), MockChrootsLogic.get_multiple())

    for field in form:
        if field.data is None or field.name in ["csrf_token", "chroots"]:
            continue
        if field.name not in data.keys():
            continue
        setattr(copr, field.name, field.data)

    if form.chroots.data:
        CoprChrootsLogic.update_from_names(flask.g.user, copr,
                                           form.chroots.data)

    try:
        CoprsLogic.update(flask.g.user, copr)
        if copr.group:  # load group.id
            _ = copr.group.id
        db.session.commit()
    except (ActionInProgressException, InsufficientRightsException,
            NonAdminCannotDisableAutoPrunning) as ex:
        db.session.rollback()
        raise ex

    return flask.jsonify(to_dict(copr))
예제 #2
0
def edit_project_chroot(ownername, projectname, chrootname):
    copr = get_copr(ownername, projectname)
    data = rename_fields(get_form_compatible_data())
    form = forms.ModifyChrootForm(data, meta={'csrf': False})
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise BadRequest(form.errors)

    buildroot_pkgs = repos = comps_xml = comps_name = with_opts = without_opts = None
    if "buildroot_pkgs" in data:
        buildroot_pkgs = form.buildroot_pkgs.data
    if "repos" in data:
        repos = form.repos.data
    if "with_opts" in data:
        with_opts = form.with_opts.data
    if "without_opts" in data:
        without_opts = form.without_opts.data
    if form.upload_comps.has_file():
        comps_xml = form.upload_comps.data.stream.read()
        comps_name = form.upload_comps.data.filename
    if form.delete_comps.data:
        CoprChrootsLogic.remove_comps(flask.g.user, chroot)
    CoprChrootsLogic.update_chroot(flask.g.user,
                                   chroot,
                                   buildroot_pkgs,
                                   repos,
                                   comps=comps_xml,
                                   comps_name=comps_name,
                                   with_opts=with_opts,
                                   without_opts=without_opts)
    db.session.commit()
    return flask.jsonify(to_dict(chroot))
예제 #3
0
    def test_update_from_names(self, f_users, f_coprs, f_mock_chroots, f_db):
        chroot_names = ["fedora-17-x86_64", "fedora-17-i386"]
        assert [ch.name for ch in self.c2.copr_chroots] == chroot_names
        CoprChrootsLogic.update_from_names(self.c2.user, self.c2, chroot_names)
        assert [ch.name for ch in self.c2.copr_chroots] == chroot_names

        chroot_names = ["fedora-17-x86_64"]
        CoprChrootsLogic.update_from_names(self.c2.user, self.c2, chroot_names)
        assert [ch.name for ch in self.c2.copr_chroots] == chroot_names
예제 #4
0
    def test_update_from_names_disabled(self, f_users, f_coprs, f_mock_chroots,
                                        f_db):
        # Say, that fedora-17-x86_64 is outdated
        self.mc2.is_active = False

        # The fedora-17-x86_64 is not a part of the copr edit form,
        # because it is outdated. See #712, PR#719
        CoprChrootsLogic.update_from_names(self.c2.user, self.c2,
                                           ["fedora-17-i386"])

        # However, it should not be removed from the Copr
        assert [ch.name for ch in self.c2.copr_chroots
                ] == ["fedora-17-x86_64", "fedora-17-i386"]
예제 #5
0
def process_chroot_update(copr, chroot_name):

    form = forms.ChrootForm()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    if not flask.g.user.can_build_in(copr):
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))

    if form.validate_on_submit():
        if "submit" in flask.request.form:
            action = flask.request.form["submit"]
            if action == "update":
                comps_name = comps_xml = None
                module_md_name = module_md = None

                if form.comps.has_file():
                    comps_xml = form.comps.data.stream.read()
                    comps_name = form.comps.data.filename

                if form.module_md.has_file():
                    module_md = form.module_md.data.stream.read()
                    module_md_name = form.module_md.data.filename

                coprs_logic.CoprChrootsLogic.update_chroot(
                    flask.g.user, chroot, form.buildroot_pkgs.data,
                    comps=comps_xml, comps_name=comps_name,
                    module_md=module_md, module_md_name=module_md_name
                )

            elif action == "delete_comps":
                CoprChrootsLogic.remove_comps(flask.g.user, chroot)

            elif action == "delete_module_md":
                CoprChrootsLogic.remove_module_md(flask.g.user, chroot)

            flask.flash(
                "Buildroot {0} in project {1} has been updated successfully.".format(
                    chroot_name, copr.name))

            db.session.commit()
        return flask.redirect(url_for_copr_edit(copr))

    else:
        flask.flash("You are not allowed to modify chroots.")
        return render_chroot_edit(copr, chroot_name)
예제 #6
0
def waiting():
    """
    Return list of waiting actions and builds.
    """

    # models.Actions
    actions_list = [
        action.to_dict(options={
            "__columns_except__": ["result", "message", "ended_on"]
        })
        for action in actions_logic.ActionsLogic.get_waiting()
    ]

    # tasks represented by models.BuildChroot with some other stuff
    builds_list = []
    for task in BuildsLogic.get_build_task_queue().limit(200):
        try:
            copr = task.build.copr

            # we are using fake username's here
            if copr.is_a_group_project:
                user_name = u"@{}".format(copr.group.name)
            else:
                user_name = copr.user.name

            record = {
                "task_id": task.task_id,
                "build_id": task.build.id,
                "project_owner": user_name,
                "project_name": task.build.copr.name,
                "submitter": task.build.user.name if task.build.user else None, # there is no user for webhook builds
                "pkgs": task.build.pkgs,  # TODO to be removed
                "chroot": task.mock_chroot.name,

                "repos": task.build.repos,
                "memory_reqs": task.build.memory_reqs,
                "timeout": task.build.timeout,
                "enable_net": task.build.enable_net,
                "git_repo": task.build.package.dist_git_repo,
                "git_hash": task.git_hash,
                "git_branch": helpers.chroot_to_branch(task.mock_chroot.name),
                "package_name": task.build.package.name,
                "package_version": task.build.pkg_version
            }
            copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name)
            if copr_chroot:
                record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs
            else:
                record["buildroot_pkgs"] = ""

            builds_list.append(record)

        except Exception as err:
            app.logger.exception(err)

    response_dict = {"actions": actions_list, "builds": builds_list}
    return flask.jsonify(response_dict)
예제 #7
0
def waiting():
    """
    Return list of waiting actions and builds.
    """

    # models.Actions
    actions_list = [
        action.to_dict(
            options={"__columns_except__": ["result", "message", "ended_on"]})
        for action in actions_logic.ActionsLogic.get_waiting()
    ]

    # tasks represented by models.BuildChroot with some other stuff
    builds_list = []
    for task in BuildsLogic.get_build_task_queue().limit(200):
        try:
            copr = task.build.copr

            # we are using fake username's here
            if copr.is_a_group_project:
                user_name = u"@{}".format(copr.group.name)
            else:
                user_name = copr.owner.name

            record = {
                "task_id": "{}-{}".format(task.build.id,
                                          task.mock_chroot.name),
                "build_id": task.build.id,
                "project_owner": user_name,
                "project_name": task.build.copr.name,
                "submitter": task.build.user.name,
                "pkgs": task.build.pkgs,  # TODO to be removed
                "chroot": task.mock_chroot.name,
                "repos": task.build.repos,
                "memory_reqs": task.build.memory_reqs,
                "timeout": task.build.timeout,
                "enable_net": task.build.enable_net,
                "git_repo": task.build.package.dist_git_repo,
                "git_hash": task.git_hash,
                "git_branch": helpers.chroot_to_branch(task.mock_chroot.name),
                "package_name": task.build.package.name,
                "package_version": task.build.pkg_version
            }
            copr_chroot = CoprChrootsLogic.get_by_name_safe(
                task.build.copr, task.mock_chroot.name)
            if copr_chroot:
                record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs
            else:
                record["buildroot_pkgs"] = ""

            builds_list.append(record)

        except Exception as err:
            app.logger.exception(err)

    response_dict = {"actions": actions_list, "builds": builds_list}
    return flask.jsonify(response_dict)
예제 #8
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"}
예제 #9
0
    def test_filter_outdated_to_be_deleted(self, f_users, f_coprs,
                                           f_mock_chroots, f_db):
        outdated = CoprChrootsLogic.filter_outdated_to_be_deleted(
            CoprChrootsLogic.get_multiple())
        assert outdated.all() == []

        # A chroot is supposed to be removed today (without a time specification)
        self.c2.copr_chroots[0].delete_after = date.today()
        assert outdated.all() == [self.c2.copr_chroots[0]]

        # A chroot should be deleted tomorrow, don't touch it yet
        self.c2.copr_chroots[0].delete_after = datetime.today() + timedelta(
            days=1)
        assert outdated.all() == []

        # A chroot was supposed to be deleted yesterday, delete it
        self.c2.copr_chroots[0].delete_after = datetime.today() - timedelta(
            days=1)
        assert outdated.all() == [self.c2.copr_chroots[0]]
예제 #10
0
    def test_filter_outdated(self, f_users, f_coprs, f_mock_chroots, f_db):
        outdated = CoprChrootsLogic.filter_outdated(
            CoprChrootsLogic.get_multiple())
        assert outdated.all() == []

        # A chroot is supposed to be removed today (without a time specification)
        # Do not notify anyone, it is already too late. For all intents and purposes,
        # the data is already gone.
        self.c2.copr_chroots[0].delete_after = date.today()
        assert outdated.all() == []

        # A chroot will be deleted tomorrow
        self.c2.copr_chroots[0].delete_after = datetime.today() + timedelta(
            days=1)
        assert outdated.all() == [self.c2.copr_chroots[0]]

        # A chroot was deleted yesterday
        self.c2.copr_chroots[0].delete_after = datetime.today() - timedelta(
            days=1)
        assert outdated.all() == []
예제 #11
0
파일: coprs_chroots.py 프로젝트: 0-T-0/copr
def process_chroot_update(copr, chroot_name):

    form = forms.ChrootForm()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    if not flask.g.user.can_build_in(copr):
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))

    if form.validate_on_submit():
        if "submit" in flask.request.form:
            action = flask.request.form["submit"]
            if action == "update":
                comps_name = comps_xml = None
                if form.comps.has_file():
                    comps_xml = form.comps.data.stream.read()
                    comps_name = form.comps.data.filename

                coprs_logic.CoprChrootsLogic.update_chroot(
                    flask.g.user, chroot, form.buildroot_pkgs.data,
                    comps=comps_xml, comps_name=comps_name)

            elif action == "delete_comps":
                CoprChrootsLogic.remove_comps(flask.g.user, chroot)

            flask.flash(
                "Buildroot {0} in project {1} has been updated successfully.".format(
                    chroot_name, copr.name))

            db.session.commit()
        return flask.redirect(url_for_copr_edit(copr))

    else:
        flask.flash("You are not allowed to modify chroots.")
        return render_chroot_edit(copr, chroot_name)
예제 #12
0
def build_config(build_chroot):
    config = generate_build_config(build_chroot.build.copr, build_chroot.name)
    copr_chroot = CoprChrootsLogic.get_by_name_safe(build_chroot.build.copr,
                                                    build_chroot.name)
    return {
        "repos": config.get("repos"),
        "additional_repos": generate_additional_repos(copr_chroot),
        "additional_packages": config.get("additional_packages"),
        "use_bootstrap_container": config.get("use_bootstrap_container"),
        "with_opts": config.get("with_opts"),
        "without_opts": config.get("without_opts"),
        "memory_limit": build_chroot.build.memory_reqs,
        "timeout": build_chroot.build.timeout,
        "enable_net": build_chroot.build.enable_net,
        "is_background": build_chroot.build.is_background,
    }
예제 #13
0
def waiting():
    """
    Return a single action and a single build.
    """
    action_record = None
    build_record = None

    action = actions_logic.ActionsLogic.get_waiting().first()
    if action:
        action_record = action.to_dict(options={
            "__columns_except__": ["result", "message", "ended_on"]
        })

    task = BuildsLogic.get_build_task()
    if task:
        try:
            build_record = {
                "task_id": task.task_id,
                "build_id": task.build.id,
                "project_owner": task.build.copr.owner_name,
                "project_name": task.build.copr.name,
                "submitter": task.build.user.name if task.build.user else None, # there is no user for webhook builds
                "pkgs": task.build.pkgs,  # TODO to be removed
                "chroot": task.mock_chroot.name,

                "repos": task.build.repos,
                "memory_reqs": task.build.memory_reqs,
                "timeout": task.build.timeout,
                "enable_net": task.build.enable_net,
                "git_repo": task.build.package.dist_git_repo,
                "git_hash": task.git_hash,
                "git_branch": helpers.chroot_to_branch(task.mock_chroot.name),
                "package_name": task.build.package.name,
                "package_version": task.build.pkg_version
            }

            copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name)
            if copr_chroot:
                build_record["buildroot_pkgs"] = copr_chroot.buildroot_pkgs
            else:
                build_record["buildroot_pkgs"] = ""

        except Exception as err:
            app.logger.exception(err)

    response_dict = {"action": action_record, "build": build_record}
    return flask.jsonify(response_dict)