def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.cli_client = cli.Client(cls.cfg) allowed_imports = get_pulp_setting(cls.cli_client, "ALLOWED_IMPORT_PATHS") if not allowed_imports or "/tmp" not in allowed_imports: raise unittest.SkipTest( "Cannot run import-tests unless /tmp is in ALLOWED_IMPORT_PATHS ({})." .format(allowed_imports), ) cls.client = api.Client(cls.cfg, api.json_handler) cls.core_client = CoreApiClient( configuration=cls.cfg.get_bindings_config()) cls.file_client = gen_file_client() cls.repo_api = RepositoriesFileApi(cls.file_client) cls.remote_api = RemotesFileApi(cls.file_client) cls.versions_api = RepositoriesFileVersionsApi(cls.file_client) cls.content_api = ContentFilesApi(cls.file_client) cls.exporter_api = ExportersPulpApi(cls.core_client) cls.exports_api = ExportersCoreExportsApi(cls.core_client) cls.importer_api = ImportersPulpApi(cls.core_client) cls.imports_api = ImportersCoreImportsApi(cls.core_client) cls.import_check_api = ImportersCoreImportCheckApi(cls.core_client) (cls.import_repos, cls.export_repos, cls.remotes) = cls._setup_repositories() cls.exporter = cls._create_exporter() cls.export = cls._create_export() cls.chunked_export = cls._create_chunked_export() cls._setup_import_check_directories()
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 test_second_unit_replaces_the_first(self): """Create a duplicate content unit with different ``artifacts`` and same ``relative_path``. Artifacts are unique by ``relative_path`` and ``file``. """ delete_orphans() content_api = ContentFilesApi(self.client) repo_api = RepositoriesFileApi(self.client) versions_api = RepositoriesFileVersionsApi(self.client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) artifact = gen_artifact() # create first content unit. content_attrs = gen_file_content_attrs(artifact) content_attrs["repository"] = repo.pulp_href response = content_api.create(**content_attrs) monitor_task(response.task) artifact = gen_artifact(file=__file__) # create second content unit. second_content_attrs = gen_file_content_attrs(artifact) second_content_attrs["repository"] = repo.pulp_href second_content_attrs["relative_path"] = content_attrs["relative_path"] response = content_api.create(**second_content_attrs) monitor_task(response.task) repo_latest_version = versions_api.read( repo_api.read(repo.pulp_href).latest_version_href) self.assertEqual( repo_latest_version.content_summary.present["file.file"]["count"], 1)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = api.Client(cls.cfg, api.json_handler) cls.core_client = CoreApiClient(configuration=cls.cfg.get_bindings_config()) cls.file_client = gen_file_client() cls.content_api = ContentFilesApi(cls.file_client) cls.repo_api = RepositoriesFileApi(cls.file_client) cls.versions_api = RepositoriesFileVersionsApi(cls.file_client) cls.remote_api = RemotesFileApi(cls.file_client) cls.exporter_api = ExportersPulpApi(cls.core_client) cls.exports_api = ExportersCoreExportsApi(cls.core_client) (cls.repos, cls.remotes) = cls._setup_repositories()
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = api.Client(cls.cfg, api.json_handler) cls.file_client = gen_file_client() cls.content_api = ContentFilesApi(cls.file_client) cls.repo_api = RepositoriesFileApi(cls.file_client) cls.versions_api = RepositoriesFileVersionsApi(cls.file_client) cls.remote_api = RemotesFileApi(cls.file_client) cls.publication_api = PublicationsFileApi(cls.file_client) cls.exporter_api = ExportersFilesystemApi(cls.file_client) cls.exports_api = ExportersFileExportsApi(cls.file_client) cls.repos, cls.remotes, cls.publications = cls._setup_repositories()
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) core_client = CoreApiClient(configuration) file_client = FileApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_content_api = ContentFilesApi(file_client) cls.tasks_api = TasksApi(core_client) cls.migration_plans_api = MigrationPlansApi(migration_client) set_pulp2_snapshot(name='file_base_4repos')
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) file_client = FileApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_remote_api = RemotesFileApi(file_client) cls.file_distribution_api = DistributionsFileApi(file_client) cls.file_publication_api = PublicationsFileApi(file_client) cls.file_content_api = ContentFilesApi(file_client) cls.migration_plans_api = MigrationPlansApi(migration_client) cls.pulp2content_api = Pulp2ContentApi(migration_client) cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration() configuration.username = '******' configuration.password = '******' configuration.host = 'http://pulp' configuration.safe_chars_for_path_param = '/' core_client = CoreApiClient(configuration) file_client = FileApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_content_api = ContentFilesApi(file_client) cls.tasks_api = TasksApi(core_client) cls.migration_plans_api = MigrationPlansApi(migration_client)
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) file_client = FileApiClient(configuration) rpm_client = RpmApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for File cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_remote_api = RemotesFileApi(file_client) cls.file_distribution_api = DistributionsFileApi(file_client) cls.file_publication_api = PublicationsFileApi(file_client) cls.file_content_api = ContentFilesApi(file_client) # Create api clients for RPM cls.rpm_repo_api = RepositoriesRpmApi(rpm_client) cls.rpm_repo_versions_api = RepositoriesRpmVersionsApi(rpm_client) cls.rpm_remote_api = RemotesRpmApi(rpm_client) cls.rpm_distribution_api = DistributionsRpmApi(rpm_client) cls.rpm_publication_api = PublicationsRpmApi(rpm_client) cls.rpm_content_apis = { 'advisory': ContentAdvisoriesApi(rpm_client), 'disttree': ContentDistributionTreesApi(rpm_client), 'modulemd': ContentModulemdsApi(rpm_client), 'modulemd-defaults': ContentModulemdDefaultsApi(rpm_client), 'category': ContentPackagecategoriesApi(rpm_client), 'environment': ContentPackageenvironmentsApi(rpm_client), 'group': ContentPackagegroupsApi(rpm_client), 'langpack': ContentPackagelangpacksApi(rpm_client), 'package': ContentPackagesApi(rpm_client), } # Create api clients for Migration cls.migration_plans_api = MigrationPlansApi(migration_client) cls.pulp2content_api = Pulp2ContentApi(migration_client) cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)
return artifact # Configure HTTP basic authorization: basic configuration = Configuration() configuration.username = "******" configuration.password = "******" configuration.safe_chars_for_path_param = "/" core_client = CoreApiClient(configuration) file_client = FileApiClient(configuration) # Create api clients for all resource types artifacts = ArtifactsApi(core_client) filerepoversions = RepositoriesFileVersionsApi(file_client) filecontent = ContentFilesApi(file_client) filedistributions = DistributionsFileApi(file_client) filepublications = PublicationsFileApi(file_client) fileremotes = RemotesFileApi(file_client) filerepositories = RepositoriesFileApi(file_client) tasks = TasksApi(core_client) uploads = UploadsApi(core_client) # Test creating an Artifact from a 10mb file uploaded in 1mb chunks with NamedTemporaryFile() as downloaded_file: response = requests.get("https://fixtures.pulpproject.org/file-large/1.iso") response.raise_for_status() downloaded_file.write(response.content) artifact = upload_file_in_chunks(downloaded_file.name)
class RepoVersionRetentionTestCase(unittest.TestCase): """Test retain_repo_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_retain_repo_versions(self): """Test repo version retention.""" self._create_repo_versions({"retain_repo_versions": 1}) versions = self.version_api.list(file_file_repository_href=self.repo.pulp_href).results self.assertEqual(len(versions), 1) latest_version = self.version_api.read( file_file_repository_version_href=self.repo.latest_version_href ) self.assertEqual(latest_version.number, 3) self.assertEqual(latest_version.content_summary.present["file.file"]["count"], 3) self.assertEqual(latest_version.content_summary.added["file.file"]["count"], 3) def test_retain_repo_versions_on_update(self): """Test repo version retention when retain_repo_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 retain_repo_versions to 2 result = self.repo_api.partial_update(self.repo.pulp_href, {"retain_repo_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) latest_version = self.version_api.read( file_file_repository_version_href=self.repo.latest_version_href ) self.assertEqual(latest_version.number, 3) self.assertEqual(latest_version.content_summary.present["file.file"]["count"], 3) self.assertEqual(latest_version.content_summary.added["file.file"]["count"], 1) def test_autodistribute(self): """Test repo version retention with autopublish/autodistribute.""" self._create_repo_versions({"retain_repo_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 manifest = download_content_unit(self.cfg, self.distro.to_dict(), "PULP_MANIFEST") self.assertEqual(manifest.decode("utf-8").count("\n"), len(self.content))