Example #1
0
    def update_from_names(cls, user, copr, names):
        UsersLogic.raise_if_cant_update_copr(
            user, copr, "Only owners and admins may update their projects.")
        current_chroots = copr.mock_chroots
        new_chroots = cls.mock_chroots_from_names(names)
        # add non-existing
        run_createrepo = False
        for mock_chroot in new_chroots:
            if mock_chroot not in current_chroots:
                db.session.add(
                    models.CoprChroot(copr=copr, mock_chroot=mock_chroot))
                run_createrepo = True

        if run_createrepo:
            ActionsLogic.send_createrepo(copr)

        # delete no more present
        to_remove = []
        for mock_chroot in current_chroots:
            if mock_chroot in new_chroots:
                continue
            if not mock_chroot.is_active:
                continue
            # can't delete here, it would change current_chroots and break
            # iteration
            to_remove.append(mock_chroot)

        for mc in to_remove:
            copr.mock_chroots.remove(mc)
Example #2
0
    def test_delete_build_basic(self, f_users, f_coprs, f_mock_chroots,
                                f_builds, f_db):

        self.b1.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"
        expected_dir = self.b1.result_dir_name
        self.db.session.add(self.b1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert delete_data["result_dir_name"] == expected_dir
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #3
0
    def test_delete_build_as_admin(self, f_users, f_coprs, f_mock_chroots,
                                   f_builds, f_db):

        self.b4.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"
        expected_dir = self.b4.result_dir
        for bc in self.b4_bc:
            bc.status = StatusEnum("succeeded")
            bc.ended_on = time.time()

        self.u1.admin = True

        self.db.session.add_all(self.b4_bc)
        self.db.session.add(self.b4)
        self.db.session.add(self.u1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b4_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b4)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b4.id).one()
Example #4
0
    def add(cls,
            user,
            name,
            selected_chroots,
            repos=None,
            description=None,
            instructions=None,
            check_for_duplicates=False,
            group=None,
            **kwargs):
        copr = models.Copr(name=name,
                           repos=repos or u"",
                           owner_id=user.id,
                           description=description or u"",
                           instructions=instructions or u"",
                           created_on=int(time.time()),
                           **kwargs)

        if group is not None:
            UsersLogic.raise_if_not_in_group(user, group)
            copr.group = group

        # form validation checks for duplicates
        CoprsLogic.new(user, copr, check_for_duplicates=check_for_duplicates)
        CoprChrootsLogic.new_from_names(copr, selected_chroots)

        db.session.flush()
        ActionsLogic.send_create_gpg_key(copr)

        return copr
Example #5
0
    def test_delete_build_basic(self, f_users, f_coprs, f_mock_chroots,
                                f_builds, f_db):

        self.b1.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"
        expected_dir = self.b1.result_dir
        self.db.session.add(self.b1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert delete_data['chroot_builddirs'] == {
            'srpm-builds': ['bar'],
            'fedora-18-x86_64': ['bar']
        }

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #6
0
    def test_delete_build_as_admin(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

        self.b4.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"
        expected_dir = self.b4.result_dir_name
        for bc in self.b4_bc:
            bc.status = StatusEnum("succeeded")
            bc.ended_on = time.time()

        self.u1.admin = True

        self.db.session.add_all(self.b4_bc)
        self.db.session.add(self.b4)
        self.db.session.add(self.u1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b4_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b4)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert delete_data["result_dir_name"] == expected_dir
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b4.id).one()
Example #7
0
    def test_delete_build_basic(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

        self.b1.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"
        expected_dir = self.b1.result_dir_name
        self.db.session.add(self.b1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert delete_data["result_dir_name"] == expected_dir
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #8
0
    def _update_chroot(cls, buildroot_pkgs, repos, comps, comps_name,
                       copr_chroot, with_opts, without_opts, delete_after,
                       delete_notify):
        if buildroot_pkgs is not None:
            copr_chroot.buildroot_pkgs = buildroot_pkgs

        if repos is not None:
            copr_chroot.repos = repos.replace("\n", " ")

        if with_opts is not None:
            copr_chroot.with_opts = with_opts

        if without_opts is not None:
            copr_chroot.without_opts = without_opts

        if comps_name is not None:
            copr_chroot.update_comps(comps)
            copr_chroot.comps_name = comps_name
            ActionsLogic.send_update_comps(copr_chroot)

        if delete_after is not None:
            copr_chroot.delete_after = delete_after

        if delete_notify is not None:
            copr_chroot.delete_notify = delete_notify

        db.session.add(copr_chroot)
Example #9
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        created = (not bool(forking.get(copr, dstname)))
        fcopr = forking.fork_copr(copr, dstname)

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException(
                "Source project should not be same as destination")

        builds_map = {}
        for package in copr.main_dir.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build(successful=True)
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)

            if build.result_dir:
                builds_map['srpm-builds'] = (build.result_dir,
                                             fbuild.result_dir)

            for chroot, fchroot in zip(build.build_chroots,
                                       fbuild.build_chroots):
                if chroot.result_dir:
                    builds_map[chroot.name] = (chroot.result_dir,
                                               fchroot.result_dir)

        db.session.commit()
        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created
Example #10
0
    def test_project_delete_fail_unfinished_project_action(
            self, f_users, f_mock_chroots, f_coprs, f_users_api, f_db):

        ActionsLogic.send_delete_copr(self.c1)
        self.db.session.commit()
        href = "/api_2/projects/{}".format(self.c1.id)
        r0 = self.request_rest_api_with_auth(href, method="delete")
        assert r0.status_code == 400
Example #11
0
    def test_re_enable_auto_createrepo_produce_action(self, f_users, f_coprs,
                                                      f_mock_chroots, f_db):

        self.db.session.add_all(
            [self.u1, self.c1, self.mc1, self.mc2, self.mc3])

        username = self.u1.name
        coprname = self.c1.name
        copr_id = self.c1.id
        chroot = self.mc1.name

        # 1.ensure ACR enabled

        self.db.session.commit()
        c1_actual = CoprsLogic.get(self.u1.name, self.c1.name).one()
        assert c1_actual.auto_createrepo
        # 1. disabling ACR
        self.test_client.post("/coprs/{0}/{1}/update/".format(
            username, coprname),
                              data={
                                  "name": coprname,
                                  chroot: "y",
                                  "id": copr_id,
                                  "disable_createrepo": True
                              },
                              follow_redirects=True)
        self.db.session.commit()

        # check current status
        c1_actual = CoprsLogic.get(username, coprname).one()
        assert not c1_actual.auto_createrepo
        # no actions issued before
        assert len(ActionsLogic.get_many().all()) == 0

        # 2. enabling ACR
        self.test_client.post("/coprs/{0}/{1}/update/".format(
            username, coprname),
                              data={
                                  "name": coprname,
                                  chroot: "y",
                                  "id": copr_id,
                                  "disable_createrepo": "false"
                              },
                              follow_redirects=True)
        self.db.session.commit()

        c1_actual = CoprsLogic.get(username, coprname).one()

        # ACR enabled
        assert c1_actual.auto_createrepo
        # added action
        assert len(ActionsLogic.get_many().all()) > 0
        action = ActionsLogic.get_many(
            action_type=ActionTypeEnum("createrepo")).one()

        data_dict = json.loads(action.data)
        assert data_dict["username"] == username
        assert data_dict["projectname"] == coprname
Example #12
0
    def remove_comps(cls, user, copr_chroot):
        UsersLogic.raise_if_cant_update_copr(
            user, copr_chroot.copr,
            "Only owners and admins may update their projects.")

        copr_chroot.comps_name = None
        copr_chroot.comps_zlib = None
        ActionsLogic.send_update_comps(copr_chroot)
        db.session.add(copr_chroot)
Example #13
0
def on_auto_createrepo_change(target_copr, value_acr, old_value_acr,
                              initiator):
    """ Emit createrepo action when auto_createrepo re-enabled"""
    if old_value_acr == NEVER_SET:
        #  created new copr, not interesting
        return
    if not old_value_acr and value_acr:
        #  re-enabled
        ActionsLogic.send_createrepo(target_copr)
Example #14
0
    def remove_comps(cls, user, copr_chroot):
        UsersLogic.raise_if_cant_update_copr(
            user, copr_chroot.copr,
            "Only owners and admins may update their projects.")

        copr_chroot.comps_name = None
        copr_chroot.comps_zlib = None
        ActionsLogic.send_update_comps(copr_chroot)
        db.session.add(copr_chroot)
Example #15
0
    def test_delete_build_no_chroots_to_clean(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

        for bchroot in self.b1_bc:
            bchroot.status = helpers.StatusEnum("skipped")

        self.db.session.commit()
        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()
        assert len(ActionsLogic.get_many().all()) == 0
Example #16
0
    def delete_build(cls, user, build, send_delete_action=True):
        """
        :type user: models.User
        :type build: models.Build
        """
        cls.check_build_to_delete(user, build)

        if send_delete_action:
            ActionsLogic.send_delete_build(build)

        db.session.delete(build)
Example #17
0
    def test_delete_build_no_chroots_to_clean(self, f_users, f_coprs,
                                              f_mock_chroots, f_builds, f_db):

        for bchroot in self.b1_bc:
            bchroot.status = helpers.StatusEnum("skipped")

        self.db.session.commit()
        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()
        assert len(ActionsLogic.get_many().all()) == 0
Example #18
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        if dstgroup and not user.can_build_in_group(dstgroup):
            raise exceptions.InsufficientRightsException(
                "Only members may create projects in the particular groups.")

        fcopr = CoprsLogic.get_by_group_id(dstgroup.id, dstname).first() if dstgroup \
            else CoprsLogic.filter_without_group_projects(CoprsLogic.get(flask.g.user.name, dstname)).first()

        if fcopr:
            raise exceptions.DuplicateException("You already have {}/{} project".format(user.name, copr.name))

        # @TODO Move outside and properly test it
        def create_object(clazz, from_object, exclude=list()):
            arguments = {}
            for name, column in from_object.__mapper__.columns.items():
                if not name in exclude:
                    arguments[name] = getattr(from_object, name)
            return clazz(**arguments)

        fcopr = create_object(models.Copr, copr, exclude=["id", "group_id"])
        fcopr.forked_from_id = copr.id
        fcopr.owner = user
        fcopr.owner_id = user.id
        if dstname:
            fcopr.name = dstname
        if dstgroup:
            fcopr.group = dstgroup
            fcopr.group_id = dstgroup.id

        for chroot in list(copr.copr_chroots):
            CoprChrootsLogic.create_chroot(user, fcopr, chroot.mock_chroot, chroot.buildroot_pkgs,
                                           comps=chroot.comps, comps_name=chroot.comps_name)

        builds_map = {}
        for package in copr.packages:
            fpackage = create_object(models.Package, package, exclude=["id", "copr_id"])
            fpackage.copr = fcopr
            db.session.add(fpackage)

            build = package.last_build()
            if not build:
                continue

            fbuild = create_object(models.Build, build, exclude=["id", "copr_id", "package_id"])
            fbuild.copr = fcopr
            fbuild.package = fpackage
            fbuild.build_chroots = [create_object(models.BuildChroot, c, exclude=["id"]) for c in build.build_chroots]
            db.session.add(fbuild)
            builds_map[fbuild.id] = build.id

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        db.session.add(fcopr)
        return fcopr
Example #19
0
def on_auto_createrepo_change(target_copr, value_acr, old_value_acr, initiator):
    """ Emit createrepo action when auto_createrepo re-enabled"""
    if old_value_acr == NEVER_SET:
        #  created new copr, not interesting
        return
    if not old_value_acr and value_acr:
        #  re-enabled
        ActionsLogic.send_createrepo(
            target_copr.user.name,
            target_copr.name,
            chroots=[chroot.name for chroot in target_copr.active_chroots]
        )
Example #20
0
    def test_re_enable_auto_createrepo_produce_action(
            self, f_users, f_coprs, f_mock_chroots, f_db):

        self.db.session.add_all(
            [self.u1, self.c1, self.mc1, self.mc2, self.mc3])


        username = self.u1.name
        coprname = self.c1.name
        copr_id = self.c1.id
        chroot = self.mc1.name

        # 1.ensure ACR enabled

        self.db.session.commit()
        c1_actual = CoprsLogic.get(self.u1.name, self.c1.name).one()
        assert c1_actual.auto_createrepo
        # 1. disabling ACR
        self.test_client.post(
            "/coprs/{0}/{1}/update/".format(username, coprname),
            data={"name": coprname, chroot: "y", "id": copr_id,
                  "disable_createrepo": True},
            follow_redirects=True
        )
        self.db.session.commit()

        # check current status
        c1_actual = CoprsLogic.get(username, coprname).one()
        assert not c1_actual.auto_createrepo
        # no actions issued before
        assert len(ActionsLogic.get_many().all()) == 0

        # 2. enabling ACR
        self.test_client.post(
            "/coprs/{0}/{1}/update/".format(username, coprname),
            data={"name": coprname, chroot: "y", "id": copr_id,
                  "disable_createrepo": "false"},
            follow_redirects=True
        )
        self.db.session.commit()

        c1_actual = CoprsLogic.get(username, coprname).one()

        # ACR enabled
        assert c1_actual.auto_createrepo
        # added action
        assert len(ActionsLogic.get_many().all()) > 0
        action = ActionsLogic.get_many(action_type=ActionTypeEnum("createrepo")).one()

        data_dict = json.loads(action.data)
        assert data_dict["username"] == username
        assert data_dict["projectname"] == coprname
Example #21
0
    def _update_chroot(cls, buildroot_pkgs, comps, comps_name, module_md,
                       module_md_name, copr_chroot):
        copr_chroot.buildroot_pkgs = buildroot_pkgs

        if comps_name is not None:
            copr_chroot.update_comps(comps)
            copr_chroot.comps_name = comps_name
            ActionsLogic.send_update_comps(copr_chroot)

        if module_md_name is not None:
            copr_chroot.update_module_md(module_md)
            copr_chroot.module_md_name = module_md_name
            ActionsLogic.send_update_module_md(copr_chroot)
Example #22
0
    def add(cls,
            user,
            name,
            selected_chroots,
            repos=None,
            description=None,
            instructions=None,
            check_for_duplicates=False,
            group=None,
            persistent=False,
            auto_prune=True,
            use_bootstrap_container=False,
            follow_fedora_branching=False,
            **kwargs):

        if not user.admin and persistent:
            raise exceptions.NonAdminCannotCreatePersistentProject()

        if not user.admin and not auto_prune:
            raise exceptions.NonAdminCannotDisableAutoPrunning()

        # form validation checks for duplicates
        cls.new(user, name, group, check_for_duplicates=check_for_duplicates)

        copr = models.Copr(name=name,
                           repos=repos or u"",
                           user=user,
                           description=description or u"",
                           instructions=instructions or u"",
                           created_on=int(time.time()),
                           persistent=persistent,
                           auto_prune=auto_prune,
                           use_bootstrap_container=use_bootstrap_container,
                           follow_fedora_branching=follow_fedora_branching,
                           **kwargs)

        if group is not None:
            UsersLogic.raise_if_not_in_group(user, group)
            copr.group = group

        copr_dir = models.CoprDir(main=True, name=name, copr=copr)

        db.session.add(copr_dir)
        db.session.add(copr)

        CoprChrootsLogic.new_from_names(copr, selected_chroots)

        db.session.flush()
        ActionsLogic.send_create_gpg_key(copr)

        return copr
Example #23
0
def copr_build_module(copr):
    form = forms.ModuleFormUploadFactory(csrf_enabled=False)
    if not form.validate_on_submit():
        # @TODO Prettier error
        raise LegacyApiError(form.errors)

    modulemd = form.modulemd.data.read()
    ActionsLogic.send_build_module(copr, modulemd)
    db.session.commit()

    return flask.jsonify({
        "output": "ok",
        "message": "Module build was submitted",
        "modulemd": modulemd,
    })
Example #24
0
    def delete_unsafe(cls, user, copr):
        """
        Deletes copr without termination of ongoing builds.
        """
        cls.raise_if_cant_delete(user, copr)
        # TODO: do we want to dump the information somewhere, so that we can
        # search it in future?
        cls.raise_if_unfinished_blocking_action(
            copr, "Can't delete this project,"
            " another operation is in progress: {action}")

        ActionsLogic.send_delete_copr(copr)
        CoprDirsLogic.delete_all_by_copr(copr)

        copr.deleted = True
        return copr
Example #25
0
    def delete_multiple_builds(cls, user, builds):
        """
        :type user: models.User
        :type builds: list of models.Build
        """
        to_delete = []
        for build in builds:
            cls.check_build_to_delete(user, build)
            to_delete.append(build)

        if to_delete:
            ActionsLogic.send_delete_multiple_builds(to_delete)

        for build in to_delete:
            for build_chroot in build.build_chroots:
                db.session.delete(build_chroot)

            db.session.delete(build)
Example #26
0
    def test_fork_copr_sends_actions(self, mc_flask_g, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        mc_flask_g.user.name = self.u2.name
        fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
        self.db.session.commit()

        actions = ActionsLogic.get_many(ActionTypeEnum("gen_gpg_key")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["username"] == self.u2.name
        assert data["projectname"] == "dstname"

        actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["user"] == self.u2.name
        assert data["copr"] == "dstname"

        last_build, forked_build = self.c1.packages[0].builds[1], fc1.builds[0]
        assert data["builds_map"] == {str(forked_build.id): str(last_build.result_dir_name)}
Example #27
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        fcopr = forking.fork_copr(copr, dstname)
        created = fcopr in db.session.new

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException("Source project should not be same as destination")

        builds_map = {}
        for package in copr.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build()
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)
            builds_map[fbuild.id] = build.result_dir_name

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created
Example #28
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        created = (not bool(forking.get(copr, dstname)))
        fcopr = forking.fork_copr(copr, dstname)

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException("Source project should not be same as destination")

        builds_map = {}
        for package in copr.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build()
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)
            builds_map[fbuild.id] = build.result_dir_name

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created
Example #29
0
    def test_build_post_json_on_project_during_action(self, f_users, f_coprs,
                                                      f_db, f_mock_chroots,
                                                      f_mock_chroots_many,
                                                      f_build_many_chroots,
                                                      f_users_api):

        ActionsLogic.send_delete_copr(self.c1)
        chroot_name_list = [c.name for c in self.c1.active_chroots]
        metadata = {
            "project_id": 1,
            "srpm_url": "http://example.com/mypkg.src.rpm",
            "chroots": chroot_name_list
        }
        self.db.session.commit()
        r0 = self.request_rest_api_with_auth(
            "/api_2/builds",
            method="post",
            content=metadata,
        )
        assert r0.status_code == 400
Example #30
0
    def test_delete_build_basic(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #31
0
    def test_delete_build_basic(self, f_users, f_coprs, f_mock_chroots,
                                f_builds, f_db):
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #32
0
    def delete_build(cls, user, build, send_delete_action=True):
        """
        :type user: models.User
        :type build: models.Build
        """
        if not user.can_edit(build.copr) or build.persistent:
            raise InsufficientRightsException(
                "You are not allowed to delete build `{}`.".format(build.id))

        if not build.finished:
            raise ActionInProgressException(
                "You can not delete build `{}` which is not finished.".format(build.id),
                "Unfinished build")

        if send_delete_action:
            ActionsLogic.send_delete_build(build)

        for build_chroot in build.build_chroots:
            db.session.delete(build_chroot)

        db.session.delete(build)
Example #33
0
    def test_copr_logic_add_sends_create_gpg_key_action(self, f_users, f_mock_chroots, f_db):
        name = u"project_1"
        selected_chroots = [self.mc1.name]

        CoprsLogic.add(self.u1, name, selected_chroots)
        self.db.session.commit()

        actions = ActionsLogic.get_many(ActionTypeEnum("gen_gpg_key")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["username"] == self.u1.name
        assert data["projectname"] == name
Example #34
0
    def delete_build(cls, user, build, send_delete_action=True):
        """
        :type user: models.User
        :type build: models.Build
        """
        if not user.can_edit(build.copr):
            raise exceptions.InsufficientRightsException(
                "You are not allowed to delete build `{}`.".format(build.id))

        if not build.deletable:
            # from celery.contrib import rdb; rdb.set_trace()
            raise exceptions.ActionInProgressException(
                "You can not delete build `{}` which is not finished.".format(build.id),
                "Unfinished build")

        if send_delete_action and build.state not in ["canceled"]: # cancelled builds should have nothing in backend to delete
            ActionsLogic.send_delete_build(build)

        for build_chroot in build.build_chroots:
            db.session.delete(build_chroot)
        db.session.delete(build)
Example #35
0
    def delete_build(cls, user, build, send_delete_action=True):
        """
        :type user: models.User
        :type build: models.Build
        """
        if not user.can_edit(build.copr) or build.persistent:
            raise exceptions.InsufficientRightsException(
                "You are not allowed to delete build `{}`.".format(build.id))

        if not build.finished:
            # from celery.contrib import rdb; rdb.set_trace()
            raise exceptions.ActionInProgressException(
                "You can not delete build `{}` which is not finished.".format(build.id),
                "Unfinished build")

        if send_delete_action and build.state not in ["canceled"]: # cancelled builds should have nothing in backend to delete
            ActionsLogic.send_delete_build(build)

        for build_chroot in build.build_chroots:
            db.session.delete(build_chroot)
        db.session.delete(build)
Example #36
0
    def test_fork_copr_sends_actions(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        with app.app_context():
            with mock.patch('flask.g') as mc_flask_g:
                mc_flask_g.user.name = self.u2.name
                fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
                self.db.session.commit()

                actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
                assert len(actions) == 1
                data = json.loads(actions[0].data)
                assert data["user"] == self.u2.name
                assert data["copr"] == "dstname"
                assert data["builds_map"] == {'srpm-builds': {'bar': '00000005'},'fedora-18-x86_64': {'bar': '00000005-hello-world'}}
Example #37
0
    def test_delete_build_bad_src_pkg(self, f_users, f_coprs, f_mock_chroots,
                                      f_builds, f_db):

        # has meaning only for the builds with old result dir naming schema

        self.b1.pkgs = "http://example.com/"
        self.db.session.add(self.b1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            bchroot.git_hash = None
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 0

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #38
0
    def cancel_build(cls, user, build):
        if not user.can_build_in(build.copr):
            raise InsufficientRightsException(
                "You are not allowed to cancel this build.")
        if not build.cancelable:
            if build.status == StatusEnum("starting"):
                # this is not intuitive, that's why we provide more specific message
                err_msg = "Cannot cancel build {} in state 'starting'".format(build.id)
            else:
                err_msg = "Cannot cancel build {}".format(build.id)
            raise RequestCannotBeExecuted(err_msg)

        if build.status == StatusEnum("running"): # otherwise the build is just in frontend
            ActionsLogic.send_cancel_build(build)

        build.canceled = True
        cls.process_update_callback(build)

        for chroot in build.build_chroots:
            chroot.status = 2  # canceled
            if chroot.ended_on is not None:
                chroot.ended_on = time.time()
Example #39
0
    def add(cls, user, name, selected_chroots, repos=None, description=None,
            instructions=None, check_for_duplicates=False, group=None, **kwargs):
        copr = models.Copr(name=name,
                           repos=repos or u"",
                           user_id=user.id,
                           description=description or u"",
                           instructions=instructions or u"",
                           created_on=int(time.time()),
                           **kwargs)

        if group is not None:
            UsersLogic.raise_if_not_in_group(user, group)
            copr.group = group

        # form validation checks for duplicates
        cls.new(user, copr, check_for_duplicates=check_for_duplicates)
        CoprChrootsLogic.new_from_names(copr, selected_chroots)

        db.session.flush()
        ActionsLogic.send_create_gpg_key(copr)

        return copr
Example #40
0
    def test_delete_build_some_chroots(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

        expected_chroots_to_delete = set([self.b1_bc[0].name,
                                          self.b1_bc[-1].name])
        for bchroot in self.b1_bc[1:-1]:
            bchroot.status = helpers.StatusEnum("skipped")

        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #41
0
    def test_delete_build_bad_src_pkg(
            self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

        # has meaning only for the builds with old result dir naming schema

        self.b1.pkgs = "http://example.com/"
        self.db.session.add(self.b1)
        self.db.session.commit()

        expected_chroots_to_delete = set()
        for bchroot in self.b1_bc:
            bchroot.git_hash = None
            expected_chroots_to_delete.add(bchroot.name)

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 0

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #42
0
    def test_build_post_multipart_on_project_during_action(
            self, f_users, f_coprs, f_builds, f_db, f_mock_chroots,
            f_mock_chroots_many, f_build_many_chroots, f_users_api):

        ActionsLogic.send_delete_copr(self.c1)
        chroot_name_list = [c.name for c in self.c1.active_chroots]
        metadata = {
            "project_id": 1,
            "enable_net": True,
            "chroots": chroot_name_list
        }
        data = {
            "metadata": json.dumps(metadata),
            "srpm": (BytesIO(b'my file contents'), 'hello world.src.rpm')
        }
        self.db.session.commit()
        r0 = self.request_rest_api_with_auth(
            "/api_2/builds",
            method="post",
            content_type="multipart/form-data",
            data=data)
        assert r0.status_code == 400
Example #43
0
    def test_fork_copr_sends_actions(self, mc_flask_g, f_users, f_coprs,
                                     f_mock_chroots, f_builds, f_db):
        mc_flask_g.user.name = self.u2.name
        fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
        self.db.session.commit()

        actions = ActionsLogic.get_many(ActionTypeEnum("gen_gpg_key")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["username"] == self.u2.name
        assert data["projectname"] == "dstname"

        actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["user"] == self.u2.name
        assert data["copr"] == "dstname"

        last_build, forked_build = self.c1.packages[0].builds[1], fc1.builds[0]
        assert data["builds_map"] == {
            str(forked_build.id): str(last_build.result_dir_name)
        }
Example #44
0
    def test_delete_build_some_chroots(self, f_users, f_coprs, f_mock_chroots,
                                       f_builds, f_db):

        expected_chroots_to_delete = set(
            [self.b1_bc[0].name, self.b1_bc[-1].name])
        for bchroot in self.b1_bc[1:-1]:
            bchroot.status = helpers.StatusEnum("skipped")

        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 0
        BuildsLogic.delete_build(self.u1, self.b1)
        self.db.session.commit()

        assert len(ActionsLogic.get_many().all()) == 1
        action = ActionsLogic.get_many().one()
        delete_data = json.loads(action.data)
        assert "chroots" in delete_data
        assert expected_chroots_to_delete == set(delete_data["chroots"])

        with pytest.raises(NoResultFound):
            BuildsLogic.get(self.b1.id).one()
Example #45
0
 def _update_chroot(cls, buildroot_pkgs, comps, comps_name, copr_chroot):
     copr_chroot.buildroot_pkgs = buildroot_pkgs
     if comps_name is not None:
         copr_chroot.update_comps(comps)
         copr_chroot.comps_name = comps_name
         ActionsLogic.send_update_comps(copr_chroot)