def test_remove_packages(self): feed_url = "http://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/pulp_unittest/" repo = mock.Mock(spec=Repository) repo.working_dir = self.working_dir repo.id = "test_remove_packages" sync_conduit = importer_mocks.get_sync_conduit(existing_units=[], pkg_dir=self.pkg_dir) config = importer_mocks.get_basic_config(feed_url=feed_url) importerRPM = importer_rpm.ImporterRPM() status, summary, details = importerRPM.sync(repo, sync_conduit, config) self.assertTrue(status) self.assertEquals(summary["num_synced_new_rpms"], 3) self.assertEquals(len(self.get_files_in_dir("*.rpm", self.pkg_dir)), 3) self.assertEquals(len(self.get_files_in_dir("*.rpm", repo.working_dir)), 3) expected_rpms = self.get_expected_rpms_from_pulp_unittest(repo.id) # Confirm that both the RPM and the Symlink for each expected rpm does exist # Then run remove_unit # Confirm that both the RPM and the Symlink have been deleted from the file system for rpm in expected_rpms.values(): rpm_save_path = os.path.join(rpm["pkgpath"], rpm["filename"]) self.assertTrue(os.path.exists(rpm_save_path)) symlink_save_path = os.path.join(rpm["savepath"], rpm["filename"]) self.assertTrue(os.path.lexists(symlink_save_path)) unit = Unit(TYPE_ID_RPM, importer_rpm.form_rpm_unit_key(rpm), importer_rpm.form_rpm_metadata(rpm), rpm_save_path) importer_rpm.remove_unit(sync_conduit, unit) self.assertTrue(os.path.exists(rpm_save_path)) self.assertTrue(os.path.exists(symlink_save_path))
def test_remove_old_packages(self): feed_url = "http://jmatthews.fedorapeople.org/repo_multiple_versions/" repo = mock.Mock(spec=Repository) repo.working_dir = self.working_dir repo.id = "test_remove_old_packages" sync_conduit = importer_mocks.get_sync_conduit(type_id=TYPE_ID_RPM, pkg_dir=self.pkg_dir) ### # Test that old packages are not in rpmList and are never intended to be downloaded # Additionallity verify that already existing packages which are NOT orphaned are also # removed with remove_old functionality ### config = importer_mocks.get_basic_config(feed_url=feed_url, remove_old=False, num_old_packages=0) importerRPM = importer_rpm.ImporterRPM() status, summary, details = importerRPM.sync(repo, sync_conduit, config) self.assertTrue(status) self.assertEquals(summary["num_synced_new_rpms"], 12) pkgs = self.get_files_in_dir("*.rpm", self.pkg_dir) self.assertEquals(len(pkgs), 12) yumRepoGrinder = importer_rpm.get_yumRepoGrinder(repo.id, repo.working_dir, config) yumRepoGrinder.setup(basepath=repo.working_dir) rpm_items = yumRepoGrinder.getRPMItems() yumRepoGrinder.stop() del yumRepoGrinder self.assertEquals(len(rpm_items), 12) existing_units = [] for rpm in rpm_items: u = Unit( TYPE_ID_RPM, importer_rpm.form_rpm_unit_key(rpm), importer_rpm.form_rpm_metadata(rpm), os.path.join(self.pkg_dir, rpm["pkgpath"], rpm["filename"]), ) existing_units.append(u) config = importer_mocks.get_basic_config(feed_url=feed_url, remove_old=True, num_old_packages=6) sync_conduit = importer_mocks.get_sync_conduit( type_id=TYPE_ID_RPM, existing_units=existing_units, pkg_dir=self.pkg_dir ) importerRPM = importer_rpm.ImporterRPM() status, summary, details = importerRPM.sync(repo, sync_conduit, config) self.assertTrue(status) self.assertEquals(summary["num_rpms"], 7) self.assertEquals(summary["num_orphaned_rpms"], 5) self.assertEquals(summary["num_synced_new_rpms"], 0) self.assertEquals(summary["num_not_synced_rpms"], 0) pkgs = self.get_files_in_dir("*.rpm", self.pkg_dir) self.assertEquals(len(pkgs), 7) config = importer_mocks.get_basic_config(feed_url=feed_url, remove_old=True, num_old_packages=0) importerRPM = importer_rpm.ImporterRPM() status, summary, details = importerRPM.sync(repo, sync_conduit, config) self.assertTrue(status) self.assertEquals(summary["num_rpms"], 1) self.assertEquals(summary["num_orphaned_rpms"], 11) self.assertEquals(summary["num_synced_new_rpms"], 0) self.assertEquals(summary["num_not_synced_rpms"], 0) pkgs = self.get_files_in_dir("*.rpm", self.pkg_dir) self.assertEquals(len(pkgs), 1)