示例#1
0
 def _setup_content(cls):
     cls._setup_repositories(cls.export_repos)
     cls._setup_remotes()
     repository_sync_data_a = AnsibleRepositorySyncURL(
         remote=cls.remotes[0].pulp_href)
     repository_sync_data_b = AnsibleRepositorySyncURL(
         remote=cls.remotes[1].pulp_href)
     sync_response_a = cls.repo_api.sync(cls.export_repos[0].pulp_href,
                                         repository_sync_data_a)
     sync_response_b = cls.repo_api.sync(cls.export_repos[1].pulp_href,
                                         repository_sync_data_b)
     monitor_task(sync_response_a.task)
     monitor_task(sync_response_b.task)
     repo_ver_a = cls.repo_ver_api.read(
         f"{cls.export_repos[0].pulp_href}versions/1/")
     repo_ver_b = cls.repo_ver_api.read(
         f"{cls.export_repos[1].pulp_href}versions/1/")
     cls.export_content_count[
         "collection_version"] = repo_ver_a.content_summary.added[
             "ansible.collection_version"]["count"]
     cls.export_content_count[
         "collection_deprecation"] = repo_ver_a.content_summary.added[
             "ansible.collection_deprecation"]["count"]
     cls.export_content_count["role"] = repo_ver_b.content_summary.added[
         "ansible.role"]["count"]
示例#2
0
    def test_noop_resync_collections_from_pulp(self):
        """Test whether sync yields no-op when repo hasn't changed since last sync."""
        second_body = gen_ansible_remote(
            url=self.distribution.client_url,
            requirements_file=self.requirements_file,
            sync_dependencies=False,
        )
        second_remote = self.remote_collection_api.create(second_body)
        self.addCleanup(self.remote_collection_api.delete,
                        second_remote.pulp_href)

        second_repo = self._create_repo_and_sync_with_remote(second_remote)

        second_content = self.cv_api.list(
            repository_version=f"{second_repo.pulp_href}versions/1/")
        self.assertGreaterEqual(len(second_content.results), 1)

        # Resync
        repository_sync_data = AnsibleRepositorySyncURL(
            remote=second_remote.pulp_href, optimize=True)
        sync_response = self.repo_api.sync(second_repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        second_repo = self.repo_api.read(second_repo.pulp_href)
        task = tasks.read(sync_response.task)

        msg = "no-op: {url} did not change since last sync".format(
            url=second_remote.url)
        messages = [r.message for r in task.progress_reports]
        self.assertIn(msg, str(messages))
    def create_install_scenario(self, body):
        """Create Install scenario."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

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

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = AnsibleRepositorySyncURL(
            remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Create a distribution.
        body = gen_distribution()
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_create.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])

        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)
        return distribution
示例#4
0
def _sync_and_assert(remote, ansible_repo, ansible_repo_api_client,
                     ansible_collection_version_api_client):
    body = AnsibleRepositorySyncURL(remote=remote.pulp_href)
    monitor_task(
        ansible_repo_api_client.sync(ansible_repo.pulp_href, body).task)

    content_response = ansible_collection_version_api_client.list(
        repository_version=f"{ansible_repo.versions_href}1/")
    assert content_response.count == 1
示例#5
0
    def _sync_repo(self, repo, **kwargs):
        """
        Sync the repo with optional `kwarg` parameters passed on to the sync method.

        Args:
            repo: The repository to sync

        Returns:
            repository: The updated repository after the sync is complete
        """
        repository_sync_data = AnsibleRepositorySyncURL(**kwargs)
        sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)
        return repo
    def create_install_scenario(self, body, collection_name):
        """Create Install scenario."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

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

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = AnsibleRepositorySyncURL(
            remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Create a distribution.
        body = gen_distribution()
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_create.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])

        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

        with tempfile.TemporaryDirectory() as temp_dir:
            # FIXME Use --no-deps while https://pulp.plan.io/issues/7751 is not addressed
            cmd = "ansible-galaxy collection install {} -c -s {} -p {} --no-deps".format(
                collection_name, distribution.client_url, temp_dir)

            directory = "{}/ansible_collections/{}".format(
                temp_dir, collection_name.replace(".", "/"))

            self.assertTrue(not path.exists(directory),
                            "Directory {} already exists".format(directory))

            subprocess.run(cmd.split())

            self.assertTrue(path.exists(directory),
                            "Could not find directory {}".format(directory))
示例#7
0
    def test_install_role(self):
        """Test whether ansible-galaxy can install a Role hosted by Pulp."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        body = gen_ansible_remote(url=ANSIBLE_ELASTIC_FIXTURE_URL)
        remote = self.remote_role_api.create(body)
        self.addCleanup(self.remote_role_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = AnsibleRepositorySyncURL(
            remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Create a distribution.
        body = gen_distribution()
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_create.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])

        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = "ansible-galaxy role install {} -c -s {} -p {}".format(
                ANSIBLE_ELASTIC_ROLE, distribution.client_url, temp_dir)

            directory = "{}/{}".format(temp_dir,
                                       ANSIBLE_ELASTIC_ROLE_NAMESPACE_NAME)

            self.assertTrue(not path.exists(directory),
                            "Directory {} already exists".format(directory))

            subprocess.run(cmd.split())

            self.assertTrue(path.exists(directory),
                            "Could not find directory {}".format(directory))
示例#8
0
    def create_install_scenario(self, body, collection_name):
        """Create Install scenario."""
        repo = self.repo_api.create(gen_repo(name="pre_upgrade"))

        remote = self.remote_collection_api.create(body)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = AnsibleRepositorySyncURL(
            remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Create a distribution.
        body = gen_distribution()
        body["base_path"] = "pulp_pre_upgrade_test"
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_create.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = "ansible-galaxy collection install {} -c -s {} -p {}".format(
                collection_name, distribution.client_url, temp_dir)

            directory = "{}/ansible_collections/{}".format(
                temp_dir, collection_name.replace(".", "/"))

            self.assertTrue(not path.exists(directory),
                            "Directory {} already exists".format(directory))

            subprocess.run(cmd.split())

            self.assertTrue(path.exists(directory),
                            "Could not find directory {}".format(directory))