Ejemplo n.º 1
0
    def setUpClass(cls):
        """Sync a remote repository and create a new distribution pointing to the repository."""
        client_api = gen_container_client()
        cls.blobs_api = ContentBlobsApi(client_api)
        cls.manifests_api = ContentManifestsApi(client_api)
        cls.tags_api = ContentTagsApi(client_api)
        cls.repo_api = RepositoriesContainerApi(client_api)
        cls.remote_api = RemotesContainerApi(client_api)
        cls.dist_api = DistributionsContainerApi(client_api)

        cls.repo = cls.repo_api.create(gen_repo())
        cls.remote = cls.remote_api.create(gen_container_remote())
        body = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        response = cls.repo_api.sync(cls.repo.pulp_href, body)
        monitor_task(response.task)

        cls.repo = cls.repo_api.read(cls.repo.pulp_href)

        response = cls.dist_api.create(
            gen_distribution(repository=cls.repo.pulp_href))
        cls.distro = cls.dist_api.read(
            monitor_task(response.task).created_resources[0])

        relative_path = os.path.join("v2/", f"{cls.distro.base_path}/")
        cls.dist_url = urljoin(PULP_CONTENT_HOST_BASE_URL, relative_path)
Ejemplo n.º 2
0
    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.
        """
        repo = self.client.post(CONTAINER_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['pulp_href'])

        remote = self.client.post(CONTAINER_REMOTE_PATH, gen_container_remote())
        self.addCleanup(self.client.delete, remote['pulp_href'])

        # Sync the repository.
        self.assertIsNone(repo['latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['pulp_href'])
        self.assertIsNotNone(repo['latest_version_href'])

        # Sync the repository again.
        latest_version_href = repo['latest_version_href']
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['pulp_href'])
        self.assertEqual(latest_version_href, repo['latest_version_href'])
Ejemplo n.º 3
0
    def setUpClass(cls):
        """Create class wide-variables."""
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.page_handler)

        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)

        cls.repository = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)

        distribution_data = gen_distribution(repository=cls.repository.pulp_href)
        distribution_response = cls.distributions_api.create(
            ContainerContainerDistribution(**distribution_data)
        )
        created_resources = monitor_task(distribution_response.task).created_resources
        cls.distribution = cls.distributions_api.read(created_resources[0])
Ejemplo n.º 4
0
    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"])
Ejemplo n.º 5
0
    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 = self.client.post(CONTAINER_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['pulp_href'])

        remote = self.client.post(CONTAINER_REMOTE_PATH, gen_container_remote())
        self.addCleanup(self.client.delete, remote['pulp_href'])

        sync(self.cfg, remote, repo)

        cmd = 'lsof -t +D {}'.format(MEDIA_PATH).split()
        response = cli_client.run(cmd).stdout
        self.assertEqual(len(response), 0, response)
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     cls.from_repo = cls.client.post(CONTAINER_REPO_PATH, gen_repo())
     remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
     cls.remote = cls.client.post(CONTAINER_REMOTE_PATH, remote_data)
     delete_orphans(cls.cfg)
Ejemplo n.º 8
0
 def setUpClass(cls):
     """Sync pulp/test-fixture-1 so we can copy content from it."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     cls.from_repo = cls.client.post(CONTAINER_REPO_PATH, gen_repo())
     remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
     cls.remote = cls.client.post(CONTAINER_REMOTE_PATH, remote_data)
     sync(cls.cfg, cls.remote, cls.from_repo)
     latest_version = cls.client.get(cls.from_repo['pulp_href'])['latest_version_href']
     cls.latest_from_version = "repository_version={version}".format(version=latest_version)
Ejemplo n.º 9
0
    def test_02_create_same_name(self):
        """Try to create a second remote with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/PulpQE/pulp-smash/issues/1055>`_.
        """
        body = gen_container_remote()
        body['name'] = self.remote['name']
        with self.assertRaises(HTTPError):
            self.client.post(CONTAINER_REMOTE_PATH, body)
Ejemplo n.º 10
0
    def test_02_create_same_name(self):
        """Try to create a second remote with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/pulp/pulp-smash/issues/1055>`_.
        """
        body = gen_container_remote()
        body["name"] = self.remote.name
        with self.assertRaises(ApiException):
            self.remote_api.create(body)
Ejemplo n.º 11
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_container_remote()
        del body["url"]
        with self.assertRaises(ApiException):
            RemotesContainerApi(gen_container_client()).create(body)
Ejemplo n.º 12
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/PulpQE/pulp-smash/issues/984>`_
        """
        body = gen_container_remote()
        del body['url']
        with self.assertRaises(HTTPError):
            api.Client(config.get_config()).post(CONTAINER_REMOTE_PATH, body)
Ejemplo n.º 13
0
    def setUpClass(cls):
        """Create class-wide variables.

        1. Create a repository.
        2. Create a remote pointing to external registry.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()
        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        cls.client = api.Client(cls.cfg, api.code_handler)
        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.distributions_api = DistributionsContainerApi(client_api)

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.repositories_api.create(
                ContainerContainerRepository(**gen_repo()))

            # Step 2
            cls.remote = cls.remotes_api.create(gen_container_remote())

            # Step 3
            sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
            sync_response = cls.repositories_api.sync(_repo.pulp_href,
                                                      sync_data)
            monitor_task(sync_response.task)
            cls.repo = cls.repositories_api.read(_repo.pulp_href)

            # Step 4.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(
                    **gen_distribution(repository=cls.repo.pulp_href,
                                       base_path="pulp_pre_upgrade_test")))
            created_resources = monitor_task(
                distribution_response.task).created_resources
            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo = cls.distributions_api.read(
                distribution.pulp_href)

            # remove callback if everything goes well
            stack.pop_all()
Ejemplo n.º 14
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.client_api = gen_container_client()

        cls.repository_api = RepositoriesContainerApi(cls.client_api)
        cls.from_repo = cls.repository_api.create(
            ContainerContainerRepository(**gen_repo()))

        cls.remote_api = RemotesContainerApi(cls.client_api)
        remote_data = gen_container_remote(upstream_name=PULP_FIXTURE_1)
        cls.remote = cls.remote_api.create(remote_data)

        delete_orphans()
Ejemplo n.º 15
0
def _gen_verbose_remote():
    """Return a semi-random dict for use in defining a remote.

    For most tests, it's desirable to create remotes with as few attributes
    as possible, so that the tests can specifically target and attempt to break
    specific features. This module specifically targets remotes, so it makes
    sense to provide as many attributes as possible.

    Note that 'username' and 'password' are write-only attributes.
    """
    attrs = gen_container_remote()
    attrs.update({
        "password": utils.uuid4(),
        "username": utils.uuid4(),
        "policy": choice(ON_DEMAND_DOWNLOAD_POLICIES)
    })
    return attrs
Ejemplo n.º 16
0
    def setUpClass(cls):
        """Create class wide-variables."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        cls.repository = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Ejemplo n.º 17
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            [
                "container.add_containerrepository",
                "container.add_containerremote",
            ]
        )
        cls.user_repov_remover = gen_user(
            [
                "container.delete_containerrepository_versions",
                "container.view_containerrepository",
            ]
        )
        cls.user_repo_remover = gen_user(
            [
                "container.delete_containerrepository",
                "container.view_containerrepository",
            ]
        )
        cls.user_reader = gen_user(["container.view_containerrepository"])
        cls.user_helpless = gen_user([])

        # sync a repo
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo())
        )
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        )
        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            model_roles=[
                "container.containerrepository_creator",
                "container.containerremote_creator",
            ]
        )
        cls.user_repov_remover = gen_user(
            model_roles=[
                "container.containerrepository_content_manager",
            ]
        )
        # TODO: Not sure what is the right role for this user...
        cls.user_repo_remover = gen_user(
            model_roles=[
                "container.containerrepository_owner",
            ]
        )
        cls.user_reader = gen_user(model_roles=["container.containerrepository_viewer"])
        cls.user_helpless = gen_user()

        # sync a repo
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo())
        )
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=PULP_FIXTURE_1)
        )
        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Ejemplo n.º 20
0
    def setUpClass(cls):
        """Sync pulp/test-fixture-1 so we can copy content from it."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)

        cls.from_repo = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.from_repo.pulp_href, sync_data)
        monitor_task(sync_response.task)

        cls.latest_from_version = cls.repositories_api.read(
            cls.from_repo.pulp_href
        ).latest_version_href
Ejemplo n.º 21
0
    def sync_repository_with_whitelisted_tags(self, whitelist_tags):
        """Sync a new repository with the whitelisted tags passed as an argument."""
        self.repository = self.repositories_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(self.repositories_api.delete,
                        self.repository.pulp_href)

        remote_data = gen_container_remote(
            upstream_name=DOCKERHUB_PULP_FIXTURE_1,
            whitelist_tags=whitelist_tags)
        remote = self.remotes_api.create(remote_data)
        self.addCleanup(self.remotes_api.delete, remote.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)

        sync_response = self.repositories_api.sync(self.repository.pulp_href,
                                                   repository_sync_data)
        monitor_task(sync_response.task)
        repository = self.repositories_api.read(self.repository.pulp_href)
        self.assertIsNotNone(repository.latest_version_href)
Ejemplo n.º 22
0
    def test_all(self):
        """
        Sync a repository using a Remote url that does not exist.

        Test that we get a task failure.

        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(CONTAINER_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['pulp_href'])

        remote = client.post(
            CONTAINER_REMOTE_PATH,
            gen_container_remote(url="http://i-am-an-invalid-url.com/invalid/")
        )
        self.addCleanup(client.delete, remote['pulp_href'])

        with self.assertRaises(exceptions.TaskReportError):
            sync(cfg, remote, repo)
Ejemplo n.º 23
0
    def setUpClass(cls):
        """Create class wide-variables."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)
        cls.namespaces_api = PulpContainerNamespacesApi(api_client)

        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)

        cls.repository = cls.repositories_api.create(
            ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(
            ContainerContainerRemote(**remote_data))

        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href,
                                                  sync_data)
        monitor_task(sync_response.task)
Ejemplo n.º 24
0
    def sync_repository_with_filtered_tags(self,
                                           include_tags=None,
                                           exclude_tags=None):
        """Sync a new repository with the included tags passed as an argument."""
        self.repository = self.repositories_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(self.repositories_api.delete,
                        self.repository.pulp_href)

        remote_data = gen_container_remote(
            upstream_name=DOCKERHUB_PULP_FIXTURE_1,
            include_tags=include_tags,
            exclude_tags=exclude_tags,
        )
        remote = self.remotes_api.create(remote_data)
        self.addCleanup(self.remotes_api.delete, remote.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)

        sync_response = self.repositories_api.sync(self.repository.pulp_href,
                                                   repository_sync_data)
        monitor_task(sync_response.task)
    def setUpClass(cls):
        """Create class wide-variables."""
        cls.cfg = config.get_config()

        token_auth = cls.cfg.hosts[0].roles['token auth']
        client = cli.Client(cls.cfg)
        client.run(
            'openssl ecparam -genkey -name prime256v1 -noout -out {}'.format(
                token_auth['private key']).split())
        client.run('openssl ec -in {} -pubout -out {}'.format(
            token_auth['private key'], token_auth['public key']).split())

        cls.client = api.Client(cls.cfg, api.page_handler)

        cls.repository = cls.client.post(CONTAINER_REPO_PATH, gen_repo())
        remote_data = gen_container_remote(
            upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.client.post(CONTAINER_REMOTE_PATH, remote_data)
        sync(cls.cfg, cls.remote, cls.repository)

        cls.distribution = cls.client.using_handler(api.task_handler).post(
            CONTAINER_DISTRIBUTION_PATH,
            gen_distribution(repository=cls.repository['pulp_href']))
Ejemplo n.º 26
0
    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)
Ejemplo n.º 28
0
    def setUpClass(cls):
        """Create class-wide variables.

        1. Create a repository.
        2. Create a remote pointing to external registry.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository
        5. Create another container distribution to the serve the repository version

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()

        token_auth = cls.cfg.hosts[0].roles['token auth']
        client = cli.Client(cls.cfg)
        client.run('openssl ecparam -genkey -name prime256v1 -noout -out {}'
                   .format(token_auth['private key']).split())
        client.run('openssl ec -in {} -pubout -out {}'.format(
            token_auth['private key'], token_auth['public key']).split())

        cls.client = api.Client(cls.cfg, api.page_handler)
        cls.teardown_cleanups = []

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.client.post(CONTAINER_REPO_PATH, gen_repo())
            cls.teardown_cleanups.append((cls.client.delete, _repo['pulp_href']))

            # Step 2
            cls.remote = cls.client.post(
                CONTAINER_REMOTE_PATH, gen_container_remote()
            )
            cls.teardown_cleanups.append(
                (cls.client.delete, cls.remote['pulp_href'])
            )

            # Step 3
            sync(cls.cfg, cls.remote, _repo)
            cls.repo = cls.client.get(_repo['pulp_href'])

            # Step 4.
            response_dict = cls.client.using_handler(api.task_handler).post(
                CONTAINER_DISTRIBUTION_PATH,
                gen_distribution(repository=cls.repo['pulp_href'])
            )
            distribution_href = response_dict['pulp_href']
            cls.distribution_with_repo = cls.client.get(distribution_href)
            cls.teardown_cleanups.append(
                (cls.client.delete, cls.distribution_with_repo['pulp_href'])
            )

            # Step 5.
            response_dict = cls.client.using_handler(api.task_handler).post(
                CONTAINER_DISTRIBUTION_PATH,
                gen_distribution(repository_version=cls.repo['latest_version_href'])
            )
            distribution_href = response_dict['pulp_href']
            cls.distribution_with_repo_version = cls.client.get(distribution_href)
            cls.teardown_cleanups.append(
                (cls.client.delete, cls.distribution_with_repo_version['pulp_href'])
            )

            # remove callback if everything goes well
            stack.pop_all()
Ejemplo n.º 29
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repository_api = RepositoriesContainerApi(api_client)
        cls.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)

        cls.namespace_api = PulpContainerNamespacesApi(api_client)
        cls.registry = cli.RegistryClient(cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest, "Tests require podman/docker")
        cls.registry_name = urlparse(cfg.get_base_url()).netloc

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            [
                "container.add_containerrepository",
                "container.add_containerremote",
                "container.add_containernamespace",
                "container.add_containerdistribution",
            ]
        )
        cls.user_creator2 = gen_user(
            [
                "container.add_containernamespace",
                "container.add_containerdistribution",
            ]
        )
        cls.user_reader = gen_user(
            [
                "container.view_containerrepository",
                "container.view_containerpushrepository",
            ]
        )
        cls.user_reader2 = gen_user(["container.view_containerrepository"])
        cls.user_reader3 = gen_user(["container.view_containerpushrepository"])
        cls.user_helpless = gen_user([])

        # create a push repo with user_creator
        image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a"
        cls._pull(image_path)
        repo_name = "testcontent/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator)
        cls.push_repository = cls.pushrepository_api.list(name=repo_name).results[0]

        # create a second push repo with user_creator2
        image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_b"
        cls._pull(image_path)
        repo_name = "testcontent2/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator2)
        cls.push_repository2 = cls.pushrepository_api.list(name=repo_name).results[0]

        # sync a repo with user_creator
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo())
        )
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        )
        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Ejemplo n.º 30
0
    def setUpClass(cls):
        """Create class-wide variables and delete orphans.

        1. Create a repository.
        2. Create a remote pointing to external registry with policy=on_demand.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository
        5. Create another container distribution to the serve the repository version

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()
        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.distributions_api = DistributionsContainerApi(client_api)

        cls.teardown_cleanups = []

        delete_orphans()

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.repositories_api.create(
                ContainerContainerRepository(**gen_repo()))
            cls.teardown_cleanups.append(
                (cls.repositories_api.delete, _repo.pulp_href))

            # Step 2
            cls.remote = cls.remotes_api.create(
                gen_container_remote(policy="on_demand"))
            cls.teardown_cleanups.append(
                (cls.remotes_api.delete, cls.remote.pulp_href))

            # Step 3
            sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
            sync_response = cls.repositories_api.sync(_repo.pulp_href,
                                                      sync_data)
            monitor_task(sync_response.task)

            cls.repo = cls.repositories_api.read(_repo.pulp_href)
            cls.artifacts_api = ArtifactsApi(core_client)
            cls.artifact_count = cls.artifacts_api.list().count

            # Step 4.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(**gen_distribution(
                    repository=cls.repo.pulp_href)))
            created_resources = monitor_task(
                distribution_response.task).created_resources

            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo = cls.distributions_api.read(
                distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete,
                 cls.distribution_with_repo.pulp_href))

            # Step 5.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(**gen_distribution(
                    repository_version=cls.repo.latest_version_href)))
            created_resources = monitor_task(
                distribution_response.task).created_resources
            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo_version = cls.distributions_api.read(
                distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete,
                 cls.distribution_with_repo_version.pulp_href))

            # remove callback if everything goes well
            stack.pop_all()