Пример #1
0
    def f_mock_chroots(self):
        self.mc1 = models.MockChroot(
            os_release="fedora", os_version="18", arch="x86_64", is_active=True)
        self.mc2 = models.MockChroot(
            os_release="fedora", os_version="17", arch="x86_64", is_active=True)
        self.mc3 = models.MockChroot(
            os_release="fedora", os_version="17", arch="i386", is_active=True)
        self.mc4 = models.MockChroot(
            os_release="fedora", os_version="rawhide", arch="i386", is_active=True)

        # only bind to coprs if the test has used the f_coprs fixture
        if hasattr(self, "c1"):
            cc1 = models.CoprChroot()
            cc1.mock_chroot = self.mc1
            # c1 foocopr with fedora-18-x86_64
            self.c1.copr_chroots.append(cc1)

            cc2 = models.CoprChroot()
            cc2.mock_chroot = self.mc2
            cc3 = models.CoprChroot()
            cc3.mock_chroot = self.mc3
            # c2 foocopr with fedora-17-i386 fedora-17-x86_64
            self.c2.copr_chroots.append(cc2)
            self.c2.copr_chroots.append(cc3)

            cc4 = models.CoprChroot()
            cc4.mock_chroot = self.mc4
            # c3 barcopr with fedora-rawhide-i386
            self.c3.copr_chroots.append(cc4)
            self.db.session.add_all([cc1, cc2, cc3, cc4])

        self.db.session.add_all([self.mc1, self.mc2, self.mc3, self.mc4])
Пример #2
0
    def test_chroot_alias(self, f_users, f_coprs, f_mock_chroots, f_db):
        # Test a chroot alias feature on a real-world example (RhBug: 1756632)

        mc_kwargs = dict(os_version="8",
                         arch="x86_64",
                         is_active=True,
                         distgit_branch=models.DistGitBranch(name="bar"))
        mc_epel = models.MockChroot(os_release="epel", **mc_kwargs)
        mc_rhelbeta = models.MockChroot(os_release="rhelbeta", **mc_kwargs)

        cc_epel = models.CoprChroot(mock_chroot=mc_epel)
        cc_rhelbeta = models.CoprChroot(mock_chroot=mc_rhelbeta)

        self.c1.copr_chroots = [cc_epel, cc_rhelbeta]
        self.db.session.commit()

        app.config["BACKEND_BASE_URL"] = "https://foo"
        with app.app_context():
            kwargs = dict(user=self.u1.username, copr=self.c1.name)
            url = "/coprs/{user}/{copr}/repo/{chroot}/"

            # Both chroots enabled, without alias
            r1 = self.tc.get(url.format(chroot="epel-8", **kwargs))
            r2 = self.tc.get(url.format(chroot="rhelbeta-8", **kwargs))
            assert "baseurl=https://foo/results/user1/foocopr/epel-8-$basearch/" in r1.data.decode(
                "utf-8")
            assert "baseurl=https://foo/results/user1/foocopr/rhelbeta-8-$basearch/" in r2.data.decode(
                "utf-8")

            # Both chroots enabled, alias defined
            app.config["CHROOT_NAME_RELEASE_ALIAS"] = {"epel-8": "rhelbeta-8"}
            r1 = self.tc.get(url.format(chroot="epel-8", **kwargs))
            r2 = self.tc.get(url.format(chroot="rhelbeta-8", **kwargs))
            assert "baseurl=https://foo/results/user1/foocopr/epel-8-$basearch/" in r1.data.decode(
                "utf-8")
            assert "baseurl=https://foo/results/user1/foocopr/rhelbeta-8-$basearch/" in r2.data.decode(
                "utf-8")

            # Only one chroot enabled, alias defined
            self.c1.copr_chroots = [cc_rhelbeta]
            self.db.session.commit()
            cache.clear()
            r1 = self.tc.get(url.format(chroot="epel-8", **kwargs))
            r2 = self.tc.get(url.format(chroot="rhelbeta-8", **kwargs))
            assert "baseurl=https://foo/results/user1/foocopr/rhelbeta-8-$basearch/" in r1.data.decode(
                "utf-8")
            assert "baseurl=https://foo/results/user1/foocopr/rhelbeta-8-$basearch/" in r2.data.decode(
                "utf-8")
Пример #3
0
    def f_mock_chroots_many(self):
        """
        Adds more chroots to self.c1
        """
        self.mc_list = []
        for arch in ["x86_64", "i386"]:
            for os_version in range(17, 22):
                mc = models.MockChroot(os_release="fedora",
                                       os_version=os_version,
                                       arch=arch,
                                       is_active=True)
                self.mc_list.append(mc)

            for os_version in [5, 6, 7]:
                mc = models.MockChroot(os_release="epel",
                                       os_version=os_version,
                                       arch=arch,
                                       is_active=True)
                self.mc_list.append(mc)

        self.mc_list[-1].is_active = False

        # only bind to coprs if the test has used the f_coprs fixture
        if hasattr(self, "c1"):
            for mc in self.mc_list:
                cc = models.CoprChroot()
                cc.mock_chroot = mc
                self.c1.copr_chroots.append(cc)

        self.db.session.add_all(self.mc_list)
Пример #4
0
    def test_regression_monitor_no_copr_returned(self, f_db, f_users,
                                                 f_mock_chroots):
        # https://bugzilla.redhat.com/show_bug.cgi?id=1165284

        # commit users to the database
        self.db.session.commit()
        copr_name = u"temp"

        # trying to get monitor page for non-existing project
        res = self.tc.get("/coprs/{}/{}/monitor/".format(
            self.u1.name, copr_name))
        assert res.status_code == 404

        tmp_copr = models.Copr(name=copr_name, owner=self.u1)
        cc = models.CoprChroot()
        cc.mock_chroot = self.mc1
        tmp_copr.copr_chroots.append(cc)

        self.db.session.add_all([tmp_copr, cc])
        self.db.session.commit()

        res = self.tc.get("/coprs/{}/{}/monitor/".format(
            self.u1.name, copr_name))
        assert res.status_code == 200

        self.db.session.add(CoprsLogic.delete_unsafe(self.u1, tmp_copr))
        self.db.session.commit()

        res = self.tc.get("/coprs/{}/{}/monitor/".format(
            self.u1.name, copr_name))
        assert res.status_code == 404
Пример #5
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)
Пример #6
0
    def create_chroot(cls,
                      user,
                      copr,
                      mock_chroot,
                      buildroot_pkgs=None,
                      repos=None,
                      comps=None,
                      comps_name=None,
                      with_opts="",
                      without_opts="",
                      delete_after=None,
                      delete_notify=None):
        """
        :type user: models.User
        :type mock_chroot: models.MockChroot
        """
        if buildroot_pkgs is None:
            buildroot_pkgs = ""
        if repos is None:
            repos = ""
        UsersLogic.raise_if_cant_update_copr(
            user, copr, "Only owners and admins may update their projects.")

        chroot = models.CoprChroot(copr=copr, mock_chroot=mock_chroot)
        cls._update_chroot(buildroot_pkgs, repos, comps, comps_name, chroot,
                           with_opts, without_opts, delete_after,
                           delete_notify)
        return chroot
Пример #7
0
    def f_mock_chroots(self):
        self.mc1 = models.MockChroot(
            os_release="fedora", os_version="18", arch="x86_64", is_active=True)
        self.mc1.distgit_branch = models.DistGitBranch(name='f18')

        self.mc2 = models.MockChroot(
            os_release="fedora", os_version="17", arch="x86_64", is_active=True,
            comment="A short chroot comment")
        self.mc2.distgit_branch = models.DistGitBranch(name='fedora-17')

        self.mc3 = models.MockChroot(
            os_release="fedora", os_version="17", arch="i386", is_active=True,
            comment="Chroot comment containing <a href='https://copr.fedorainfracloud.org/'>url with four words</a>")
        self.mc3.distgit_branch = self.mc2.distgit_branch

        self.mc4 = models.MockChroot(
            os_release="fedora", os_version="rawhide", arch="i386", is_active=True)
        self.mc4.distgit_branch = models.DistGitBranch(name='master')

        self.mc_basic_list = [self.mc1, self.mc2, self.mc3, self.mc4]
        # only bind to coprs if the test has used the f_coprs fixture
        if hasattr(self, "c1"):
            cc1 = models.CoprChroot()
            cc1.mock_chroot = self.mc1
            # c1 foocopr with fedora-18-x86_64
            self.c1.copr_chroots.append(cc1)

            cc2 = models.CoprChroot()
            cc2.mock_chroot = self.mc2
            cc3 = models.CoprChroot()
            cc3.mock_chroot = self.mc3
            # c2 foocopr with fedora-17-i386 fedora-17-x86_64
            self.c2.copr_chroots.append(cc2)
            self.c2.copr_chroots.append(cc3)

            cc4 = models.CoprChroot()
            cc4.mock_chroot = self.mc4
            # c3 barcopr with fedora-rawhide-i386
            self.c3.copr_chroots.append(cc4)
            self.db.session.add_all([cc1, cc2, cc3, cc4])

        self.db.session.add_all([self.mc1, self.mc2, self.mc3, self.mc4])
Пример #8
0
    def create_chroot(cls, user, copr, mock_chroot,
                      buildroot_pkgs=None, comps=None, comps_name=None):
        """
        :type user: models.User
        :type mock_chroot: models.MockChroot
        """
        if buildroot_pkgs is None:
            buildroot_pkgs = ""
        UsersLogic.raise_if_cant_update_copr(
            user, copr,
            "Only owners and admins may update their projects.")

        chroot = models.CoprChroot(copr=copr, mock_chroot=mock_chroot)
        cls._update_chroot(buildroot_pkgs, comps, comps_name, chroot)
        return chroot
Пример #9
0
    def update_from_names(cls, user, copr, names):
        current_chroots = copr.mock_chroots
        new_chroots = cls.mock_chroots_from_names(user, names)
        # add non-existing
        for mock_chroot in new_chroots:
            if mock_chroot not in current_chroots:
                db.session.add(
                    models.CoprChroot(copr=copr, mock_chroot=mock_chroot))

        # delete no more present
        to_remove = []
        for mock_chroot in current_chroots:
            if mock_chroot not in new_chroots:
                # 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)
Пример #10
0
    def f_mock_chroots_many(self):
        """
        Adds more chroots to self.c1
        Requires: f_mock_chroots
        """
        self.mc_list = []
        for arch in ["x86_64", "i386"]:
            for os_version in range(19, 24):
                mc = models.MockChroot(
                    os_release="fedora", os_version=os_version,
                    arch=arch, is_active=True)
                # Let's try slashes now. for example.  Some copr instances use
                # this pattern.
                mc.distgit_branch = BranchesLogic.get_or_create(
                        'fedora/{0}'.format(os_version),
                        session=self.db.session)
                self.mc_list.append(mc)

            for os_version in [5, 6, 7]:
                mc = models.MockChroot(
                    os_release="epel", os_version=os_version,
                    arch=arch, is_active=True)
                mc.distgit_branch = BranchesLogic.get_or_create(
                        'el{0}'.format(os_version),
                        session=self.db.session)
                self.mc_list.append(mc)

        self.mc_list[-1].is_active = False

        # only bind to coprs if the test has used the f_coprs fixture
        if hasattr(self, "c1"):
            for mc in self.mc_list:
                cc = models.CoprChroot()
                cc.mock_chroot = mc
                # TODO: why 'self.c1.copr_chroots.append(cc)' doesn't work here?
                cc.copr = self.c1

        self.db.session.add_all(self.mc_list)
Пример #11
0
 def new_from_names(cls, copr, names):
     for mock_chroot in cls.mock_chroots_from_names(names):
         db.session.add(
             models.CoprChroot(copr=copr, mock_chroot=mock_chroot))
Пример #12
0
    def new_from_names(cls, copr, names):
        for mock_chroot in cls.mock_chroots_from_names(names):
            db.session.add(
                models.CoprChroot(copr=copr, mock_chroot=mock_chroot))

        ActionsLogic.send_createrepo(copr)