Ejemplo n.º 1
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])
Ejemplo n.º 2
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")
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def send_rawhide_to_release(cls, data):
     action = models.Action(
         action_type=ActionTypeEnum("rawhide_to_release"),
         object_type="None",
         data=json.dumps(data),
         created_on=int(time.time()),
     )
     db.session.add(action)
Ejemplo n.º 5
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["ownername"] == username
        assert data_dict["projectname"] == coprname
Ejemplo n.º 6
0
    def unfinished_blocking_actions_for(cls, copr):
        blocking_actions = [ActionTypeEnum("delete")]

        actions = (models.Action.query.filter(
            models.Action.object_type ==
            "copr").filter(models.Action.object_id == copr.id).filter(
                models.Action.result == BackendResultEnum("waiting")).filter(
                    models.Action.action_type.in_(blocking_actions)))

        return actions
Ejemplo n.º 7
0
    def test_legal_flag_doesnt_block_copr_functionality(
            self, f_users, f_coprs, f_db):
        self.db.session.add(
            self.models.Action(object_type="copr",
                               object_id=self.c1.id,
                               action_type=ActionTypeEnum("legal-flag")))

        self.db.session.commit()
        # test will fail if this raises exception
        CoprsLogic.raise_if_unfinished_blocking_action(self.c1, "ha, failed")
Ejemplo n.º 8
0
    def get_waiting(cls):
        """
        Return actions that aren't finished
        """

        query = (models.Action.query.filter(
            models.Action.result == BackendResultEnum("waiting")).filter(
                models.Action.action_type != ActionTypeEnum("legal-flag")).
                 order_by(models.Action.created_on.asc()))

        return query
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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["ownername"] == self.u1.name
        assert data["projectname"] == name
Ejemplo n.º 12
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'}}
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    def send_create_gpg_key(cls, copr):
        """
        :type copr: models.Copr
        """

        data_dict = {
            "ownername": copr.owner_name,
            "projectname": copr.name,
        }

        action = models.Action(
            action_type=ActionTypeEnum("gen_gpg_key"),
            object_type="copr",
            data=json.dumps(data_dict),
            created_on=int(time.time()),
        )
        db.session.add(action)
Ejemplo n.º 15
0
 def test_fork_copr_projects_with_more_builds(self, mc_flask_g, f_users, f_fork_prepare, f_db):
     mc_flask_g.user.name = self.u2.name
     fc2, created = ComplexLogic.fork_copr(self.c2, 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': {'00000008-whatsupthere-world': '00000012', '00000006-hello-world': '00000013',
                         '00000010-new-package': '00000014', '00000011-new-package': '00000015'},
         'fedora-17-x86_64': {'8-whatsupthere-world': '00000012-whatsupthere-world',
                              '6-hello-world': '00000013-hello-world',
                              '10-new-package': '00000014-new-package'},
         'fedora-17-i386': {'8-whatsupthere-world': '00000012-whatsupthere-world',
                            '6-hello-world': '00000013-hello-world',
                            '11-new-package': '00000015-new-package'}}
Ejemplo n.º 16
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)
Ejemplo n.º 17
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)
Ejemplo n.º 18
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=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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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)