def create_distribution(repository_href=None): """Utility to create a pulp_file distribution.""" file_client = gen_file_client() distro_api = DistributionsFileApi(file_client) body = {"name": utils.uuid4(), "base_path": utils.uuid4()} if repository_href: body["repository"] = repository_href result = distro_api.create(body) distro_href = monitor_task(result.task).created_resources[0] distro = distro_api.read(distro_href) return distro
def set_distribution_base_path(file_distribution_href, base_path): """ Set the base path of a FileDistribution and return the updated representation. Args: file_distribution_href: The distribution href that is to be updated. This must refer to a distribution of type `FileDistribution`. base_path: The base path to set on the `distribution`. Returns: The bindings object representing the updated FileDistribution. """ file_client = gen_file_client() distributions_api = DistributionsFileApi(file_client) update_response = distributions_api.partial_update( file_distribution_href, {"base_path": base_path}) monitor_task(update_response.task) return distributions_api.read(file_distribution_href)
def test_access_error(self): """HTTP error is not raised when accessing published data.""" repo_api = RepositoriesFileApi(self.client) remote_api = RemotesFileApi(self.client) publications = PublicationsFileApi(self.client) distributions = DistributionsFileApi(self.client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) remote = remote_api.create(gen_file_remote()) self.addCleanup(remote_api.delete, remote.pulp_href) repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = repo_api.read(repo.pulp_href) publish_data = FileFilePublication(repository=repo.pulp_href) publish_response = publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources publication_href = created_resources[0] self.addCleanup(publications.delete, publication_href) body = gen_distribution() body["publication"] = publication_href distribution_response = distributions.create(body) created_resources = monitor_task( distribution_response.task).created_resources distribution = distributions.read(created_resources[0]) self.addCleanup(distributions.delete, distribution.pulp_href) pulp_manifest = parse_pulp_manifest( self.download_pulp_manifest(distribution.to_dict(), "PULP_MANIFEST")) self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)
def do_test(self, policy): """Verify whether content served by pulp can be downloaded. The process of publishing content is more involved in Pulp 3 than it was under Pulp 2. Given a repository, the process is as follows: 1. Create a publication from the repository. (The latest repository version is selected if no version is specified.) A publication is a repository version plus metadata. 2. Create a distribution from the publication. The distribution defines at which URLs a publication is available, e.g. ``http://example.com/content/foo/`` and ``http://example.com/content/bar/``. Do the following: 1. Create, populate, publish, and distribute a repository. 2. Select a random content unit in the distribution. Download that content unit from Pulp, and verify that the content unit has the same checksum when fetched directly from Pulp-Fixtures. This test targets the following issues: * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_ * `Pulp Smash #872 <https://github.com/pulp/pulp-smash/issues/872>`_ """ cfg = config.get_config() client = gen_file_client() repo_api = RepositoriesFileApi(client) remote_api = RemotesFileApi(client) publications = PublicationsFileApi(client) distributions = DistributionsFileApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_file_remote(policy=policy) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync a Repository repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = repo_api.read(repo.pulp_href) # Create a publication. publish_data = FileFilePublication(repository=repo.pulp_href) publish_response = publications.create(publish_data) created_resources = monitor_task(publish_response.task) publication_href = created_resources[0] self.addCleanup(publications.delete, publication_href) # Create a distribution. body = gen_distribution() body["publication"] = publication_href distribution_response = distributions.create(body) created_resources = monitor_task(distribution_response.task) distribution = distributions.read(created_resources[0]) self.addCleanup(distributions.delete, distribution.pulp_href) # Pick a file, and download it from both Pulp Fixtures… unit_path = choice(get_file_content_paths(repo.to_dict())) fixtures_hash = hashlib.sha256( utils.http_get(urljoin(FILE_FIXTURE_URL, unit_path))).hexdigest() # …and Pulp. content = download_content_unit(cfg, distribution.to_dict(), unit_path) pulp_hash = hashlib.sha256(content).hexdigest() self.assertEqual(fixtures_hash, pulp_hash)
class RepoVersionRetentionTestCase(unittest.TestCase): """Test retained_versions for repositories This test targets the following issues: * `Pulp #8368 <https:://pulp.plan.io/issues/8368>`_ """ @classmethod def setUp(self): """Add content to Pulp.""" self.cfg = config.get_config() self.client = api.Client(self.cfg, api.json_handler) self.core_client = CoreApiClient( configuration=self.cfg.get_bindings_config()) self.file_client = gen_file_client() self.content_api = ContentFilesApi(self.file_client) self.repo_api = RepositoriesFileApi(self.file_client) self.version_api = RepositoriesFileVersionsApi(self.file_client) self.distro_api = DistributionsFileApi(self.file_client) self.publication_api = PublicationsFileApi(self.file_client) delete_orphans() populate_pulp(self.cfg, url=FILE_LARGE_FIXTURE_MANIFEST_URL) self.content = sample(self.content_api.list().results, 3) self.publications = [] def _create_repo_versions(self, repo_attributes={}): self.repo = self.repo_api.create(gen_repo(**repo_attributes)) self.addCleanup(self.repo_api.delete, self.repo.pulp_href) if "autopublish" in repo_attributes and repo_attributes["autopublish"]: self.distro = create_distribution( repository_href=self.repo.pulp_href) self.addCleanup(self.distro_api.delete, self.distro.pulp_href) for content in self.content: result = self.repo_api.modify( self.repo.pulp_href, {"add_content_units": [content.pulp_href]}) monitor_task(result.task) self.repo = self.repo_api.read(self.repo.pulp_href) self.publications += self.publication_api.list( repository_version=self.repo.latest_version_href).results def test_retained_versions(self): """Test repo version retention.""" self._create_repo_versions({"retained_versions": 1}) versions = self.version_api.list( file_file_repository_href=self.repo.pulp_href).results self.assertEqual(len(versions), 1) self.assertEqual(self.repo.latest_version_href.split("/")[-2], "3") def test_retained_versions_on_update(self): """Test repo version retention when retained_versions is set.""" self._create_repo_versions() versions = self.version_api.list( file_file_repository_href=self.repo.pulp_href).results self.assertEqual(len(versions), 4) # update retained_versions to 2 result = self.repo_api.partial_update(self.repo.pulp_href, {"retained_versions": 2}) monitor_task(result.task) versions = self.version_api.list( file_file_repository_href=self.repo.pulp_href).results self.assertEqual(len(versions), 2) self.assertEqual(self.repo.latest_version_href.split("/")[-2], "3") def test_autodistribute(self): """Test repo version retention with autopublish/autodistribute.""" self._create_repo_versions({ "retained_versions": 1, "autopublish": True }) # all but the last publication should be gone for publication in self.publications[:-1]: with self.assertRaises(ApiException) as ae: self.publication_api.read(publication.pulp_href) self.assertEqual(404, ae.exception.status) # check that the last publication is distributed self.distro = self.distro_api.read(self.distro.pulp_href) self.assertEqual(self.distro.publication, self.publications[-1].pulp_href)