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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
def test_add_only_adds_active_chroots(self, f_users, f_coprs, f_builds, f_mock_chroots, f_db): self.mc2.is_active = False self.db.session.commit() b = BuildsLogic.add(self.u2, "blah", self.c2) self.db.session.commit() build_id = b.id expected_name = self.mc3.name assert len(b.chroots) == 0 self.tc.post("/backend/update/", content_type="application/json", headers=self.auth_header, data=self.data) b = BuildsLogic.get(build_id).first() assert len(b.chroots) == 1 assert b.chroots[0].name == expected_name
def split_one(orig_build_id): from coprs import db from coprs import models from coprs.logic.builds_logic import BuildsLogic from coprs.models import BuildChroot def clone_build(build): other = models.Build( pkgs=build.pkgs, built_packages=build.built_packages, pkg_version=build.pkg_version, canceled=build.canceled, repos=build.repos, submitted_on=build.submitted_on, started_on=build.started_on, ended_on=build.ended_on, results=build.results, memory_reqs=build.memory_reqs, timeout=build.timeout, enable_net=build.enable_net, user=build.user, copr=build.copr, ) return other def set_src_pkg(build_, src_pkg_): db.session.rollback() # some dirty state in SQLalchemy, no idea how to do correctly build_.pkgs = src_pkg_ db.session.add(build_) db.session.commit() log.info("Fixed spaces for build id={}, src_pkg={}".format(build_.id, src_pkg_)) build = BuildsLogic.get(orig_build_id).one() log.info("Start splitting build: {}, pkgs: {}".format(build.id, build.pkgs)) src_pkg_list = [] for mb_pkg in build.pkgs.strip().split(" "): src_pkg_list.append(mb_pkg) if len(src_pkg_list) == 0: log.error("> Got build with empty pkgs: id={}".format(build.id)) return if len(src_pkg_list) == 1: log.info("> Got build with one pkg in pkgs, id={}, pkgs={}".format(build.id, build.pkgs)) set_src_pkg(build, src_pkg_list[0]) return new_builds = [] new_build_chroots = [] for src_pkg in src_pkg_list: log.info("> Processing {} package".format(src_pkg)) new_build = clone_build(build) new_build.pkgs = src_pkg for bc in build.build_chroots: log.info("> > Copying chroot {}".format(bc.name)) new_bc = BuildChroot( build=new_build, mock_chroot=bc.mock_chroot, status=bc.status ) new_build_chroots.append(new_bc) new_builds.append(new_build) log.info("> Finished build split for id: {}. Doing commit".format(build.id)) db.session.rollback() # some dirty state in SQLalchemy, no idea how to do correctly db.session.add_all(new_build_chroots) db.session.add_all(new_builds) for bc in build.build_chroots: db.session.delete(bc) db.session.delete(build) db.session.commit() log.info("> New build objects were created ") log.info("> Build {} deleted ".format(build.id))
def split_one(orig_build_id): from coprs import db from coprs import models from coprs.logic.builds_logic import BuildsLogic from coprs.models import BuildChroot def clone_build(build): other = models.Build( pkgs=build.pkgs, built_packages=build.built_packages, pkg_version=build.pkg_version, canceled=build.canceled, repos=build.repos, submitted_on=build.submitted_on, started_on=build.started_on, ended_on=build.ended_on, results=build.results, memory_reqs=build.memory_reqs, timeout=build.timeout, enable_net=build.enable_net, user=build.user, copr=build.copr, ) return other def set_src_pkg(build_, src_pkg_): db.session.rollback( ) # some dirty state in SQLalchemy, no idea how to do correctly build_.pkgs = src_pkg_ db.session.add(build_) db.session.commit() log.info("Fixed spaces for build id={}, src_pkg={}".format( build_.id, src_pkg_)) build = BuildsLogic.get(orig_build_id).one() log.info("Start splitting build: {}, pkgs: {}".format( build.id, build.pkgs)) src_pkg_list = [] for mb_pkg in build.pkgs.strip().split(" "): src_pkg_list.append(mb_pkg) if len(src_pkg_list) == 0: log.error("> Got build with empty pkgs: id={}".format(build.id)) return if len(src_pkg_list) == 1: log.info("> Got build with one pkg in pkgs, id={}, pkgs={}".format( build.id, build.pkgs)) set_src_pkg(build, src_pkg_list[0]) return new_builds = [] new_build_chroots = [] for src_pkg in src_pkg_list: log.info("> Processing {} package".format(src_pkg)) new_build = clone_build(build) new_build.pkgs = src_pkg for bc in build.build_chroots: log.info("> > Copying chroot {}".format(bc.name)) new_bc = BuildChroot(build=new_build, mock_chroot=bc.mock_chroot, status=bc.status) new_build_chroots.append(new_bc) new_builds.append(new_build) log.info("> Finished build split for id: {}. Doing commit".format( build.id)) db.session.rollback( ) # some dirty state in SQLalchemy, no idea how to do correctly db.session.add_all(new_build_chroots) db.session.add_all(new_builds) for bc in build.build_chroots: db.session.delete(bc) db.session.delete(build) db.session.commit() log.info("> New build objects were created ") log.info("> Build {} deleted ".format(build.id))