def test_sync_with_invalid_requirements(self): """ Sync with invalid requirement. This test targets the following issue: 5250 * `<https://pulp.plan.io/issues/5250>`_ This test does the following: Try to create a Collection remote with invalid requirement """ collection_remote = self.client.using_handler(api.echo_handler).post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote(url=GALAXY_ANSIBLE_BASE_URL, requirements_file="INVALID"), ) self.assertEqual(collection_remote.status_code, 400, collection_remote) requirements = "collections:\n - name: test.test\n source: http://example.com" collection_remote = self.client.using_handler(api.echo_handler).post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote(url=GALAXY_ANSIBLE_BASE_URL, requirements_file=requirements), ) self.assertEqual(collection_remote.status_code, 400, collection_remote)
def test_remote_urls(self): """This tests that the remote url ends with a "/". This test targets https://pulp.plan.io/issues/7767 ansible-galaxy requires a trailing slash: https://git.io/JTMAA It does make an exception for "https://galaxy.ansible.com": https://git.io/JTMpk """ body = gen_ansible_remote(url="http://galaxy.ansible.com/api") with self.assertRaises(HTTPError) as exc: self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.assertEqual(exc.exception.response.status_code, 400) body = gen_ansible_remote(url="http://galaxy.example.com") with self.assertRaises(HTTPError) as exc: self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.assertEqual(exc.exception.response.status_code, 400) body = gen_ansible_remote(url="https://galaxy.ansible.com") remote = self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.addCleanup(self.client.delete, remote["pulp_href"]) body = gen_ansible_remote(url="https://galaxy.ansible.com/") remote = self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.addCleanup(self.client.delete, remote["pulp_href"])
def test_sync_mirror_defaults_to_false(self): """Sync multiple remotes into the same repo to ensure mirror defaults to `False`.""" body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file= "collections:\n - robertdebock.ansible_development_environment", sync_dependencies=False, ) remote_a = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote_a.pulp_href) body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="collections:\n - testing.k8s_demo_collection", sync_dependencies=False, ) remote_b = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote_b.pulp_href) repo = self._create_repo_and_sync_with_remote(remote_a) self.assertEqual(repo.latest_version_href, f"{repo.versions_href}1/") repo = self._sync_repo(repo, remote=remote_b.pulp_href) self.assertEqual(repo.latest_version_href, f"{repo.versions_href}2/") # Assert more CollectionVersion are present in the first sync than the second if repo.retain_repo_versions and repo.retain_repo_versions > 1: content_version_one = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") self.assertGreaterEqual(len(content_version_one.results), 3) content_version_two = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/2/") self.assertEqual(len(content_version_two.results), 4)
def test_sync_collections_from_pulp_using_mirror_second_time(self): """Test sync collections from pulp server using a mirror option the second time.""" body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="collections:\n - testing.k8s_demo_collection", sync_dependencies=False, ) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) first_repo = self._create_repo_and_sync_with_remote(remote) distribution = self._create_distribution_from_repo(first_repo) second_body = gen_ansible_remote(url=distribution.client_url, ) 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) first_content = self.cv_api.list( repository_version=f"{first_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(first_content.results), 1) second_content = self.cv_api.list( repository_version=f"{second_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(second_content.results), 1)
def test_mirror_sync_with_requirements(self): """ Sync multiple remotes into the same repo with mirror as `True` using requirements. This test targets the following issue: 5250 * `<https://pulp.plan.io/issues/5250>`_ This test does the following: 1. Create a repo. 2. Create two remotes a. Role remote b. Collection remote 3. Sync the repo with Role remote. 4. Sync the repo with Collection remote with ``Mirror=True``. 5. Verify whether the content in the latest version of the repo has only Collection content and Role content is deleted. """ # Step 1 repo = self.client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) # Step 2 role_remote = self.client.post(ANSIBLE_REMOTE_PATH, gen_ansible_remote()) self.addCleanup(self.client.delete, role_remote["pulp_href"]) collection_remote = self.client.post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote( url=ANSIBLE_COLLECTION_TESTING_URL_V2, requirements_file=ANSIBLE_COLLECTION_REQUIREMENT, ), ) self.addCleanup(self.client.delete, collection_remote["pulp_href"]) # Step 3 sync(self.cfg, role_remote, repo) repo = self.client.get(repo["pulp_href"]) self.assertIsNotNone(repo["latest_version_href"], repo) self.assertDictEqual(get_added_content_summary(repo), ANSIBLE_FIXTURE_CONTENT_SUMMARY) # Step 4 sync(self.cfg, collection_remote, repo, mirror=True) repo = self.client.get(repo["pulp_href"]) added_content_summary = get_added_content_summary(repo) self.assertGreaterEqual( added_content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], ANSIBLE_COLLECTION_FIXTURE_COUNT) # Step 5 content_summary = get_content_summary(repo) self.assertGreaterEqual( content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], ANSIBLE_COLLECTION_FIXTURE_COUNT) self.assertDictEqual(get_removed_content_summary(repo), ANSIBLE_FIXTURE_CONTENT_SUMMARY)
def test_sync_supports_mirror_option_true(self): """Sync multiple remotes into the same repo with mirror as `True`.""" body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file= "collections:\n - robertdebock.ansible_development_environment", ) remote_a = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote_a.pulp_href) body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="collections:\n - testing.k8s_demo_collection", ) remote_b = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote_b.pulp_href) repo = self._create_repo_and_sync_with_remote(remote_a) self.assertEqual(repo.latest_version_href, f"{repo.versions_href}1/") repo = self._sync_repo(repo, remote=remote_b.pulp_href, mirror=True) self.assertEqual(repo.latest_version_href, f"{repo.versions_href}2/") # Assert more CollectionVersion are present in the first sync than the second content_version_one = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") self.assertGreaterEqual(len(content_version_one.results), 3) content_version_two = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/2/") self.assertEqual(len(content_version_two.results), 1)
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2) 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 = RepositorySyncURL(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) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) url = (distribution.client_url + "/api/v3/collections/" + ANSIBLE_DEMO_COLLECTION.replace(".", "/")) body = gen_ansible_remote(url=url) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Check content of both repos. original_content = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") mirror_content = self.cv_api.list( repository_version=f"{mirror_repo.pulp_href}versions/1/") self.assertTrue( mirror_content.results) # check that we have some results self.assertEqual(sorted(original_content.results), sorted(mirror_content.results))
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=GALAXY_ANSIBLE_BASE_URL, requirements_file=DEMO_REQUIREMENTS) 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 = RepositorySyncURL(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) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) body = gen_ansible_remote(url=distribution.client_url, requirements_file=DEMO_REQUIREMENTS) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Check content of both repos. original_content = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") mirror_content = self.cv_api.list( repository_version=f"{mirror_repo.pulp_href}versions/1/") self.assertTrue( mirror_content.results) # check that we have some results self.assertEqual(sorted(original_content.results), sorted(mirror_content.results))
def test_sync_metadata_only_collection_from_pulp(self): """Sync collections from another Pulp that only has metadata. Create a GitRemote Create a repository Sync from the remote Create distribution to serve the repository Create CollectionRemote pointing to the distribution. Create a second repository. Sync using the CollectionRemote into the second repository. Assert content is added to the second repository. """ body = gen_ansible_remote( url="https://github.com/ansible-collections/amazon.aws/", metadata_only=True, git_ref="2.1.0", ) amazon_remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, amazon_remote.pulp_href) self.first_repo = self._create_repo_and_sync_with_remote(amazon_remote) content = self.cv_api.list( repository_version=self.first_repo.latest_version_href) self.assertEqual(len(content.results), 1) # Create a distribution. body = gen_distribution() body["repository"] = self.first_repo.pulp_href distribution_create = self.distributions_api.create(body) created_resources = monitor_task( distribution_create.task).created_resources self.distribution = self.distributions_api.read(created_resources[0]) self.addCleanup(self.distributions_api.delete, self.distribution.pulp_href) self.requirements_file = "collections:\n - amazon.aws" second_body = gen_ansible_remote( url=self.distribution.client_url, requirements_file=self.requirements_file, sync_dependencies=False, include_pulp_auth=True, ) 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) first_content = self.cv_api.list( repository_version=f"{self.first_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(first_content.results), 1) second_content = self.cv_api.list( repository_version=f"{second_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(second_content.results), 1)
def _setup_remotes(cls): """ Sets up and saves a role remote and collection remote. """ body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="collections:\n - testing.k8s_demo_collection", ) remote_a = cls.remote_collection_api.create(body) remote_b = cls.remote_role_api.create(gen_ansible_remote()) cls.remotes.extend([remote_a, remote_b])
def _setup_remotes(cls): """ Sets up and saves a role remote and collection remote. """ body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="collections:\n - robertdebock.ansible_development_environment", ) remote_a = cls.remote_collection_api.create(body) remote_b = cls.remote_role_api.create(gen_ansible_remote()) cls.remotes.extend([remote_a, remote_b])
def test_sync_collection_from_git(self): """Sync collections from Git repositories and then install one of them.""" body = gen_ansible_remote( url="https://github.com/pulp/pulp_installer.git") installer_remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, installer_remote.pulp_href) repo = self._create_repo_and_sync_with_remote(installer_remote) content = self.cv_api.list(repository_version=repo.latest_version_href) self.assertEqual(len(content.results), 1) repo = self._sync_repo(repo, remote=installer_remote.pulp_href) content = self.cv_api.list(repository_version=repo.latest_version_href) self.assertEqual(len(content.results), 1) body = gen_ansible_remote(url="https://github.com/pulp/squeezer.git") squeezer_remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, squeezer_remote.pulp_href) repo = self._sync_repo(repo, remote=squeezer_remote.pulp_href) content = self.cv_api.list(repository_version=repo.latest_version_href) self.assertEqual(len(content.results), 2) # 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) collection_name = "pulp.squeezer" with tempfile.TemporaryDirectory() as temp_dir: # The install command needs --pre so a pre-release collection versions install cmd = "ansible-galaxy collection install --pre {} -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))
def test_sync_collections_from_pulp(self): """Test sync collections from pulp server.""" cfg = config.get_config() client = api.Client(cfg) repo = client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo["pulp_href"]) remote = client.post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2), ) self.addCleanup(client.delete, remote["pulp_href"]) sync(cfg, remote, repo) repo = client.get(repo["pulp_href"]) distribution = client.post( ANSIBLE_DISTRIBUTION_PATH, gen_distribution(repository=repo["pulp_href"])) self.addCleanup(client.delete, distribution["pulp_href"]) second_repo = client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(client.delete, second_repo["pulp_href"]) url = reduce( urljoin, ( cfg.get_base_url(), "pulp_ansible/galaxy/", distribution["base_path"] + "/", "api/v2/collections", ), ) pulp_remote = client.post(ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote(url=url)) self.addCleanup(client.delete, pulp_remote["pulp_href"]) sync(cfg, pulp_remote, second_repo) second_repo = client.get(second_repo["pulp_href"]) self.assertEqual(get_content(repo), get_content(second_repo)) galaxy_collection_data = client.get(ANSIBLE_COLLECTION_TESTING_URL_V2) pulp_collection_data = client.get( urljoin(url + "/", ANSIBLE_DEMO_COLLECTION.replace(".", "/"))) galaxy_keys = [ i for i in galaxy_collection_data.keys() if i != "deprecated" ].sort() pulp_keys = [*pulp_collection_data].sort() self.assertEqual(galaxy_keys, pulp_keys)
def test_sync_collections_from_pulp(self): """Test sync collections from pulp server.""" cfg = config.get_config() client = api.Client(cfg) repo = client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo["pulp_href"]) remote = client.post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote( url=GALAXY_ANSIBLE_BASE_URL, requirements_file=DEMO_REQUIREMENTS, ), ) self.addCleanup(client.delete, remote["pulp_href"]) sync(cfg, remote, repo) repo = client.get(repo["pulp_href"]) distribution = client.post( ANSIBLE_DISTRIBUTION_PATH, gen_distribution(repository=repo["pulp_href"])) self.addCleanup(client.delete, distribution["pulp_href"]) second_repo = client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(client.delete, second_repo["pulp_href"]) url = distribution["client_url"] body = gen_ansible_remote(url=url, requirements_file=DEMO_REQUIREMENTS) pulp_remote = client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.addCleanup(client.delete, pulp_remote["pulp_href"]) sync(cfg, pulp_remote, second_repo) second_repo = client.get(second_repo["pulp_href"]) self.assertEqual(get_content(repo), get_content(second_repo)) galaxy_collection_data = client.get( urljoin( f"{GALAXY_ANSIBLE_BASE_URL}/api/v2/collections/", ANSIBLE_DEMO_COLLECTION.replace(".", "/"), )) pulp_collection_data = client.get( urljoin(f"{url}/api/v2/collections/", ANSIBLE_DEMO_COLLECTION.replace(".", "/"))) galaxy_keys = [ i for i in galaxy_collection_data.keys() if i != "deprecated" ].sort() pulp_keys = [*pulp_collection_data].sort() self.assertEqual(galaxy_keys, pulp_keys)
def test_consume_content(self): """Test whether ansible-galaxy can install content hosted by Pulp.""" repo = self.client.post(REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL) remote = self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) 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"]) # Create distribution distribution = self.client.post( ANSIBLE_DISTRIBUTION_PATH, gen_distribution(repository=repo["pulp_href"])) self.addCleanup(self.client.delete, distribution["pulp_href"]) with tempfile.TemporaryDirectory() as temp_dir: self.cli_client.run( "ansible-galaxy collection install {} -c -s {} -p {}".format( COLLECTION_WHITELIST, distribution["client_url"], temp_dir).split()) directory = "{}/ansible_collections/{}".format( temp_dir, COLLECTION_WHITELIST.replace(".", "/")) self.assertTrue(path.exists(directory), "Could not find directory {}".format(directory))
def test_sync_with_proxy_auth(self): """Test sync collections from pulp server.""" if not os.getenv("PULP_PROXY_TEST"): self.skipTest("Proxy isn't set.") second_body = gen_ansible_remote( url=self.distribution.client_url, requirements_file=self.requirements_file, sync_dependencies=False, proxy_url="http://ciproxy:8899", proxy_username="******", proxy_password="******", ) 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) first_content = self.cv_api.list( repository_version=f"{self.first_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(first_content.results), 1) second_content = self.cv_api.list( repository_version=f"{second_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(second_content.results), 1)
def test_sync_with_aws_requirements(self): """Test to sync down amazon.aws versions.""" requirements_file = "collections:\n - amazon.aws" repo = self.client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) collection_remote = self.client.post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote( url=GALAXY_ANSIBLE_BASE_URL, requirements_file=requirements_file, ), ) self.addCleanup(self.client.delete, collection_remote["pulp_href"]) sync(self.cfg, collection_remote, repo, mirror=True) repo = self.client.get(repo["pulp_href"]) added_content_summary = get_added_content_summary(repo) self.assertGreaterEqual( added_content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], 67) content_summary = get_content_summary(repo) self.assertGreaterEqual( content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], 67)
def test_sync_collection_from_git_commit_sha(self): """Sync collections from Git repositories with git_ref that is a commit sha.""" body = gen_ansible_remote( url="https://github.com/ansible-collections/amazon.aws/", metadata_only=True, git_ref="d0b54fc082cb63f63d34246c8fe668e19e74777c", ) amazon_remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, amazon_remote.pulp_href) repo = self._create_repo_and_sync_with_remote(amazon_remote) content = self.cv_api.list(repository_version=repo.latest_version_href) self.assertEqual(len(content.results), 1) # 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) version = self.collections_versions_v3api.read("aws", "amazon", distribution.base_path, "1.5.1") self.assertEqual(version.git_url, "https://github.com/ansible-collections/amazon.aws/") self.assertEqual(version.git_commit_sha, "d0b54fc082cb63f63d34246c8fe668e19e74777c") self.assertEqual(version.download_url, None)
def test_sync_metadata_only_collection_from_git(self): """Sync collections from Git repositories with metadata_only=True.""" body = gen_ansible_remote( url="https://github.com/ansible-collections/amazon.aws/", metadata_only=True, git_ref="2.1.0", ) amazon_remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, amazon_remote.pulp_href) repo = self._create_repo_and_sync_with_remote(amazon_remote) content = self.cv_api.list(repository_version=repo.latest_version_href) self.assertEqual(len(content.results), 1) # 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) version = self.collections_versions_v3api.read("aws", "amazon", distribution.base_path, "2.1.0") self.assertEqual(version.git_url, "https://github.com/ansible-collections/amazon.aws/") self.assertEqual(version.git_commit_sha, "013162a952c7b2d11c7e2ebf443d8d4d7a21e95a") self.assertEqual(version.download_url, None)
def test_sync_with_requirements(self): """ Sync using a complex requirements.yml file. This test targets the following issue: 5250 * `<https://pulp.plan.io/issues/5250>`_ """ # Step 1 repo = self.client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) collection_remote = self.client.post( ANSIBLE_COLLECTION_REMOTE_PATH, gen_ansible_remote( url=GALAXY_ANSIBLE_BASE_URL, requirements_file=ANSIBLE_COLLECTION_REQUIREMENT, ), ) self.addCleanup(self.client.delete, collection_remote["pulp_href"]) sync(self.cfg, collection_remote, repo, mirror=True) repo = self.client.get(repo["pulp_href"]) added_content_summary = get_added_content_summary(repo) self.assertGreaterEqual( added_content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], ANSIBLE_COLLECTION_FIXTURE_COUNT) content_summary = get_content_summary(repo) self.assertGreaterEqual( content_summary[ANSIBLE_COLLECTION_CONTENT_NAME], ANSIBLE_COLLECTION_FIXTURE_COUNT)
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 test_sync_with_invalid_requirements(self): """Sync with invalid requirement.""" body = gen_ansible_remote( url="https://galaxy.ansible.com", requirements_file="INAVLID", ) self.assertRaises(ApiException, self.remote_collection_api.create, body)
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(REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo['_href']) remote = self.client.post(ANSIBLE_REMOTE_PATH, gen_ansible_remote()) self.addCleanup(self.client.delete, remote['_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)
def test_successive_syncs_repo_version(self): """Test whether successive syncs update repository versions. This test targets the following issue: * `Pulp #5000 <https://pulp.plan.io/issues/5000>`_ Do the following: 1. Create a repository, and a remote. 2. Sync the repository an arbitrary number of times. 3. Verify that the repository version is equal to the previous number of syncs. """ repo = self.client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2) remote = self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.addCleanup(self.client.delete, remote["pulp_href"]) number_of_syncs = randint(1, 5) for _ in range(number_of_syncs): sync(self.cfg, remote, repo) repo = self.client.get(repo["pulp_href"]) path = urlsplit(repo["latest_version_href"]).path latest_repo_version = int(path.split("/")[-2]) self.assertEqual(latest_repo_version, 1, repo)
def test_sync(self): """Sync repository with the ansible plugin collections content type. This test targets the following issue: * `Pulp #4913 <https://pulp.plan.io/issues/4913>`_ 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. """ repo = self.client.post(ANSIBLE_REPO_PATH, gen_repo()) self.addCleanup(self.client.delete, repo["pulp_href"]) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2) remote = self.client.post(ANSIBLE_COLLECTION_REMOTE_PATH, body) self.addCleanup(self.client.delete, remote["pulp_href"]) # Sync the repository. self.assertEqual(repo["latest_version_href"], f"{repo['pulp_href']}versions/0/") sync(self.cfg, remote, repo) repo = self.client.get(repo["pulp_href"]) self.assertIsNotNone(repo["latest_version_href"], repo)
def test_remote_urls(self): """This tests that the remote url ends with a "/".""" body = gen_ansible_remote(url="http://galaxy.ansible.com/api") self.assertRaises(ApiException, self.remote_collection_api.create, body) body = gen_ansible_remote(url="http://galaxy.example.com") self.assertRaises(ApiException, self.remote_collection_api.create, body) body = gen_ansible_remote(url="https://galaxy.ansible.com") remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) body = gen_ansible_remote(url="https://galaxy.ansible.com/") remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)
def test_install_collection(self): """Test whether ansible-galaxy can install a Collection hosted by Pulp.""" url = self.cfg.get_content_host_base_url( ) + "/pulp_ansible/galaxy/pulp_pre_upgrade_test/" body = gen_ansible_remote(url=url, requirements_file=DEMO_REQUIREMENTS, include_pulp_auth=True) self.create_install_scenario(body, ANSIBLE_DEMO_COLLECTION)
def test_all(self): """Test whether a particular repository version can be published. 1. Create a repository with at least 2 repository versions. 2. Create a publication by supplying the latest ``repository_version``. 3. Assert that the publication ``repository_version`` attribute points to the latest repository version. 4. Create a publication by supplying the non-latest ``repository_version``. 5. Assert that the publication ``repository_version`` attribute points to the supplied repository version. 6. Assert that an exception is raised when providing two different repository versions to be published at same time. """ cfg = config.get_config() client = api.Client(cfg, api.json_handler) body = gen_ansible_remote() remote = client.post(ANSIBLE_REMOTE_PATH, body) self.addCleanup(client.delete, remote['_href']) repo = client.post(REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) sync(cfg, remote, repo) publisher = client.post(ANSIBLE_PUBLISHER_PATH, gen_ansible_publisher()) self.addCleanup(client.delete, publisher['_href']) # Step 1 repo = client.post(REPO_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) for ansible_content in client.get( ANSIBLE_ROLE_CONTENT_PATH)['results']: client.post(repo['_versions_href'], {'add_content_units': [ansible_content['_href']]}) version_hrefs = tuple(ver['_href'] for ver in get_versions(repo)) non_latest = choice(version_hrefs[:-1]) # Step 2 publication = publish(cfg, publisher, repo) # Step 3 self.assertEqual(publication['repository_version'], version_hrefs[-1]) # Step 4 publication = publish(cfg, publisher, repo, non_latest) # Step 5 self.assertEqual(publication['repository_version'], non_latest) # Step 6 with self.assertRaises(HTTPError): body = { 'repository': repo['_href'], 'repository_version': non_latest } client.post(urljoin(publisher['_href'], 'publish/'), body)
def test_install_collection_with_token_from_automation_hub(self): """Test whether ansible-galaxy can install a Collection hosted by Pulp.""" body = gen_ansible_remote( url=TOKEN_AUTH_COLLECTION_TESTING_URL, auth_url=AH_AUTH_URL, token=os.environ["AUTOMATION_HUB_TOKEN_AUTH"], tls_validation=False, ) self.create_install_scenario(body, TOKEN_DEMO_COLLECTION)
def test_02_metadata_only_remote(self): """Create a remote where `metadata_only` is set to True.""" body = gen_ansible_remote( url="https://github.com/geerlingguy/ansible-role-adminer.git", metadata_only=True ) remote = self.remote_git_api.create(body) self.addCleanup(self.remote_git_api.delete, remote.pulp_href) for k, v in body.items(): self.assertEqual(body[k], getattr(remote, k))