def _create_publication(self, repository, version=None, cleanup=True): """ Creates a `PythonPublication` from the `PythonRepository`. Args: repository: The repository to use for the publication version: Optional - The version to repo_version to use, either an int or href cleanup: whether to cleanup the publication Returns: The created `PythonPublication` """ if version is not None: try: rv_href = f"{repository.versions_href}{int(version)}/" except ValueError: rv_href = version publish_data = PythonPythonPublication(repository_version=rv_href) else: publish_data = PythonPythonPublication( repository=repository.pulp_href) publish_response = self.publications_api.create(publish_data) pub = self.publications_api.read( monitor_task(publish_response.task).created_resources[0]) if cleanup: self.addCleanup(self.publications_api.delete, pub.pulp_href) return pub
def publish(repo, version_href=None): """Publish a repository. :param repo: A dict of information about the repository. :param version_href: A href for the repo version to be published. :returns: A publication. A dict of information about the just created publication. """ if version_href: publish_data = PythonPythonPublication(repository_href=version_href) else: publish_data = PythonPythonPublication(repository=repo["pulp_href"]) publish_response = pub_api.create(publish_data) created_resources = monitor_task(publish_response.task).created_resources return pub_api.read(created_resources[0]).to_dict()
def test_on_demand(self): """Test whether a particular repository version can be published. 1. Create a repository 2. Create a remote with on_demand sync policy 3. Sync 4. Publish repository """ client = gen_python_client() repo_api = RepositoriesPythonApi(client) remote_api = RemotesPythonApi(client) publications = PublicationsPypiApi(client) body = gen_python_remote(policy="on_demand") remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.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 = PythonPythonPublication(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) publication = publications.read(publication_href) self.assertEqual(publication.repository_version, repo.latest_version_href)
def create_publication(pub_api, repository, cleanup=None): """Creates a new python publication.""" publish_data = PythonPythonPublication(repository=repository.pulp_href) publish_response = pub_api.create(publish_data) publication = pub_api.read( monitor_task(publish_response.task).created_resources[0]) if cleanup: cleanup(pub_api.delete, publication.pulp_href) return publication
def test_all(self): """Test whether a particular repository version can be published. 1. Create a repository with at least 2 repository versions. 2. Create a publication by supplying the latest ``repository_version``. 3. Assert that the publication ``repository_version`` attribute points to the latest repository version. 4. Create a publication by supplying the non-latest ``repository_version``. 5. Create distribution. 6. Assert that the publication ``repository_version`` attribute points to the supplied repository version. 7. Assert that an exception is raised when providing two different repository versions to be published at same time. """ # Step 1 repo_content = get_content( self.repo.to_dict())[PYTHON_CONTENT_NAME][:-1] for file_content in repo_content: repository_modify_data = RepositoryAddRemoveContent( remove_content_units=[file_content["pulp_href"]]) modify_response = self.repo_api.modify(self.repo.pulp_href, repository_modify_data) monitor_task(modify_response.task) version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(self.repo.to_dict())) non_latest = choice(version_hrefs[1:-1]) # Step 2 publish_data = PythonPythonPublication(repository=self.repo.pulp_href) publication = self.create_publication(publish_data) # Step 3 self.assertEqual(publication.repository_version, version_hrefs[-1]) # Step 4 publish_data = PythonPythonPublication(repository_version=non_latest) publication = self.create_publication(publish_data) # Step 5 body = gen_distribution() body["base_path"] = "pulp_pre_upgrade_test" body["publication"] = publication.pulp_href distribution_response = self.distributions.create(body) created_resources = monitor_task( distribution_response.task).created_resources distribution = self.distributions.read(created_resources[0]) # Step 6 self.assertEqual(publication.repository_version, non_latest) # Step 7 with self.assertRaises(ApiException): body = { "repository": self.repo.pulp_href, "repository_version": non_latest } self.publications.create(body) # Step 8 url = self.cfg.get_content_host_base_url( ) + "/pulp/content/pulp_pre_upgrade_test/" self.assertEqual(url, distribution.base_url, url)
def test_all(self): """Test whether a particular repository version can be published. 1. Create a repository with at least 2 repository versions. 2. Create a publication by supplying the latest ``repository_version``. 3. Assert that the publication ``repository_version`` attribute points to the latest repository version. 4. Create a publication by supplying the non-latest ``repository_version``. 5. Assert that the publication ``repository_version`` attribute points to the supplied repository version. 6. Assert that an exception is raised when providing two different repository versions to be published at same time. """ cfg = config.get_config() client = gen_python_client() repo_api = RepositoriesPythonApi(client) remote_api = RemotesPythonApi(client) publications = PublicationsPypiApi(client) body = gen_python_remote() remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.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) # Step 1 repo = repo_api.read(repo.pulp_href) for python_content in get_content(repo.to_dict())[PYTHON_CONTENT_NAME]: modify_repo(cfg, repo.to_dict(), add_units=[python_content]) version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict())) non_latest = choice(version_hrefs[:-1]) # Step 2 publish_data = PythonPythonPublication(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) publication = publications.read(publication_href) # Step 3 self.assertEqual(publication.repository_version, version_hrefs[-1]) # Step 4 publish_data.repository = None publish_data.repository_version = non_latest publish_response = publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources publication_href = created_resources[0] publication = publications.read(publication_href) # Step 5 self.assertEqual(publication.repository_version, non_latest) # Step 6 with self.assertRaises(ApiException): body = { "repository": repo.pulp_href, "repository_version": non_latest } publications.create(body)
def test_all(self): """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>`_ """ client = gen_python_client() repo_api = RepositoriesPythonApi(client) remote_api = RemotesPythonApi(client) publications = PublicationsPypiApi(client) distributions = DistributionsPypiApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_python_remote() 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 = PythonPythonPublication(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 content unit (of each type), and download it from both Pulp Fixtures… unit_paths = [ choice(paths) for paths in get_python_content_paths(repo.to_dict()).values() ] fixtures_hashes = [ hashlib.sha256( utils.http_get( urljoin(urljoin(PYTHON_FIXTURE_URL, "packages/"), unit_path[0]))).hexdigest() for unit_path in unit_paths ] # …and Pulp. pulp_hashes = [] cfg = config.get_config() for unit_path in unit_paths: content = download_content_unit(cfg, distribution.to_dict(), unit_path[1]) pulp_hashes.append(hashlib.sha256(content).hexdigest()) self.assertEqual(fixtures_hashes, pulp_hashes)