def test_action_run_delete_copr(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() test_action = Action( action={ "action_type": ActionType.DELETE, "object_type": "copr", "id": 6, "old_value": "old_dir", }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=os.path.join(tmp_dir, "dir-not-exists"), front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 6 assert result_dict["result"] == ActionResult.SUCCESS assert result_dict["job_ended_on"] == self.test_time event_dict = self.test_q.get_nowait() assert event_dict["what"] == "Action delete copr" assert event_dict["who"] == "action" assert event_dict["when"] == self.test_time with pytest.raises(EmptyQueue): self.test_q.get_nowait() assert os.path.exists(os.path.join(tmp_dir, "old_dir"))
def test_delete_build_succeeded_createrepo_error(self, mc_createrepo, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() mc_createrepo.return_value = (1, "", "Create repo failed") # mc_createrepo.side_effect = IOError() tmp_dir = self.make_temp_dir() chroot_1_dir = os.path.join(tmp_dir, "old_dir", "fedora20") os.mkdir(chroot_1_dir) foo_pkg_dir = os.path.join(chroot_1_dir, "foo") os.mkdir(foo_pkg_dir) chroot_2_dir = os.path.join(tmp_dir, "old_dir", "epel7") os.mkdir(chroot_2_dir) with open(os.path.join(chroot_1_dir, "foo", "foo.src.rpm"), "w") as fh: fh.write("foo\n") self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42, }, frontend_client=mc_front_cb, ) test_action.run()
def test_action_run_rename_success_on_empty_src(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() test_action = Action( action={ "action_type": ActionType.RENAME, "id": 1, "old_value": "old_dir", "new_value": "new_dir" }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=os.path.join(tmp_dir, "dir-not-exists"), front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 1 assert result_dict["result"] == ActionResult.SUCCESS assert result_dict["job_ended_on"] == self.test_time assert os.path.exists(os.path.join(tmp_dir, "old_dir"))
def test_action_run_delete_copr(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() self.opts.destdir = os.path.join(tmp_dir, "dir-not-exists") test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "copr", "id": 6, "old_value": "old_dir", }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 6 assert result_dict["result"] == ActionResult.SUCCESS assert result_dict["job_ended_on"] == self.test_time assert os.path.exists(os.path.join(tmp_dir, "old_dir"))
def test_handle_createrepo_failure_3(self, mc_createrepo, mc_time): mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() mc_createrepo.side_effect = [ STDOUT, CreateRepoError("test exception", ["foo", "bar"], 1), ] action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "username": "******", "projectname": "bar" }) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 10 }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 10 assert result_dict["result"] == ActionResult.FAILURE
def test_action_run_rename_success_on_empty_src(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() self.opts.destdir = os.path.join(tmp_dir, "dir-not-exists") test_action = Action( opts=self.opts, action={ "action_type": ActionType.RENAME, "id": 1, "old_value": "old_dir", "new_value": "new_dir" }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 1 assert result_dict["result"] == ActionResult.SUCCESS assert result_dict["job_ended_on"] == self.test_time assert os.path.exists(os.path.join(tmp_dir, "old_dir"))
def test_action_run_rename_failure_on_destination_exists(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() with open(os.path.join(self.tmp_dir_name, "old_dir", "foobar.txt"), "w") as handle: handle.write(self.test_content) os.mkdir(os.path.join(tmp_dir, "new_dir")) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.RENAME, "id": 1, "old_value": "old_dir", "new_value": "new_dir" }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 1 assert result_dict["result"] == ActionResult.FAILURE assert result_dict["message"] == "Destination directory already exist." assert result_dict["job_ended_on"] == self.test_time assert os.path.exists(os.path.join(tmp_dir, "old_dir")) assert os.path.exists(os.path.join(tmp_dir, "new_dir")) assert not os.path.exists( os.path.join(tmp_dir, "new_dir", "foobar.txt"))
def test_action_run_rename(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() with open(os.path.join(self.tmp_dir_name, "old_dir", "foobar.txt"), "w") as handle: handle.write(self.test_content) test_action = Action( action={ "action_type": ActionType.RENAME, "id": 1, "old_value": "old_dir", "new_value": "new_dir" }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 1 assert result_dict["result"] == ActionResult.SUCCESS assert result_dict["job_ended_on"] == self.test_time assert not os.path.exists(os.path.join(tmp_dir, "old_dir")) assert os.path.exists(os.path.join(tmp_dir, "new_dir")) assert os.path.exists(os.path.join(tmp_dir, "new_dir", "foobar.txt")) with open(os.path.join(tmp_dir, "new_dir", "foobar.txt")) as handle: assert handle.read() == self.test_content
def test_handle_createrepo_ok(self, mc_createrepo_unsafe, mc_time): mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() mc_createrepo_unsafe.return_value = 0, STDOUT, "" action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "username": "******", "projectname": "bar" }) test_action = Action( action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 8 }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 8 assert result_dict["result"] == ActionResult.SUCCESS exp_call_1 = mock.call(lock=None, path=tmp_dir + u'/foo/bar/epel-6-i386') exp_call_2 = mock.call(lock=None, path=tmp_dir + u'/foo/bar/fedora-20-x86_64') assert exp_call_1 in mc_createrepo_unsafe.call_args_list assert exp_call_2 in mc_createrepo_unsafe.call_args_list assert len(mc_createrepo_unsafe.call_args_list) == 2
def test_delete_build_succeeded_createrepo_error(self, mc_devel, mc_call_repo, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() mc_call_repo.return_value = 0 tmp_dir = self.make_temp_dir() chroot_1_dir = os.path.join(tmp_dir, "foo", "bar", "fedora20") foo_pkg_dir = os.path.join(chroot_1_dir, "foo") os.makedirs(foo_pkg_dir) chroot_2_dir = os.path.join(tmp_dir, "foo", "bar", "epel7") os.mkdir(chroot_2_dir) with open(os.path.join(foo_pkg_dir, "foo.src.rpm"), "w") as fh: fh.write("foo\n") self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42, }, ) # just fail assert test_action.run().result == ActionResult.FAILURE
def test_action_run_delete_copr(self, mc_time): tmp_dir = self.make_temp_dir() self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "copr", "id": 6, # baz doesn't exist "data": json.dumps({ "ownername": "foo", "project_dirnames": ["bar", "baz"], }), }, ) assert os.path.exists(os.path.join(tmp_dir, "foo", "bar")) assert not os.path.exists(os.path.join(tmp_dir, "foo", "baz")) assert test_action.run().result == ActionResult.SUCCESS assert os.path.exists(os.path.join(tmp_dir, "old_dir")) assert not os.path.exists(os.path.join(tmp_dir, "foo", "bar"))
def test_handle_createrepo_ok(self, mc_devel, mc_sp_call, mc_time, devel): mc_sp_call.return_value = 0 # exit_status=0 mc_devel.return_value = devel tmp_dir = self.make_temp_dir() action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "ownername": "foo", "projectname": "bar", "project_dirnames": ["bar"] }) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 8 }, ) assert test_action.run().result == ActionResult.SUCCESS for chroot in ['fedora-20-x86_64', 'epel-6-i386']: cmd = ['copr-repo', os.path.join(self.test_project_dir, chroot)] exp_call = mock.call(cmd, timeout=None) assert exp_call in mc_sp_call.call_args_list assert len(mc_sp_call.call_args_list) == 2
def test_handle_createrepo_failure_3(self, mc_createrepo_unsfe, mc_time): mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() mc_createrepo_unsfe.side_effect = [ (0, STDOUT, ""), (1, STDOUT, STDERR), ] action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "username": "******", "projectname": "bar" }) test_action = Action( action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 10 }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 10 assert result_dict["result"] == ActionResult.FAILURE
def test_action_run_rename_failure_on_destination_exists(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() with open(os.path.join(self.tmp_dir_name, "old_dir", "foobar.txt"), "w") as handle: handle.write(self.test_content) os.mkdir(os.path.join(tmp_dir, "new_dir")) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.RENAME, "id": 1, "old_value": "old_dir", "new_value": "new_dir" }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 1 assert result_dict["result"] == ActionResult.FAILURE assert result_dict["message"] == "Destination directory already exist." assert result_dict["job_ended_on"] == self.test_time assert os.path.exists(os.path.join(tmp_dir, "old_dir")) assert os.path.exists(os.path.join(tmp_dir, "new_dir")) assert not os.path.exists(os.path.join(tmp_dir, "new_dir", "foobar.txt"))
def test_delete_two_chroots(self, mc_createrepo, mc_time): """ Regression test, https://bugzilla.redhat.com/show_bug.cgi?id=1171796 """ mc_createrepo.return_value = 0, STDOUT, "" resource_name = "1171796.tar.gz" self.unpack_resource(resource_name) chroot_20_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-21-x86_64") assert os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps( { "src_pkg_name": "rubygem-log4r-1.1.10-2.fc21", "username": "******", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"], } ), }, frontend_client=mc_front_cb, ) test_action.run() assert not os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert not os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert not os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_delete_two_chroots(self, mc_createrepo, mc_time): """ Regression test, https://bugzilla.redhat.com/show_bug.cgi?id=1171796 """ mc_createrepo.return_value = 0, STDOUT, "" resource_name = "1171796.tar.gz" self.unpack_resource(resource_name) chroot_20_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-21-x86_64") assert os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "src_pkg_name": "rubygem-log4r-1.1.10-2.fc21", "username": "******", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"] }), }, frontend_client=mc_front_cb, ) test_action.run() assert not os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert not os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert not os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_action_run_legal_flag(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() test_action = Action( opts=self.opts, action={"action_type": ActionType.LEGAL_FLAG, "id": 1}, frontend_client=mc_front_cb ) test_action.run() assert not mc_front_cb.called self.dummy = str(test_action)
def test_delete_two_chroots(self, mc_createrepo_unsafe, mc_time): """ Regression test, https://bugzilla.redhat.com/show_bug.cgi?id=1171796 """ mc_createrepo_unsafe.return_value = 0, STDOUT, "" resource_name = "1171796.tar.gz" self.unpack_resource(resource_name) chroot_20_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-21-x86_64") assert os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() test_action = Action( action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "pkgs": "rubygem-log4r-1.1.10-2.fc21.src.rpm", "username": "******", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"] }), }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=self.tmp_dir_name, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() assert not os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_20_path, "build-15.rsync.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.rsync.log")) assert not os.path.isdir(os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert not os.path.isdir(os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21"))
def test_action_run_legal_flag(self, mc_time): mc_time.time.return_value = self.test_time test_action = Action( opts=self.opts, action={ "action_type": ActionType.LEGAL_FLAG, "id": 1 }, ) test_action.run() self.dummy = str(test_action)
def test_delete_build_succeeded(self, mc_createrepo, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() mc_createrepo.return_value = (0, "", "") # mc_createrepo.side_effect = IOError() tmp_dir = self.make_temp_dir() chroot_1_dir = os.path.join(tmp_dir, "old_dir", "fedora20") os.mkdir(chroot_1_dir) foo_pkg_dir = os.path.join(chroot_1_dir, "foo") os.mkdir(foo_pkg_dir) chroot_2_dir = os.path.join(tmp_dir, "old_dir", "epel7") os.mkdir(chroot_2_dir) with open(os.path.join(chroot_1_dir, "foo", "foo.src.rpm"), "w") as fh: fh.write("foo\n") log_path = os.path.join(chroot_1_dir, "build-42.log") with open(log_path, "w") as fh: fh.write(self.test_content) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42 }, frontend_client=mc_front_cb, ) assert os.path.exists(foo_pkg_dir) test_action.run() assert not os.path.exists(foo_pkg_dir) assert not os.path.exists(log_path) assert os.path.exists(chroot_1_dir) assert os.path.exists(chroot_2_dir) create_repo_expected_call = mock.call( username=u'foo', projectname=u'bar', base_url=u'http://example.com/results/foo/bar/fedora20', path='{}/old_dir/fedora20'.format(self.tmp_dir_name), front_url=None ) assert mc_createrepo.call_args == create_repo_expected_call
def test_action_run_legal_flag(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() test_action = Action( opts=self.opts, action={ "action_type": ActionType.LEGAL_FLAG, "id": 1 }, frontend_client=mc_front_cb, ) test_action.run() assert not mc_front_cb.called self.dummy = str(test_action)
def test_delete_build_with_bad_pkg_name(self, mc_createrepo, mc_time): """ regression: https://bugzilla.redhat.com/show_bug.cgi?id=1203753 """ mc_time.time.return_value = self.test_time resource_name = "1171796_doubled.tar.gz" self.unpack_resource(resource_name) chroot_20_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-21-x86_64") mc_createrepo.return_value = 0, STDOUT, "" mc_front_cb = MagicMock() self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "src_pkg_name": "", "username": "******", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"] }), }, frontend_client=mc_front_cb, ) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path) test_action.run() # shouldn't touch chroot dirs assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_delete_build_with_bad_pkg_name(self, mc_time): """ Originally written for regression: https://bugzilla.redhat.com/show_bug.cgi?id=1203753 But we nowadays donjt send src_pkg_name at all. """ mc_time.time.return_value = self.test_time self.unpack_resource("1171796_doubled.tar.gz") chroot_20_path = os.path.join(self.tmp_dir_name, "foo", "bar", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "foo", "bar", "fedora-21-x86_64") self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "src_pkg_name": "", "ownername": "foo", "projectname": "bar", "project_dirname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"] }), }, ) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path) result = test_action.run() assert result.result == ActionResult.FAILURE # shouldn't touch chroot dirs assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_delete_no_chroot_dirs(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() self.opts.destdir = tmp_dir test_action = Action(opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "not-existing-project", "data": self.ext_data_for_delete_build, }, frontend_client=mc_front_cb) with mock.patch("backend.actions.shutil") as mc_shutil: test_action.run() assert not mc_shutil.rmtree.called
def test_delete_multiple_builds_succeeded(self, mc_build_devel, mc_time): mc_time.time.return_value = self.test_time mc_build_devel.return_value = False tmp_dir = self.make_temp_dir() chroot_dir = os.path.join(tmp_dir, "foo", "bar", "fedora-20") os.makedirs(chroot_dir) pkg_build_1_dir = os.path.join(chroot_dir, "01-foo") pkg_build_2_dir = os.path.join(chroot_dir, "02-foo") pkg_build_3_dir = os.path.join(chroot_dir, "03-foo") os.mkdir(pkg_build_1_dir) os.mkdir(pkg_build_2_dir) os.mkdir(pkg_build_3_dir) ext_data = json.dumps({ "ownername": "foo", "projectname": "bar", "project_dirnames": { 'bar': { "fedora-20": ["01-foo", "02-foo"], } }, "build_ids": ['01', '02'], }) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "builds", "id": 7, "data": ext_data, }, ) assert os.path.exists(pkg_build_1_dir) assert os.path.exists(pkg_build_2_dir) test_action.run() assert not os.path.exists(pkg_build_1_dir) assert not os.path.exists(pkg_build_2_dir) assert os.path.exists(chroot_dir) assert os.path.exists(pkg_build_3_dir)
def test_delete_build_succeeded_createrepo_error(self, mc_createrepo, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() mc_createrepo.return_value = (1, "", "Create repo failed") # mc_createrepo.side_effect = IOError() tmp_dir = self.make_temp_dir() chroot_1_dir = os.path.join(tmp_dir, "old_dir", "fedora20") os.mkdir(chroot_1_dir) foo_pkg_dir = os.path.join(chroot_1_dir, "foo") os.mkdir(foo_pkg_dir) chroot_2_dir = os.path.join(tmp_dir, "old_dir", "epel7") os.mkdir(chroot_2_dir) with open(os.path.join(chroot_1_dir, "foo", "foo.src.rpm"), "w") as fh: fh.write("foo\n") test_action = Action( action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42, }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() error_event_recorded = False while not self.test_q.empty(): ev = self.test_q.get_nowait() if "Error making local repo" in ev["what"]: error_event_recorded = True assert error_event_recorded
def test_delete_build_with_bad_pkg_name(self, mc_createrepo, mc_time): """ regression: https://bugzilla.redhat.com/show_bug.cgi?id=1203753 """ mc_time.time.return_value = self.test_time resource_name = "1171796_doubled.tar.gz" self.unpack_resource(resource_name) chroot_20_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "old_dir", "fedora-21-x86_64") mc_createrepo.return_value = 0, STDOUT, "" mc_front_cb = MagicMock() self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps( { "src_pkg_name": "", "username": "******", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"], } ), }, frontend_client=mc_front_cb, ) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path) test_action.run() # shouldn't touch chroot dirs assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_handle_createrepo_failure_1(self, mc_devel, mc_call, mc_time): tmp_dir = self.make_temp_dir() mc_call.return_value = 0 # failure action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "ownername": "foo", "projectname": "bar", "project_dirnames": ["bar"] }) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 9 }, ) assert test_action.run().result == ActionResult.FAILURE
def test_delete_no_chroot_dirs(self, mc_call, mc_devel, mc_time): mc_devel.return_value = False mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "id": 1, "object_id": 1, "action_type": ActionType.DELETE, "object_type": "build", "data": self.ext_data_for_delete_build, }, ) result = test_action.run() assert len(mc_call.call_args_list) == 0 assert result.result == ActionResult.FAILURE
def test_delete_no_chroot_dirs(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "not-existing-project", "data": self.ext_data_for_delete_build, }, frontend_client=mc_front_cb ) with mock.patch("backend.actions.shutil") as mc_shutil: test_action.run() assert not mc_shutil.rmtree.called
def test_delete_build_succeeded(self, mc_devel, mc_time): mc_devel.return_value = False mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() proj_dir = os.path.join(tmp_dir, "foo", "bar") chroot_1_dir = os.path.join(proj_dir, "fedora20") chroot_2_dir = os.path.join(proj_dir, "epel7") foo_pkg_dir = os.path.join(chroot_1_dir, "00001-foo") os.makedirs(chroot_2_dir) os.makedirs(foo_pkg_dir) with open(os.path.join(foo_pkg_dir, "foo.src.rpm"), "w") as fh: fh.write("foo\n") log_path = os.path.join(chroot_1_dir, "build-{:08d}.log".format(42)) with open(log_path, "w") as fh: fh.write(self.test_content) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42 }, ) assert os.path.exists(foo_pkg_dir) assert test_action.run().result == ActionResult.SUCCESS assert not os.path.exists(foo_pkg_dir) assert not os.path.exists(log_path) assert os.path.exists(chroot_1_dir) assert os.path.exists(chroot_2_dir)
def test_action_event(self, mc_time): test_action = Action( events=self.test_q, action={}, lock=None, frontend_callback=None, destdir=None, front_url=None, results_root_url=RESULTS_ROOT_URL ) with pytest.raises(EmptyQueue): test_action.events.get_nowait() test_string = "Foo Bar" mc_time.time.return_value = self.test_time test_action.add_event(test_string) result_dict = test_action.events.get() assert result_dict["when"] == self.test_time assert result_dict["who"] == "action" assert result_dict["what"] == test_string
def test_handle_createrepo_ok(self, mc_createrepo, mc_time): mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() mc_createrepo.return_value = 0, STDOUT, "" action_data = json.dumps({ "chroots": ["epel-6-i386", "fedora-20-x86_64"], "username": "******", "projectname": "bar" }) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={ "action_type": ActionType.CREATEREPO, "data": action_data, "id": 8 }, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 8 assert result_dict["result"] == ActionResult.SUCCESS exp_call_1 = mock.call(path=tmp_dir + u'/foo/bar/epel-6-i386', front_url=self.opts.frontend_base_url, override_acr_flag=True, username=u"foo", projectname=u"bar") exp_call_2 = mock.call(path=tmp_dir + u'/foo/bar/fedora-20-x86_64', front_url=self.opts.frontend_base_url, override_acr_flag=True, username=u"foo", projectname=u"bar") assert exp_call_1 in mc_createrepo.call_args_list assert exp_call_2 in mc_createrepo.call_args_list assert len(mc_createrepo.call_args_list) == 2
def test_handle_generate_gpg_key(self, mc_cuk, mc_time): uname = "foo" pname = "bar" action_data = json.dumps({ "username": uname, "projectname": pname, }) expected_call = mock.call(uname, pname, self.opts) mc_front_cb = MagicMock() test_action = Action( opts=self.opts, action={ "action_type": ActionType.GEN_GPG_KEY, "data": action_data, "id": 11 }, frontend_client=mc_front_cb ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.SUCCESS assert mc_cuk.call_args == expected_call # handle exception mc_cuk.side_effect = CoprKeygenRequestError("foo") mc_front_cb.reset_mock() test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.FAILURE # test, that key creation is skipped when signing is disabled self.opts.do_sign = False mc_front_cb.reset_mock() mc_cuk.reset_mock() test_action.run() assert not mc_cuk.called result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.SUCCESS
def test_handle_createrepo_ok(self, mc_createrepo, mc_time): mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() mc_createrepo.return_value = 0, STDOUT, "" action_data = json.dumps( {"chroots": ["epel-6-i386", "fedora-20-x86_64"], "username": "******", "projectname": "bar"} ) self.opts.destdir = tmp_dir test_action = Action( opts=self.opts, action={"action_type": ActionType.CREATEREPO, "data": action_data, "id": 8}, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 8 assert result_dict["result"] == ActionResult.SUCCESS exp_call_1 = mock.call( path=tmp_dir + u"/foo/bar/epel-6-i386", front_url=self.opts.frontend_base_url, override_acr_flag=True, username=u"foo", projectname=u"bar", ) exp_call_2 = mock.call( path=tmp_dir + u"/foo/bar/fedora-20-x86_64", front_url=self.opts.frontend_base_url, override_acr_flag=True, username=u"foo", projectname=u"bar", ) assert exp_call_1 in mc_createrepo.call_args_list assert exp_call_2 in mc_createrepo.call_args_list assert len(mc_createrepo.call_args_list) == 2
def test_action_run_legal_flag(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() test_action = Action( action={ "action_type": ActionType.LEGAL_FLAG, "id": 1 }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=None, front_url=None, results_root_url=RESULTS_ROOT_URL ) test_action.run() assert not mc_front_cb.called result_dict = self.test_q.get() assert result_dict["when"] == self.test_time assert result_dict["who"] == "action" assert result_dict["what"] == "Action legal-flag: ignoring" with pytest.raises(EmptyQueue): test_action.events.get_nowait()
def test_delete_no_chroot_dirs(self, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() tmp_dir = self.make_temp_dir() test_action = Action( action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "not-existing-project", "data": self.ext_data_for_delete_build, }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) with mock.patch("backend.actions.shutil") as mc_shutil: test_action.run() assert not mc_shutil.rmtree.called
def test_request_exception_is_taken_care_of_when_posting_to_frontend(self, mc_time): mc_time.time.return_value = self.test_time mc_frontend_client = MagicMock() mc_frontend_client.update = MagicMock(side_effect=RequestException) tmp_dir = self.make_temp_dir() self.opts.destdir = os.path.join(tmp_dir, "dir-not-exists") test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "copr", "id": 6, "old_value": "old_dir", }, frontend_client=mc_frontend_client, ) try: test_action.run() except Exception as e: assert False
def test_handle_generate_gpg_key(self, mc_cuk, mc_time): uname = "foo" pname = "bar" action_data = json.dumps({"username": uname, "projectname": pname}) expected_call = mock.call(uname, pname, self.opts) mc_front_cb = MagicMock() test_action = Action( opts=self.opts, action={"action_type": ActionType.GEN_GPG_KEY, "data": action_data, "id": 11}, frontend_client=mc_front_cb, ) test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.SUCCESS assert mc_cuk.call_args == expected_call # handle exception mc_cuk.side_effect = CoprKeygenRequestError("foo") mc_front_cb.reset_mock() test_action.run() result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.FAILURE # test, that key creation is skipped when signing is disabled self.opts.do_sign = False mc_front_cb.reset_mock() mc_cuk.reset_mock() test_action.run() assert not mc_cuk.called result_dict = mc_front_cb.update.call_args[0][0]["actions"][0] assert result_dict["id"] == 11 assert result_dict["result"] == ActionResult.SUCCESS
def test_delete_build_succeeded(self, mc_createrepo, mc_time): mc_time.time.return_value = self.test_time mc_front_cb = MagicMock() mc_createrepo.return_value = (0, "", "") # mc_createrepo.side_effect = IOError() tmp_dir = self.make_temp_dir() chroot_1_dir = os.path.join(tmp_dir, "old_dir", "fedora20") os.mkdir(chroot_1_dir) foo_pkg_dir = os.path.join(chroot_1_dir, "foo") os.mkdir(foo_pkg_dir) chroot_2_dir = os.path.join(tmp_dir, "old_dir", "epel7") os.mkdir(chroot_2_dir) with open(os.path.join(chroot_1_dir, "foo", "foo.src.rpm"), "w") as fh: fh.write("foo\n") log_path = os.path.join(chroot_1_dir, "build-42.log") with open(log_path, "w") as fh: fh.write(self.test_content) test_action = Action( action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "old_value": "old_dir", "data": self.ext_data_for_delete_build, "object_id": 42 }, events=self.test_q, lock=None, frontend_callback=mc_front_cb, destdir=tmp_dir, front_url=None, results_root_url=RESULTS_ROOT_URL ) assert os.path.exists(foo_pkg_dir) test_action.run() assert not os.path.exists(foo_pkg_dir) assert not os.path.exists(log_path) assert_what_from_queue(self.test_q, msg_list=[ "Action delete build", "Deleting package " + " ".join(self.pkgs_stripped), "Copr path", ]) def assert_epel7(): assert_what_from_queue(self.test_q, msg_list=[ "Package foo dir not found in chroot epel7", ]) def assert_fedora20(): assert_what_from_queue(self.test_q, msg_list=[ "Removing build ", "Running createrepo", ]) ev = self.test_q.get_nowait() assert ev["who"] == "action" assert "In chroot epel7" in ev["what"] or "In chroot fedora20" in ev["what"] if "In chroot epel7" in ev["what"]: assert_epel7() assert_what_from_queue(self.test_q, msg_list=["In chroot fedora20"]) assert_fedora20() assert_what_from_queue(self.test_q, msg_list=["Removing log"]) else: assert_fedora20() assert_what_from_queue(self.test_q, msg_list=["Removing log"]) assert_what_from_queue(self.test_q, msg_list=["In chroot epel7"]) assert_epel7() with pytest.raises(EmptyQueue): self.test_q.get_nowait() create_repo_expected_call = mock.call( username=u'foo', projectname=u'bar', base_url=u'http://example.com/results/foo/bar/fedora20', lock=None, path='{}/old_dir/fedora20'.format(self.tmp_dir_name), front_url=None ) assert mc_createrepo.call_args == create_repo_expected_call
def test_action_handle_forks(self, mc_call, mc_unsign_rpms_in_dir, mc_exists, mc_copy_tree, mc_time): mc_time.time.return_value = self.test_time mc_exists = True test_action = Action( opts=self.opts, action={ "action_type": ActionType.FORK, "id": 1, "object_type": "copr", "data": json.dumps({ 'builds_map': { 'srpm-builds': { '00000002': '00000009', '00000005': '00000010' }, 'fedora-17-x86_64': { '00000002-pkg1': '00000009-pkg1', '00000005-pkg2': '00000010-pkg2' }, 'fedora-17-i386': { '00000002-pkg1': '00000009-pkg1', '00000005-pkg2': '00000010-pkg2' } }, "user": "******", "copr": "source-copr" }), "old_value": "thrnciar/source-copr", "new_value": "thrnciar/destination-copr", }, ) test_action.run() calls = mc_copy_tree.call_args_list assert len(calls) == 6 assert calls[0][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/srpm-builds/00000002", "/var/lib/copr/public_html/results/thrnciar/destination-copr/srpm-builds/00000009" ) assert calls[1][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/srpm-builds/00000005", "/var/lib/copr/public_html/results/thrnciar/destination-copr/srpm-builds/00000010" ) assert calls[2][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/fedora-17-x86_64/00000002-pkg1", "/var/lib/copr/public_html/results/thrnciar/destination-copr/fedora-17-x86_64/00000009-pkg1" ) assert calls[3][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/fedora-17-x86_64/00000005-pkg2", "/var/lib/copr/public_html/results/thrnciar/destination-copr/fedora-17-x86_64/00000010-pkg2" ) assert calls[4][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/fedora-17-i386/00000002-pkg1", "/var/lib/copr/public_html/results/thrnciar/destination-copr/fedora-17-i386/00000009-pkg1" ) assert calls[5][0] == ( "/var/lib/copr/public_html/results/thrnciar/source-copr/fedora-17-i386/00000005-pkg2", "/var/lib/copr/public_html/results/thrnciar/destination-copr/fedora-17-i386/00000010-pkg2" ) # TODO: calling createrepo for srpm-builds is useless assert len(mc_call.call_args_list) == 3 dirs = set() for call in mc_call.call_args_list: args = call[0][0] assert args[0] == 'copr-repo' dirs.add(args[1]) for chroot in ['srpm-builds', 'fedora-17-i386', 'fedora-17-x86_64']: dir = '/var/lib/copr/public_html/results/thrnciar/destination-copr/' + chroot assert dir in dirs
def test_delete_build_acr_reflected(self, mc_devel, mc_time, devel): """ When build is deleted, we want to remove it from both devel and normal (production) repodata """ mc_devel.return_value = devel self.unpack_resource("testresults.tar.gz") chroot = os.path.join(self.test_project_dir, 'fedora-23-x86_64') repodata = os.path.join(chroot, 'repodata') devel_dir = os.path.join(chroot, 'devel') repodata_devel = os.path.join(devel_dir, 'repodata') builddir = '00000049-example' assert os.path.exists(chroot) assert not os.path.exists(devel_dir) # create repodata under 'devel' assert subprocess.call(['copr-repo', chroot, '--devel']) == 0 old_primary = load_primary_xml(repodata) old_primary_devel = load_primary_xml(repodata_devel) assert len(old_primary['names']) == 3 # noarch vs. src assert len(old_primary['hrefs']) == 5 for package in old_primary_devel['packages']: assert old_primary_devel['packages'][package]['xml:base'] \ == 'https://example.com/results/@copr/prunerepo/fedora-23-x86_64' # clear it old_primary_devel['packages'][package]['xml:base'] = '' assert old_primary == old_primary_devel self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "id": 7, "object_id": 49, "old_value": "old_dir", "data": json.dumps({ "ownername": "@copr", "projectname": "prunerepo", "project_dirname": "prunerepo", "chroot_builddirs": { "fedora-23-x86_64": [builddir], }, }), }, ) assert test_action.run().result == ActionResult.SUCCESS new_primary = load_primary_xml(repodata) new_primary_devel = load_primary_xml(repodata_devel) if devel: assert new_primary_devel['names'] == set(['prunerepo']) assert len(new_primary['names']) == 3 else: assert new_primary['names'] == set(['prunerepo']) assert len(new_primary_devel['names']) == 3
def test_delete_two_chroots(self, mc_devel, mc_time): """ Regression test, https://bugzilla.redhat.com/show_bug.cgi?id=1171796 """ mc_devel.return_value = 0 self.unpack_resource("1171796.tar.gz") chroot_20_path = os.path.join(self.tmp_dir_name, "foo", "bar", "fedora-20-x86_64") chroot_21_path = os.path.join(self.tmp_dir_name, "foo", "bar", "fedora-21-x86_64") assert os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.log")) for path in [chroot_20_path, chroot_21_path]: # the 1171796 tarball above contains too old directory structure, # for some time we prefix the ID with zeroes. So create another # (newer variant of) log file and check that both logs would be # potentially removed. shutil.copy(os.path.join(path, "build-15.log"), os.path.join(path, "build-00000015.log")) assert os.path.exists( os.path.join(chroot_20_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.isdir( os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) mc_time.time.return_value = self.test_time self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "ownername": "foo", "projectname": "bar", "project_dirname": "bar", "chroot_builddirs": { "fedora-20-x86_64": ["rubygem-log4r-1.1.10-2.fc21"], "fedora-21-x86_64": ["rubygem-log4r-1.1.10-2.fc21"], } }), }, ) assert test_action.run().result == ActionResult.SUCCESS assert not os.path.exists( os.path.join(chroot_20_path, "build-00000015.log")) assert not os.path.exists( os.path.join(chroot_21_path, "build-00000015.log")) assert not os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert not os.path.exists( os.path.join(chroot_20_path, "build-15.rsync.log")) assert not os.path.exists( os.path.join(chroot_21_path, "build-15.rsync.log")) assert not os.path.isdir( os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert not os.path.isdir( os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.exists(chroot_20_path) assert os.path.exists(chroot_21_path)
def test_delete_two_chroots_two_remain(self, mc_devel, mc_time): """ Regression test, https://bugzilla.redhat.com/show_bug.cgi?id=1171796 extended: we also put two more chroots, which should be unaffected """ mc_devel.return_value = 0 self.unpack_resource("1171796_doubled.tar.gz") subdir = os.path.join(self.tmp_dir_name, "foo", "bar") chroot_20_path = os.path.join(subdir, "fedora-20-x86_64") chroot_21_path = os.path.join(subdir, "fedora-21-x86_64") chroot_20_i386_path = os.path.join(subdir, "fedora-20-i386") chroot_21_i386_path = os.path.join(subdir, "fedora-21-i386") assert os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_20_i386_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_i386_path, "build-15.log")) assert os.path.exists( os.path.join(chroot_20_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_20_i386_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_21_i386_path, "build-15.rsync.log")) assert os.path.isdir( os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_20_i386_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_21_i386_path, "rubygem-log4r-1.1.10-2.fc21")) mc_time.time.return_value = self.test_time self.opts.destdir = self.tmp_dir_name test_action = Action( opts=self.opts, action={ "action_type": ActionType.DELETE, "object_type": "build", "object_id": 15, "id": 15, "old_value": "old_dir", "data": json.dumps({ "ownername": "foo", "projectname": "bar", "chroots": ["fedora-20-x86_64", "fedora-21-x86_64"], "project_dirname": "bar", "chroot_builddirs": { "fedora-20-x86_64": ["rubygem-log4r-1.1.10-2.fc21"], "fedora-21-x86_64": ["rubygem-log4r-1.1.10-2.fc21"], } }), }, ) assert test_action.run().result == ActionResult.SUCCESS assert not os.path.exists(os.path.join(chroot_20_path, "build-15.log")) assert not os.path.exists(os.path.join(chroot_21_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_20_i386_path, "build-15.log")) assert os.path.exists(os.path.join(chroot_21_i386_path, "build-15.log")) assert not os.path.exists( os.path.join(chroot_20_path, "build-15.rsync.log")) assert not os.path.exists( os.path.join(chroot_21_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_20_i386_path, "build-15.rsync.log")) assert os.path.exists( os.path.join(chroot_21_i386_path, "build-15.rsync.log")) assert not os.path.isdir( os.path.join(chroot_20_path, "rubygem-log4r-1.1.10-2.fc21")) assert not os.path.isdir( os.path.join(chroot_21_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_20_i386_path, "rubygem-log4r-1.1.10-2.fc21")) assert os.path.isdir( os.path.join(chroot_21_i386_path, "rubygem-log4r-1.1.10-2.fc21"))