def do_publish(self, download_policy):
        """Publish repository synced with lazy download policy."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)
        publications = PublicationsFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(policy=download_policy)
        remote = remote_api.create(body)
        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)
        publication = publications.read(publication_href)
        self.assertIsNotNone(publication.repository_version, publication)
    def do_test(self, policy):
        """Access lazy synced content on using content endpoint."""
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.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 the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        # Assert that no HTTP error was raised.
        # Assert that the number of units present is according to the synced
        # feed.
        content = content_api.list().to_dict()["results"]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT, content)
Example #3
0
    def setUpClass(cls):
        """Create repos, remotes, and api-clients for all tests."""
        cls.cfg = config.get_config()
        cls.client = ApiClient(configuration=cls.cfg.get_bindings_config())
        file_client = gen_file_client()
        cls.admin_info = {
            "task_api": TasksApi(cls.client),
            "file_client": file_client,
            "remote_api": RemotesFileApi(file_client),
            "repo_api": RepositoriesFileApi(file_client),
        }
        cls.admin_info["a_remote"] = cls.admin_info["remote_api"].create(
            gen_file_remote(policy="on_demand")
        )
        cls.admin_info["a_repo"] = cls.admin_info["repo_api"].create(gen_repo())
        cls.admin_info["sync_data"] = RepositorySyncURL(remote=cls.admin_info["a_remote"].pulp_href)

        cls.new_user = gen_user()
        file_client = gen_file_client()
        cls.user_info = {
            "task_api": TasksApi(cls.client),
            "file_client": file_client,
            "remote_api": RemotesFileApi(file_client),
            "repo_api": RepositoriesFileApi(file_client),
        }
        cls.user_info["a_remote"] = cls.user_info["remote_api"].create(
            gen_file_remote(policy="on_demand")
        )
        cls.user_info["a_repo"] = cls.user_info["repo_api"].create(gen_repo())
        cls.user_info["sync_data"] = RepositorySyncURL(remote=cls.user_info["a_remote"].pulp_href)
Example #4
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphaned content units can be cleaned up."""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/")
        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)
        content = choice(get_content(repo.to_dict())[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        repo_api.modify(repo.pulp_href, dict(remove_content_units=[content["pulp_href"]]))

        artifacts_api = ArtifactsApi(core_client)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact is present on disk.
            relative_path = artifacts_api.read(content["artifact"]).file
            artifact_path = os.path.join(self.media_root, relative_path)
            cmd = ("ls", artifact_path)
            self.cli_client.run(cmd, sudo=True)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content["pulp_href"], content_units_href)

        content_before_cleanup = file_contents_api.list().count
        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 10})
        monitor_task(orphans_response.task)

        # assert content was not removed
        content_after_cleanup = file_contents_api.list().count
        self.assertEqual(content_after_cleanup, content_before_cleanup)

        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 0})
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content["pulp_href"], content_units_href)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact was removed from disk.
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
Example #5
0
    def do_test(self, url):
        """Sync repositories with the file 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. Assert that the correct number of units were added and are present
           in the repo.
        6. Sync the remote one more time.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of are present and that no units were
           added.
        """
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(url)
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        self.assertIsNotNone(repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        # Sync the repository again.
        latest_version_href = repo.latest_version_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)

        self.assertEqual(latest_version_href, repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
    def do_sync(self, download_policy):
        """Sync repositories with the different ``download_policy``.

        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. Assert that the correct number of possible units to be downloaded
           were shown.
        6. Sync the remote one more time in order to create another repository
           version.
        7. Assert that repository version is the same as the previous one.
        8. Assert that the same number of units are shown, and after the
           second sync no extra units should be shown, since the same remote
           was synced again.
        """
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(**{"policy": download_policy})
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        self.assertIsNotNone(repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        # Sync the repository again.
        latest_version_href = repo.latest_version_href
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        self.assertEqual(latest_version_href, repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Example #7
0
    def setUpClass(cls):
        """
        Initialize Pulp to make authorization assertions using client certificates.

        0. Create a FileRepository
        1. Create a FileRemote
        2. Sync in a few units we can use to fetch with
        3. Create a Publication
        4. Create a CertGuard with the CA cert used to sign all client certificates
        5. Create a Distribution for the publication that is protected by the CertGuard

        """
        cls.teardown_cleanups = []
        cls.cfg = config.get_config()

        file_client = gen_file_client()
        repo_api = RepositoriesFileApi(file_client)
        remote_api = RemotesFileApi(file_client)
        publications = PublicationsFileApi(file_client)
        cls.distributions_api = DistributionsFileApi(file_client)

        cls.repo = repo_api.create(gen_repo())
        cls.teardown_cleanups.append((repo_api.delete, cls.repo.pulp_href))

        body = gen_file_remote(policy="immediate")
        remote = remote_api.create(body)
        cls.teardown_cleanups.append((remote_api.delete, remote.pulp_href))

        # Sync a Repository
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(cls.repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        cls.repo = repo_api.read(cls.repo.pulp_href)

        # Create a publication.
        publish_data = FileFilePublication(repository=cls.repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        cls.teardown_cleanups.append((publications.delete, publication_href))

        content_guard_href = cls._setup_content_guard()

        # Create a distribution.
        body = gen_distribution()
        body["publication"] = publication_href
        body["content_guard"] = content_guard_href
        distribution_response = cls.distributions_api.create(body)
        created_resources = monitor_task(distribution_response.task)
        cls.distribution = cls.distributions_api.read(created_resources[0])
        cls.teardown_cleanups.append((cls.distributions_api.delete, cls.distribution.pulp_href))
Example #8
0
    def do_test(self, url):
        """Sync a repository given ``url`` on the remote."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(url=url)
        remote = remote_api.create(body)
        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)
        return monitor_task(sync_response.task)
Example #9
0
    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()
Example #10
0
 def setUpClass(cls):
     """Clean out Pulp before testing."""
     delete_orphans()
     client = gen_file_client()
     cls.cont_api = ContentFilesApi(client)
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
Example #11
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.file_client = gen_file_client()
     cls.repo_api = RepositoriesFileApi(cls.file_client)
     cls.publication_api = PublicationsFileApi(cls.file_client)
     cls.remote_api = RemotesFileApi(cls.file_client)
Example #12
0
    def setUpClass(cls):
        """Initialize class-wide variables"""
        cls.cfg = config.get_config()

        cls.api_client = api.Client(cls.cfg, api.json_handler)
        cls.file_client = FileApiClient(cls.cfg.get_bindings_config())
        cls.remotes_api = RemotesFileApi(cls.file_client)
Example #13
0
 def setUpClass(cls):
     """Sets up class"""
     client = gen_file_client()
     cls.cont_api = ContentFilesApi(client)
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
     cls.pub_api = PublicationsFileApi(client)
     cls.dis_api = DistributionsFileApi(client)
     cls.repo = cls.repo_api.create(gen_repo(autopublish=True))
     cls.remote = cls.remote_api.create(gen_file_remote())
     body = RepositorySyncURL(remote=cls.remote.pulp_href)
     created = monitor_task(
         cls.repo_api.sync(cls.repo.pulp_href, body).task).created_resources
     cls.repo = cls.repo_api.read(cls.repo.pulp_href)
     cls.pub1 = cls.pub_api.read(created[1])
     body = FileFilePublication(repository=cls.repo.pulp_href)
     cls.pub2 = cls.pub_api.read(
         monitor_task(cls.pub_api.create(body).task).created_resources[0])
     cls.pub3 = []
     response = cls.dis_api.create(
         gen_distribution(repository=cls.repo.pulp_href))
     cls.distro = cls.dis_api.read(
         monitor_task(response.task).created_resources[0])
     cls.distro2 = []
     cls.url = urljoin(PULP_CONTENT_BASE_URL, f"{cls.distro.base_path}/")
Example #14
0
 def setUpClass(cls):
     """Clean out Pulp before testing."""
     delete_orphans()
     client = gen_file_client()
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
     cls.publication_api = PublicationsFileApi(client)
     cls.distributions_api = DistributionsFileApi(client)
     cls.cfg = config.get_config()
Example #15
0
    def test_clean_specific_orphans(self):
        """Test whether the `content_hrefs` param removes specific orphans but not others"""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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 two orphaned content units.
        content_a = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][0]["pulp_href"]
        content_b = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][1]["pulp_href"]
        content_to_remove = dict(remove_content_units=[content_a, content_b])
        repo_api.modify(repo.pulp_href, content_to_remove)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)

        content_hrefs_dict = {"content_hrefs": [content_a]}
        orphans_response = self.orphans_cleanup_api.cleanup(content_hrefs_dict)
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)
Example #16
0
    def test_duplicate_file_sync(self):
        """Sync a repository with remotes containing same file names.

        This test does the following.

        1. Create a repository in pulp.
        2. Create two remotes containing the same file.
        3. Check whether the created repo has only one copy of the file.

        This test targets the following issue:

        `Pulp #4738 <https://pulp.plan.io/issues/4738>`_
        """
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

        # Step 1
        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        # Step 2
        remote = remote_api.create(gen_file_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)
        remote2 = remote_api.create(
            gen_file_remote(url=FILE2_FIXTURE_MANIFEST_URL))

        self.addCleanup(remote_api.delete, remote2.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)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        repository_sync_data = RepositorySyncURL(remote=remote2.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)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Example #17
0
    def test_all(self):
        """Verify whether is possible to create a remote without a URL.

        This test targets the following issues:

        * `Pulp #3395 <https://pulp.plan.io/issues/3395>`_
        * `Pulp Smash #984 <https://github.com/pulp/pulp-smash/issues/984>`_
        """
        body = gen_file_remote()
        del body["url"]
        with self.assertRaises(ApiException):
            RemotesFileApi(gen_file_client()).create(body)
Example #18
0
 def setUp(self):
     self.client = FileApiClient(self.cfg.get_bindings_config())
     self.remotes_api = RemotesFileApi(self.client)
     self.remote_attrs = {
         "name": utils.uuid4(),
         "url": FILE_FIXTURE_MANIFEST_URL,
         "ca_cert": None,
         "client_cert": None,
         "client_key": None,
         "tls_validation": False,
         "proxy_url": None,
         "username": "******",
         "password": "******",
         "download_concurrency": 10,
         "policy": "on_demand",
         "total_timeout": None,
         "connect_timeout": None,
         "sock_connect_timeout": None,
         "sock_read_timeout": None,
     }
     self.remote = self.remotes_api.create(self.remote_attrs)
Example #19
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = gen_file_client()

        cls.content_api = ContentFilesApi(cls.client)
        cls.repo_api = RepositoriesFileApi(cls.client)
        cls.remote_api = RemotesFileApi(cls.client)
        cls.publications_api = PublicationsFileApi(cls.client)
        cls.distributions_api = DistributionsFileApi(cls.client)

        cls.CUSTOM_MANIFEST = "TEST_MANIFEST"
Example #20
0
    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.repo_api = RepositoriesFileApi(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()
Example #21
0
    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)
Example #22
0
    def setUpClass(cls):
        """
        Create class-wide variables.

        Variables 'paths' and 'paths_updated' are defined as strings.
        In same way data are send from user.
        """
        cls.cfg = config.get_config()
        cls.file_client = gen_file_client()
        cls.file_remote_api = RemotesFileApi(cls.file_client)
        cls.file_acs_api = AcsFileApi(cls.file_client)
        cls.paths = ["backupone/PULP_MANIFEST", "backuptwo/manifest"]
        cls.paths_updated = ["backupone/test", "anotherbackup/PULP_MANIFEST"]
    def test_all(self):
        """Perform a lazy sync and change to immeditae to force download."""
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        client = gen_file_client()
        artifacts_api = ArtifactsApi(core_client)
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(policy=choice(ON_DEMAND_DOWNLOAD_POLICIES))
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository using a lazy download policy
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        artifacts = artifacts_api.list().to_dict()["results"]
        self.assertEqual(len(artifacts), 0, artifacts)

        # Update the policy to immediate
        response = remote_api.partial_update(remote.pulp_href,
                                             {"policy": "immediate"})
        monitor_task(response.task)
        remote = remote_api.read(remote.pulp_href)
        self.assertEqual(remote.policy, "immediate")

        # Sync using immediate download policy
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Assert that missing artifacts are downloaded
        artifacts = artifacts_api.list().to_dict()["results"]
        self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT, artifacts)
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = gen_file_client()
        cls.orphans_api = OrphansCleanupApi(core_client)
        cls.reclaim_api = RepositoriesReclaimSpaceApi(core_client)
        cls.artifacts_api = ArtifactsApi(core_client)
        cls.publication_api = PublicationsFileApi(cls.client)
        cls.distributions_api = DistributionsFileApi(cls.client)
        cls.repo_api = RepositoriesFileApi(cls.client)
        cls.remote_api = RemotesFileApi(cls.client)

        orphans_response = cls.orphans_api.cleanup(
            {"orphan_protection_time": 0})
        monitor_task(orphans_response.task)
Example #25
0
    def setUpClass(cls):
        """
        Create class-wide variables.

        Variables 'paths' and 'paths_updated' are defined as strings.
        In same way data are send from user.
        """
        cls.cfg = config.get_config()
        cls.file_client = gen_file_client()
        cls.repo_api = RepositoriesFileApi(cls.file_client)
        cls.file_remote_api = RemotesFileApi(cls.file_client)
        cls.file_acs_api = AcsFileApi(cls.file_client)
        cls.publication_api = PublicationsFileApi(cls.file_client)
        cls.distribution_api = DistributionsFileApi(cls.file_client)
        cls.paths = ["goodpath/PULP_MANIFEST", "test", "whatever/test"]
Example #26
0
    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()
Example #27
0
    def test_negative_create_file_remote_with_invalid_parameter(self):
        """Attempt to create file remote passing invalid parameter.

        Assert response returns an error 400 including ["Unexpected field"].

        This test targets the following issue:

        * `Pulp Smash #1085 <https://github.com/pulp/pulp-smash/issues/1085>`_
        """
        with self.assertRaises(ApiException) as exc:
            RemotesFileApi(gen_file_client()).create(
                gen_file_remote(foo="bar"))

        assert exc.exception.status == 400
        assert json.loads(exc.exception.body)["foo"] == ["Unexpected field"]
    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)
Example #29
0
    def setUpClass(cls):
        """Create repos, remotes, and api-clients for all tests."""
        cls.cfg = config.get_config()
        cls.client = ApiClient(configuration=cls.cfg.get_bindings_config())
        cls.task_api = TasksApi(cls.client)

        cls.file_client = gen_file_client()
        cls.remote_api = RemotesFileApi(cls.file_client)
        cls.repo_api = RepositoriesFileApi(cls.file_client)

        cls.good_remote = cls.remote_api.create(gen_file_remote(policy="on_demand"))
        cls.good_repo = cls.repo_api.create(gen_repo())
        cls.good_sync_data = RepositorySyncURL(remote=cls.good_remote.pulp_href)

        cls.bad_remote = cls.remote_api.create(
            gen_file_remote(
                "https://fixtures.pulpproject.org/THEREISNOFILEREPOHERE/", policy="on_demand"
            )
        )
        cls.bad_repo = cls.repo_api.create(gen_repo())
        cls.bad_sync_data = RepositorySyncURL(remote=cls.bad_remote.pulp_href)
    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)