def test_filtered_sync(self): test_url = "http://repos.fedorapeople.org/repos/pulp/pulp/v1/testing/6Server/i386/" temp_label = "test_filtered_sync" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5) temp_dir = tempfile.mkdtemp() # # Verify gofer packages are in repo # try: sync_report = yum_fetch.fetchYumRepo(temp_dir) synced_rpms = glob.glob("%s/%s/gofer*.rpm" % (temp_dir, temp_label)) self.assertTrue(len(synced_rpms) > 0) finally: shutil.rmtree(temp_dir) # # Verify when our blacklist filter no gofer packages are synced # filter_gofer = Filter("blacklist", regex_list=["gofer*"], description="Simple gofer filter") yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5, filter=filter_gofer) temp_dir = tempfile.mkdtemp() try: sync_report = yum_fetch.fetchYumRepo(temp_dir) synced_rpms = glob.glob("%s/%s/gofer*.rpm" % (temp_dir, temp_label)) self.assertEqual(len(synced_rpms), 0) finally: shutil.rmtree(temp_dir)
def run(self): try: self.yum_fetch = RepoFetch.YumRepoGrinder(self.temp_label, self.repo_url, parallel=self.parallel, max_speed=self.max_speed, packages_location=self.pkg_loc) self.sync_report = self.yum_fetch.fetchYumRepo(self.repos_loc) finally: self.running = False
def test_local_sync(self): test_url = "file://%s/%s" % (datadir, "repo_resync_a") temp_label = "temp_local_sync" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5) sync_report = yum_fetch.fetchYumRepo(self.temp_dir) self.assertEquals(sync_report.errors, 0) self.assertTrue(sync_report.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (self.temp_dir, temp_label)) self.assertEquals(len(synced_rpms), sync_report.successes)
def __init__(self, callback): Thread.__init__(self) self.test_url = "http://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/test_bandwidth_repo/" self.num_threads = 2 self.max_speed = 1 # 1 KB/sec self.callback = callback self.temp_dir = tempfile.mkdtemp() self.yum_fetch = RepoFetch.YumRepoGrinder(self.temp_dir, self.test_url, self.num_threads, max_speed=self.max_speed)
def test_empty_repo_sync(self): test_url = "http://jmatthews.fedorapeople.org/empty_repo/" temp_label = "test_empty_repo_sync" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5) temp_dir = tempfile.mkdtemp() try: sync_report = yum_fetch.fetchYumRepo(temp_dir) self.assertEquals(sync_report.errors, 0) self.assertEquals(sync_report.successes, 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir, temp_label)) self.assertEquals(len(synced_rpms), sync_report.successes) finally: shutil.rmtree(temp_dir)
def test_basic_sync(self): test_url = "http://repos.fedorapeople.org/repos/pulp/pulp/v1/testing/6Server/i386/" temp_label = "temp_label" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5) temp_dir = tempfile.mkdtemp() try: sync_report = yum_fetch.fetchYumRepo(temp_dir) self.assertEquals(sync_report.errors, 0) self.assertTrue(sync_report.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir, temp_label)) self.assertEquals(len(synced_rpms), sync_report.successes) finally: shutil.rmtree(temp_dir)
def test_purge_orphan_packages(self): test_url_a = "http://jmatthews.fedorapeople.org/repo_multiple_versions/" test_url_b = "http://jmatthews.fedorapeople.org/repo_resync/" temp_label = "temp_purge_orphan" yum_fetch_a = RepoFetch.YumRepoGrinder(temp_label, test_url_a, parallel=5) yum_fetch_b = RepoFetch.YumRepoGrinder(temp_label, test_url_b, parallel=5) temp_dir_a = tempfile.mkdtemp() temp_dir_b = tempfile.mkdtemp() try: # Sync some extra rpms from a different repo sync_report_a = yum_fetch_a.fetchYumRepo(temp_dir_a) # Simulate orphaned packages by copying extra rpms to a dir, then doing a sync if not os.path.exists("%s/%s" % (temp_dir_b, temp_label)): os.makedirs("%s/%s" % (temp_dir_b, temp_label)) for src_file in glob.glob("%s/%s/*.rpm" % (temp_dir_a, temp_label)): shutil.copy(src_file, "%s/%s" % (temp_dir_b, temp_label)) sync_report_b = yum_fetch_b.fetchYumRepo(temp_dir_b) self.assertTrue(sync_report_b.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir_b, temp_label)) self.assertEquals(len(synced_rpms), sync_report_b.successes) finally: shutil.rmtree(temp_dir_a) shutil.rmtree(temp_dir_b)
def test_remove_existing_packages_that_are_old(self): test_url = "http://jmatthews.fedorapeople.org/repo_multiple_versions/" temp_label = "temp_number_old_packages" num_old = 4 yum_fetch_a = RepoFetch.YumRepoGrinder(temp_label, test_url, parallel=5) yum_fetch_b = RepoFetch.YumRepoGrinder(temp_label, test_url, parallel=5, newest=False, remove_old=True, numOldPackages=num_old) self.assertEquals(yum_fetch_b.numOldPackages, num_old) temp_dir = tempfile.mkdtemp() try: # Sync all packages, including old ones sync_report = yum_fetch_a.fetchYumRepo(temp_dir) self.assertEquals(sync_report.errors, 0) self.assertTrue(sync_report.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir, temp_label)) self.assertTrue(len(synced_rpms) > num_old+1) # Resync packages with numOldPackages set # This will cause the removeOldPackages check at end of sync to run sync_report = yum_fetch_b.fetchYumRepo(temp_dir) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir, temp_label)) self.assertEquals(len(synced_rpms), sync_report.successes) self.assertEquals(len(synced_rpms), num_old+1) finally: shutil.rmtree(temp_dir)
def test_local_sync_with_errors(self): test_rpm_with_error = os.path.join( datadir, "local_errors", "pulp-test-package-0.3.1-1.fc11.x86_64.rpm") orig_stat = os.stat(test_rpm_with_error) try: os.chmod(test_rpm_with_error, 0000) self.assertFalse(os.access(test_rpm_with_error, os.R_OK)) test_url = "file://%s/%s" % (datadir, "local_errors") temp_label = "temp_local_sync_with_errors" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, 5) sync_report = yum_fetch.fetchYumRepo(self.temp_dir) self.assertEquals(sync_report.errors, 1) self.assertTrue(sync_report.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (self.temp_dir, temp_label)) self.assertEquals(len(synced_rpms), sync_report.successes) self.assertEquals(len(synced_rpms), 2) finally: os.chmod(test_rpm_with_error, orig_stat.st_mode)
def test_sync_number_old_packages(self): test_url = "http://jmatthews.fedorapeople.org/repo_multiple_versions/" num_old = 4 temp_label = "temp_number_old_packages" yum_fetch = RepoFetch.YumRepoGrinder(temp_label, test_url, parallel=5, newest=False, remove_old=True, numOldPackages=num_old) self.assertEquals(yum_fetch.numOldPackages, num_old) temp_dir = tempfile.mkdtemp() try: sync_report = yum_fetch.fetchYumRepo(temp_dir) self.assertEquals(sync_report.errors, 0) self.assertTrue(sync_report.successes > 0) synced_rpms = glob.glob("%s/%s/*.rpm" % (temp_dir, temp_label)) finally: shutil.rmtree(temp_dir) # Verify we downloaded only what was needed, i.e. we didn't # download more older rpms than asked for. self.assertEquals(len(synced_rpms), sync_report.successes) # Verify # of rpms in synced dir is latest plus num_old self.assertEquals(len(synced_rpms), num_old+1)