Example #1
0
    def test_importing_queue_multiple_bg(self, f_users, f_coprs, f_mock_chroots, f_db):
        BuildsLogic.create_new_from_url(self.u1, self.c1, "foo", background=True)
        BuildsLogic.create_new_from_url(self.u1, self.c1, "bar", background=True)

        r = self.tc.get("/backend/importing/")
        data = json.loads(r.data)
        assert json.loads(data["builds"][0]["source_json"])["url"] == "foo"
Example #2
0
 def factory(**build_options):
     pkgs = form.pkgs.data.split("\n")
     for pkg in pkgs:
         BuildsLogic.create_new_from_url(
             flask.g.user, copr, pkg,
             chroot_names=form.selected_chroots,
             **build_options
         )
     for pkg in pkgs:
         flask.flash("New build has been created: {}".format(pkg), "success")
Example #3
0
 def factory(**build_options):
     pkgs = form.pkgs.data.split("\n")
     for pkg in pkgs:
         BuildsLogic.create_new_from_url(flask.g.user,
                                         copr,
                                         pkg,
                                         chroot_names=form.selected_chroots,
                                         **build_options)
     for pkg in pkgs:
         flask.flash("New build has been created: {}".format(pkg),
                     "success")
Example #4
0
    def test_bg_priority_in_queue(self, f_users, f_coprs, f_mock_chroots, f_db):
        BuildsLogic.create_new_from_url(self.u1, self.c1, "foo", background=True)
        BuildsLogic.create_new_from_url(self.u1, self.c1, "bar")

        self.tc.post("/backend/update/",
                         content_type="application/json",
                         headers=self.auth_header,
                         data=self.data)

        r = self.tc.get("/backend/importing/")
        data = json.loads(r.data.decode("utf-8"))
        assert data[0]["srpm_url"] == "http://bar"
Example #5
0
 def create_new_build():
     # create separate build for each package
     pkgs = form.pkgs.data.split("\n")
     return [BuildsLogic.create_new_from_url(
         flask.g.user, copr,
         srpm_url=pkg,
         chroot_names=form.selected_chroots,
     ) for pkg in pkgs]
Example #6
0
 def create_new_build():
     # create separate build for each package
     pkgs = form.pkgs.data.split("\n")
     return [BuildsLogic.create_new_from_url(
         flask.g.user, copr,
         url=pkg,
         chroot_names=form.selected_chroots,
         background=form.background.data,
         copr_dirname=form.project_dirname.data,
     ) for pkg in pkgs]
Example #7
0
def copr_new_build(copr):

    form = forms.BuildFormFactory.create_form_cls(
        copr.active_chroots)(csrf_enabled=False)

    # are there any arguments in POST which our form doesn't know?
    if any([
            post_key not in form.__dict__.keys()
            for post_key in flask.request.form.keys()
    ]):
        raise LegacyApiError(
            "Unknown arguments passed (non-existing chroot probably)")

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")

    if not flask.g.user.can_build_in(copr):
        raise LegacyApiError(
            "Invalid request: user {} is not allowed to build in the copr: {}".
            format(flask.g.user.username, copr))

    # we're checking authorization above for now
    # and also creating separate build for each package
    pkgs = form.pkgs.data.split("\n")

    ids = []
    for pkg in pkgs:
        try:
            build = BuildsLogic.create_new_from_url(
                flask.g.user,
                copr,
                srpm_url=pkg,
                chroot_names=form.selected_chroots,
            )
            db.session.commit()
        except ActionInProgressException as err:
            db.session.rollback()

            raise LegacyApiError(
                "Cannot create new build due to: {}".format(err))
        except InsufficientRightsException as err:
            db.session.rollback()
            raise LegacyApiError(
                "User {} cannot create build in project {}: {}".format(
                    flask.g.user.username, copr.full_name, err))

        ids.append(build.id)

    output = {
        "output": "ok",
        "ids": ids,
        "message": "Build was added to {0}.".format(copr.name)
    }

    return flask.jsonify(output)
Example #8
0
def process_new_build_url(copr, add_view, url_on_success):
    form = forms.BuildFormFactory.create_form_cls(copr.active_chroots)()

    if form.validate_on_submit():
        pkgs = form.pkgs.data.split("\n")

        if not pkgs:
            flask.flash("No builds submitted")
        else:
            # # check which chroots we need
            # chroots = []
            # for chroot in copr.active_chroots:
            #     if chroot.name in form.selected_chroots:
            #         chroots.append(chroot)

            # build each package as a separate build
            try:
                for pkg in pkgs:
                    build_options = {
                        "enable_net": form.enable_net.data,
                        "timeout": form.timeout.data,
                    }
                    BuildsLogic.create_new_from_url(
                        flask.g.user,
                        copr,
                        pkg,
                        chroot_names=form.selected_chroots,
                        **build_options)

            except (ActionInProgressException,
                    InsufficientRightsException) as e:
                flask.flash(str(e), "error")
                db.session.rollback()
            else:
                for pkg in pkgs:
                    flask.flash("New build has been created: {}".format(pkg))

                db.session.commit()

        return flask.redirect(url_on_success)
    else:
        return render_add_build(copr, form, add_view)
Example #9
0
 def create_new_build():
     # create separate build for each package
     pkgs = form.pkgs.data.split("\n")
     return [
         BuildsLogic.create_new_from_url(
             flask.g.user,
             copr,
             srpm_url=pkg,
             chroot_names=form.selected_chroots,
         ) for pkg in pkgs
     ]
Example #10
0
def process_new_build_url(copr, add_view, url_on_success):
    form = forms.BuildFormFactory.create_form_cls(copr.active_chroots)()

    if form.validate_on_submit():
        pkgs = form.pkgs.data.split("\n")

        if not pkgs:
            flask.flash("No builds submitted")
        else:
            # # check which chroots we need
            # chroots = []
            # for chroot in copr.active_chroots:
            #     if chroot.name in form.selected_chroots:
            #         chroots.append(chroot)

            # build each package as a separate build
            try:
                for pkg in pkgs:
                    build_options = {
                        "enable_net": form.enable_net.data,
                        "timeout": form.timeout.data,
                    }
                    BuildsLogic.create_new_from_url(
                        flask.g.user, copr, pkg,
                        chroot_names=form.selected_chroots,
                        **build_options
                    )

            except (ActionInProgressException, InsufficientRightsException) as e:
                flask.flash(str(e), "error")
                db.session.rollback()
            else:
                for pkg in pkgs:
                    flask.flash("New build has been created: {}".format(pkg))

                db.session.commit()

        return flask.redirect(url_on_success)
    else:
        return render_add_build(copr, form, add_view)
Example #11
0
def copr_new_build(copr):

    form = forms.BuildFormFactory.create_form_cls(
        copr.active_chroots)(csrf_enabled=False)

    # are there any arguments in POST which our form doesn't know?
    if any([post_key not in form.__dict__.keys()
            for post_key in flask.request.form.keys()]):
        raise LegacyApiError("Unknown arguments passed (non-existing chroot probably)")

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")

    if not flask.g.user.can_build_in(copr):
        raise LegacyApiError("Invalid request: user {} is not allowed to build in the copr: {}"
                             .format(flask.g.user.username, copr))

    # we're checking authorization above for now
    # and also creating separate build for each package
    pkgs = form.pkgs.data.split("\n")

    ids = []
    for pkg in pkgs:
        try:
            build = BuildsLogic.create_new_from_url(
                flask.g.user, copr,
                srpm_url=pkg,
                chroot_names=form.selected_chroots,
            )
            db.session.commit()
        except ActionInProgressException as err:
            db.session.rollback()

            raise LegacyApiError("Cannot create new build due to: {}".format(err))
        except InsufficientRightsException as err:
            db.session.rollback()
            raise LegacyApiError("User {} cannot create build in project {}: {}"
                                 .format(flask.g.user.username, copr.full_name, err))

        ids.append(build.id)

    output = {"output": "ok",
              "ids": ids,
              "message": "Build was added to {0}.".format(copr.name)}

    return flask.jsonify(output)