def test_all(self): """ Sync a repository using a Remote url that does not exist. Test that we get a task failure. """ client_api = gen_container_client() repository_api = RepositoriesContainerApi(client_api) repository = repository_api.create( ContainerContainerRepository(**gen_repo())) self.addCleanup(repository_api.delete, repository.pulp_href) remote_api = RemotesContainerApi(client_api) remote_data = gen_container_remote( url="http://i-am-an-invalid-url.com/invalid/") remote = remote_api.create(ContainerContainerRemote(**remote_data)) self.addCleanup(remote_api.delete, remote.pulp_href) repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repository_api.sync(repository.pulp_href, repository_sync_data) with self.assertRaises(PulpTaskError) as context: monitor_task(sync_response.task) self.assertIsNotNone(context.exception.task.error["description"])
def test_all(self): """ Sync a repository using a Remote url that does not exist. Test that we get a task failure. """ client_api = gen_container_client() repository_api = RepositoriesContainerApi(client_api) repository = repository_api.create( ContainerContainerRepository(**gen_repo())) self.addCleanup(repository_api.delete, repository.pulp_href) remote_api = RemotesContainerApi(client_api) remote_data = gen_container_remote( url="http://i-am-an-invalid-url.com/invalid/") remote = remote_api.create(ContainerContainerRemote(**remote_data)) self.addCleanup(remote_api.delete, remote.pulp_href) repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repository_api.sync(repository.pulp_href, repository_sync_data) task = monitor_task(sync_response.task) if isinstance(task, dict): self.assertIsNotNone(task["error"]["description"]) else: self.assertFalse("Sync with an invalid remote URL was successful")
def populate_pulp(url=REGISTRY_V2_FEED_URL): """Add container contents to Pulp. :param url: The container repository URL. Defaults to :data:`pulp_container.tests.functional.constants.REGISTRY_V2_FEED_URL` :returns: A dictionary of created resources. """ container_client = ContainerApiClient(configuration) remotes_api = RemotesContainerApi(container_client) repositories_api = RepositoriesContainerApi(container_client) container_remote = remotes_api.create(gen_container_remote(url)) sync_data = RepositorySyncURL(remote=container_remote.pulp_href) container_repository = repositories_api.create(gen_repo()) sync_response = repositories_api.sync(container_repository.pulp_href, sync_data) return monitor_task(sync_response.task).created_resources
def test_sync(self): """Sync repositories with the container plugin. In order to sync a repository a remote has to be associated within this repository. When a repository is created this version field is set as None. After a sync the repository version is updated. Do the following: 1. Create a repository, and a remote. 2. Assert that repository version is None. 3. Sync the remote. 4. Assert that repository version is not None. 5. Sync the remote one more time. 6. Assert that repository version is the same from the previous one. """ repository_api = RepositoriesContainerApi(self.client_api) repository = repository_api.create( ContainerContainerRepository(**gen_repo())) self.addCleanup(repository_api.delete, repository.pulp_href) remote_api = RemotesContainerApi(self.client_api) remote = remote_api.create(gen_container_remote()) self.addCleanup(remote_api.delete, remote.pulp_href) self.assertEqual(repository.latest_version_href, f"{repository.pulp_href}versions/0/") repository_sync_data = ContainerRepositorySyncURL( remote=remote.pulp_href) # Sync the repository. sync_response = repository_api.sync(repository.pulp_href, repository_sync_data) monitor_task(sync_response.task) repository = repository_api.read(repository.pulp_href) self.assertIsNotNone(repository.latest_version_href) # Sync the repository again. latest_version_href = repository.latest_version_href sync_response = repository_api.sync(repository.pulp_href, repository_sync_data) monitor_task(sync_response.task) repository = repository_api.read(repository.pulp_href) self.assertEqual(latest_version_href, repository.latest_version_href)
def test_file_decriptors(self): """Test whether file descriptors are closed properly. This test targets the following issue: `Pulp #4073 <https://pulp.plan.io/issues/4073>`_ Do the following: 1. Check if 'lsof' is installed. If it is not, skip this test. 2. Create and sync a repo. 3. Run the 'lsof' command to verify that files in the path ``/var/lib/pulp/`` are closed after the sync. 4. Assert that issued command returns `0` opened files. """ cli_client = cli.Client(self.cfg, cli.echo_handler) # check if 'lsof' is available if cli_client.run(("which", "lsof")).returncode != 0: raise unittest.SkipTest("lsof package is not present") repo_api = RepositoriesContainerApi(self.client_api) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) remote_api = RemotesContainerApi(self.client_api) remote = remote_api.create(gen_container_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) cmd = "lsof -t +D {}".format(MEDIA_PATH).split() response = cli_client.run(cmd).stdout self.assertEqual(len(response), 0, response)
def test_import_export(self): """ Test exporting and importing of a container repository. """ core_client = CoreApiClient(configuration) container_client = ContainerApiClient(configuration) remotes_api = RemotesContainerApi(container_client) repositories_api = RepositoriesContainerApi(container_client) repository_versions_api = RepositoriesContainerVersionsApi( container_client) manifests_api = ContentManifestsApi(container_client) exporters_api = ExportersPulpApi(core_client) exports_api = ExportersPulpExportsApi(core_client) importers_api = ImportersPulpApi(core_client) imports_api = ImportersPulpImportsApi(core_client) # Setup remote = remotes_api.create(gen_container_remote()) self.addCleanup(remotes_api.delete, remote.pulp_href) sync_data = ContainerRepositorySyncURL(remote=remote.pulp_href) repository = repositories_api.create(gen_repo()) self.addCleanup(repositories_api.delete, repository.pulp_href) sync_response = repositories_api.sync(repository.pulp_href, sync_data) monitor_task(sync_response.task).created_resources # Export the repository body = { "name": uuid4(), "path": "/tmp/{}/".format(uuid4()), "repositories": [repository.pulp_href], } exporter = exporters_api.create(body) self.addCleanup(exporters_api.delete, exporter.pulp_href) export_response = exports_api.create(exporter.pulp_href, {}) export_href = monitor_task(export_response.task).created_resources[0] export = exports_api.read(export_href) # Clean the old repository out monitor_task( repository_versions_api.delete( repository.latest_version_href).task) delete_orphans() # Import the repository import_repository = repositories_api.create(gen_repo()) self.addCleanup(repositories_api.delete, import_repository.pulp_href) body = { "name": uuid4(), "repo_mapping": { repository.name: import_repository.name }, } importer = importers_api.create(body) self.addCleanup(importers_api.delete, importer.pulp_href) filenames = [ f for f in list(export.output_file_info.keys()) if f.endswith("tar.gz") ] import_response = imports_api.create(importer.pulp_href, {"path": filenames[0]}) if hasattr(import_response, "task_group"): task_group_href = import_response.task_group else: task_group_href = monitor_task( import_response.task).created_resources[1] monitor_task_group(task_group_href) # Verify that the imported repository contains the right associations import_repository = repositories_api.read(import_repository.pulp_href) manifests = manifests_api.list( repository_version=import_repository.latest_version_href).results for manifest in manifests: if "manifest.list" in manifest.media_type: self.assertNotEqual(manifest.listed_manifests, []) else: self.assertNotEqual(manifest.blobs, []) self.assertIsNotNone(manifest.config_blob)