예제 #1
0
 def f_actions(self):
     # if using actions, we need to flush coprs into db, so that we can get
     # their ids
     self.f_db()
     self.a1 = models.Action(
         action_type=helpers.ActionTypeEnum("rename"),
         object_type="copr",
         object_id=self.c1.id,
         old_value="{0}/{1}".format(self.c1.user.name, self.c1.name),
         new_value="{0}/new_name".format(self.c1.user.name),
         created_on=int(time.time()))
     self.a2 = models.Action(
         action_type=helpers.ActionTypeEnum("rename"),
         object_type="copr",
         object_id=self.c2.id,
         old_value="{0}/{1}".format(self.c2.user.name, self.c2.name),
         new_value="{0}/new_name2".format(self.c2.user.name),
         created_on=int(time.time()))
     self.a3 = models.Action(action_type=helpers.ActionTypeEnum("delete"),
                             object_type="copr",
                             object_id=100,
                             old_value="asd/qwe",
                             new_value=None,
                             result=helpers.BackendResultEnum("success"),
                             created_on=int(time.time()))
     self.db.session.add_all([self.a1, self.a2, self.a3])
예제 #2
0
 def f_actions(self, f_db):
     self.delete_action = models.Action(action_type=ActionTypeEnum("delete"),
                                        object_type="copr",
                                        object_id=self.c1.id,
                                        old_value="asd/qwe",
                                        new_value=None,
                                        result=BackendResultEnum("waiting"),
                                        created_on=int(time.time()))
     self.cancel_build_action = models.Action(action_type=ActionTypeEnum("cancel_build"),
                                              data=json.dumps({'task_id': 123}),
                                              result=BackendResultEnum("waiting"),
                                              created_on=int(time.time()))
     self.db.session.add_all([self.delete_action, self.cancel_build_action])
예제 #3
0
    def send_build_module(cls, user, copr, modulemd):
        """
        :type copr: models.Copr
        :type modulemd: str content of module yaml file
        """

        if not user.can_build_in(copr):
            raise exceptions.InsufficientRightsException(
                "You don't have permissions to build in this copr.")

        modulemd_b64 = base64.b64encode(modulemd)
        data = {
            "ownername": copr.owner_name,
            "projectname": copr.name,
            "chroots": [c.name for c in copr.active_chroots],
            "modulemd_b64": modulemd_b64,
        }

        action = models.Action(
            action_type=helpers.ActionTypeEnum("build_module"),
            object_type="copr",
            old_value="",
            new_value="",
            data=json.dumps(data),
            created_on=int(time.time()),
        )
        db.session.add(action)
예제 #4
0
    def send_update_module_md(cls, chroot):
        """ Schedules update module_md.yaml action

        :type copr_chroot: models.CoprChroot
        """
        if chroot.copr.is_a_group_project:
            url_path = url_for('coprs_ns.group_chroot_view_module_md',
                               group_name=chroot.copr.group.name,
                               coprname=chroot.copr.name,
                               chrootname=chroot.name)
        else:
            url_path = url_for('coprs_ns.chroot_view_module_md',
                               username=chroot.copr.user.username,
                               coprname=chroot.copr.name,
                               chrootname=chroot.name)

        data_dict = {
            "ownername": chroot.copr.owner_name,
            "projectname": chroot.copr.name,
            "chroot": chroot.name,
            "module_md_present": chroot.module_md_zlib is not None,
            "url_path": url_path,
        }

        action = models.Action(
            action_type=helpers.ActionTypeEnum("update_module_md"),
            object_type="copr_chroot",
            data=json.dumps(data_dict),
            created_on=int(time.time()))
        db.session.add(action)
예제 #5
0
    def test_state(self, f_users, f_coprs, f_mock_chroots, f_builds, f_modules, f_db):
        self.b1.build_chroots[0].status = StatusEnum("pending")
        self.b3.build_chroots[0].status = StatusEnum("succeeded")
        self.b3.build_chroots[1].status = StatusEnum("succeeded")
        self.b3.source_status = StatusEnum("succeeded")

        # even though b3 is succeeded, b1 is still pending
        self.m1.builds = [self.b1, self.b3]
        assert self.m1.status == ModuleStatusEnum("pending")

        # now what if b1 succeeds
        self.b1.build_chroots[0].status = StatusEnum("succeeded")
        assert self.m1.status == ModuleStatusEnum("succeeded")

        # let's say that b3 failed
        self.b3.build_chroots[0].status = StatusEnum("failed")
        assert self.m1.status == ModuleStatusEnum("failed")


        # once the action exists, it dictates the status
        self.b3.build_chroots[0].status = StatusEnum("succeeded")
        action = models.Action(
            action_type=ActionTypeEnum("build_module"),
            object_type="module",
            object_id=self.m1.id,
        )
        db.session.add(action)
        assert self.m1.status == ModuleStatusEnum("waiting")

        # the backend proceeds the action
        action.result = BackendResultEnum("success")
        assert self.m1.status == ModuleStatusEnum("succeeded")
예제 #6
0
    def update(cls, user, copr, check_for_duplicates=True):
        cls.raise_if_unfinished_blocking_action(
            user, copr, "Can't change this project name,"
                        " another operation is in progress: {action}")

        users_logic.UsersLogic.raise_if_cant_update_copr(
            user, copr, "Only owners and admins may update their projects.")

        existing = cls.exists_for_user(copr.owner, copr.name).first()
        if existing:
            if check_for_duplicates and existing.id != copr.id:
                raise exceptions.DuplicateException(
                    "Project: '{0}' already exists".format(copr.name))

        else:  # we're renaming
            # if we fire a models.Copr.query, it will use the modified copr in session
            # -> workaround this by just getting the name
            old_copr_name = (db.session.query(models.Copr.name)
                             .filter(models.Copr.id == copr.id)
                             .filter(models.Copr.deleted == False)
                             .first()[0])

            action = models.Action(action_type=helpers.ActionTypeEnum("rename"),
                                   object_type="copr",
                                   object_id=copr.id,
                                   old_value="{0}/{1}".format(copr.owner.name,
                                                              old_copr_name),
                                   new_value="{0}/{1}".format(copr.owner.name,
                                                              copr.name),
                                   created_on=int(time.time()))
            db.session.add(action)
        db.session.add(copr)
예제 #7
0
 def send_createrepo(cls, copr, dirnames=None):
     possible_dirnames = [copr_dir.name for copr_dir in copr.dirs]
     if not dirnames:
         # by default we createrepo for all of them
         dirnames = possible_dirnames
     else:
         missing = set(dirnames) - set(possible_dirnames)
         if missing:
             raise exceptions.NotFoundException(
                 "Can't createrepo for {} dirnames in {} project".format(
                     missing, copr.full_name))
     data_dict = {
         "ownername": copr.owner_name,
         "projectname": copr.name,
         "project_dirnames": dirnames,
         "chroots": [chroot.name for chroot in copr.active_chroots],
     }
     action = models.Action(
         action_type=ActionTypeEnum("createrepo"),
         object_type="repository",
         object_id=0,
         data=json.dumps(data_dict),
         created_on=int(time.time()),
     )
     db.session.add(action)
예제 #8
0
    def send_delete_build(cls, build):
        """ Schedules build delete action
        :type build: models.Build
        """
        # don't delete skipped chroots
        chroots_to_delete = [
            chroot.name for chroot in build.build_chroots
            if chroot.state not in ["skipped"]
        ]
        if len(chroots_to_delete) == 0:
            return

        data_dict = {
            "username": build.copr.owner.name,
            "projectname": build.copr.name,
            "chroots": chroots_to_delete
        }

        if build.is_older_results_naming_used:
            if build.src_pkg_name is None or build.src_pkg_name == "":
                return
            data_dict["src_pkg_name"] = build.src_pkg_name
        else:
            data_dict["result_dir_name"] = build.result_dir_name

        action = models.Action(action_type=helpers.ActionTypeEnum("delete"),
                               object_type="build",
                               object_id=build.id,
                               old_value="{0}/{1}".format(
                                   build.copr.owner.name, build.copr.name),
                               data=json.dumps(data_dict),
                               created_on=int(time.time()))
        db.session.add(action)
예제 #9
0
 def send_rawhide_to_release(cls, data):
     action = models.Action(
         action_type=helpers.ActionTypeEnum("rawhide_to_release"),
         object_type="None",
         data=json.dumps(data),
         created_on=int(time.time()),
     )
     db.session.add(action)
예제 #10
0
파일: coprs_logic.py 프로젝트: rsuste/copr
 def create_delete_action(cls, copr):
     action = models.Action(action_type=helpers.ActionTypeEnum("delete"),
                            object_type="copr",
                            object_id=copr.id,
                            old_value=copr.full_name,
                            new_value="",
                            created_on=int(time.time()))
     db.session.add(action)
     return action
예제 #11
0
 def send_delete_copr(cls, copr):
     data_dict = {
         "ownername": copr.owner_name,
         "project_dirnames": [copr_dir.name for copr_dir in copr.dirs],
     }
     action = models.Action(action_type=ActionTypeEnum("delete"),
                            object_type="copr",
                            object_id=copr.id,
                            data=json.dumps(data_dict),
                            created_on=int(time.time()))
     db.session.add(action)
예제 #12
0
 def send_delete_build(cls, build):
     """
     Schedules build delete action
     :type build: models.Build
     """
     action = models.Action(action_type=ActionTypeEnum("delete"),
                            object_type="build",
                            object_id=build.id,
                            data=json.dumps(
                                cls.get_build_delete_data(build)),
                            created_on=int(time.time()))
     db.session.add(action)
예제 #13
0
 def send_createrepo(cls, username, coprname, chroots):
     data_dict = {
         "username": username,
         "projectname": coprname,
         "chroots": chroots
     }
     action = models.Action(
         action_type=helpers.ActionTypeEnum("createrepo"),
         object_type="None",
         object_id=0,
         old_value="",
         data=json.dumps(data_dict),
         created_on=int(time.time()),
     )
     db.session.add(action)
예제 #14
0
    def send_cancel_build(cls, build):
        """ Schedules build cancel action
        :type build: models.Build
        """
        for chroot in build.build_chroots:
            if chroot.state != "running":
                continue

            data_dict = {
                "task_id": chroot.task_id,
            }

            action = models.Action(action_type=ActionTypeEnum("cancel_build"),
                                   data=json.dumps(data_dict),
                                   created_on=int(time.time()))
            db.session.add(action)
예제 #15
0
    def send_fork_copr(cls, src, dst, builds_map):
        """
        :type src: models.Copr
        :type dst: models.Copr
        :type builds_map: dict where keys are forked builds IDs and values are IDs from the original builds.
        """

        action = models.Action(
            action_type=helpers.ActionTypeEnum("fork"),
            object_type="copr",
            old_value="{0}".format(src.full_name),
            new_value="{0}".format(dst.full_name),
            data=json.dumps({"user": dst.owner_name, "copr": dst.name, "builds_map": builds_map}),
            created_on=int(time.time()),
        )
        db.session.add(action)
예제 #16
0
    def send_create_gpg_key(cls, copr):
        """
        :type copr: models.Copr
        """

        data_dict = {
            "username": copr.owner.name,
            "projectname": copr.name,
        }

        action = models.Action(
            action_type=helpers.ActionTypeEnum("gen_gpg_key"),
            object_type="copr",
            data=json.dumps(data_dict),
            created_on=int(time.time()),
        )
        db.session.add(action)
예제 #17
0
    def send_delete_chroot(cls, copr_chroot):
        """
        Schedules deletion of a chroot directory from project
        Useful to remove outdated chroots
        :type build: models.CoprChroot
        """
        data_dict = {
            "ownername": copr_chroot.copr.owner_name,
            "projectname": copr_chroot.copr.name,
            "chrootname": copr_chroot.name,
        }

        action = models.Action(action_type=ActionTypeEnum("delete"),
                               object_type="chroot",
                               object_id=None,
                               data=json.dumps(data_dict),
                               created_on=int(time.time()))
        db.session.add(action)
예제 #18
0
    def send_update_comps(cls, chroot):
        """ Schedules update comps.xml action

        :type copr_chroot: models.CoprChroot
        """

        data_dict = {
            "username": chroot.copr.owner.name,
            "projectname": chroot.copr.name,
            "chroot": chroot.name,
            "comps_present": chroot.comps_zlib is not None,
        }

        action = models.Action(
            action_type=helpers.ActionTypeEnum("update_comps"),
            object_type="copr_chroot",
            data=json.dumps(data_dict),
            created_on=int(time.time()))
        db.session.add(action)
예제 #19
0
    def send_delete_multiple_builds(cls, builds):
        """
        Schedules builds delete action for builds belonging to the same project
        :type build: list of models.Build
        """
        project_dirnames = {}
        data = {'project_dirnames': project_dirnames}

        build_ids = []
        for build in builds:
            build_delete_data = cls.get_build_delete_data(build)
            build_ids.append(build.id)

            # inherit some params from the first build
            for param in ['ownername', 'projectname']:
                new = build_delete_data[param]
                if param in data and data[param] != new:
                    # this shouldn't happen
                    raise exceptions.BadRequest("Can not delete builds "
                                                "from more projects")
                data[param] = new

            dirname = build_delete_data['project_dirname']
            if not dirname in project_dirnames:
                project_dirnames[dirname] = {}

            project_dirname = project_dirnames[dirname]
            for chroot, subdirs in build_delete_data['chroot_builddirs'].items(
            ):
                if chroot not in project_dirname:
                    project_dirname[chroot] = subdirs
                else:
                    project_dirname[chroot].extend(subdirs)

        data['build_ids'] = build_ids

        # not object_id here, we are working with multiple IDs
        action = models.Action(action_type=ActionTypeEnum("delete"),
                               object_type="builds",
                               data=json.dumps(data),
                               created_on=int(time.time()))
        db.session.add(action)
예제 #20
0
    def delete(cls, user, copr, check_for_duplicates=True):
        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(
            user, copr, "Can't delete this project,"
                        " another operation is in progress: {action}")

        action = models.Action(action_type=helpers.ActionTypeEnum("delete"),
                               object_type="copr",
                               object_id=copr.id,
                               old_value="{0}/{1}".format(copr.owner.name,
                                                          copr.name),
                               new_value="",
                               created_on=int(time.time()))
        copr.deleted = True

        db.session.add(action)

        return copr
예제 #21
0
    def delete_build(cls, user, build):
        if not user.can_build_in(build.copr):
            raise exceptions.InsufficientRightsException(
                "You are not allowed to delete this build.")

        if not build.deletable:
            raise exceptions.ActionInProgressException(
                "You can not delete build which is not finished.",
                "Unfinished build")

        # Only failed, finished, succeeded  get here.
        if build.state not in ["cancelled"
                               ]:  # has nothing in backend to delete
            # don't delete skipped chroots
            chroots_to_delete = [
                chroot.name for chroot in build.build_chroots
                if chroot.state not in ["skipped"]
            ]

            if chroots_to_delete:
                data_dict = {
                    "pkgs": build.pkgs,
                    "username": build.copr.owner.name,
                    "projectname": build.copr.name,
                    "chroots": chroots_to_delete
                }

                action = models.Action(
                    action_type=helpers.ActionTypeEnum("delete"),
                    object_type="build",
                    object_id=build.id,
                    old_value="{0}/{1}".format(build.copr.owner.name,
                                               build.copr.name),
                    data=json.dumps(data_dict),
                    created_on=int(time.time()))
                db.session.add(action)

        for build_chroot in build.build_chroots:
            db.session.delete(build_chroot)
        db.session.delete(build)
예제 #22
0
    def send_update_comps(cls, chroot):
        """ Schedules update comps.xml action

        :type copr_chroot: models.CoprChroot
        """

        url_path = helpers.copr_url("coprs_ns.chroot_view_comps",
                                    chroot.copr,
                                    chrootname=chroot.name)
        data_dict = {
            "ownername": chroot.copr.owner_name,
            "projectname": chroot.copr.name,
            "chroot": chroot.name,
            "comps_present": chroot.comps_zlib is not None,
            "url_path": url_path,
        }

        action = models.Action(action_type=ActionTypeEnum("update_comps"),
                               object_type="copr_chroot",
                               data=json.dumps(data_dict),
                               created_on=int(time.time()))
        db.session.add(action)
예제 #23
0
    def send_build_module(cls, copr, modulemd):
        """
        :type copr: models.Copr
        :type modulemd: str content of module yaml file
        """

        modulemd_b64 = base64.b64encode(modulemd)
        data = {
            "ownername": copr.owner_name,
            "projectname": copr.name,
            "chroots": [c.name for c in copr.active_chroots],
            "modulemd_b64": modulemd_b64,
        }

        action = models.Action(
            action_type=helpers.ActionTypeEnum("build_module"),
            object_type="copr",
            old_value="",
            new_value="",
            data=json.dumps(data),
            created_on=int(time.time()),
        )
        db.session.add(action)
예제 #24
0
    def send_build_module(cls, copr, module):
        """
        :type copr: models.Copr
        :type modulemd: str content of module yaml file
        """

        mock_chroots = set.intersection(
            *[set(b.chroots) for b in module.builds])
        data = {
            "chroots": [ch.name for ch in mock_chroots],
            "builds": [b.id for b in module.builds],
        }

        action = models.Action(
            action_type=ActionTypeEnum("build_module"),
            object_type="module",
            object_id=module.id,
            old_value="",
            new_value="",
            data=json.dumps(data),
            created_on=int(time.time()),
        )
        db.session.add(action)