Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite and cleanup some tests #1711

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def test_tags_filter(
assert len(collections) == 0, collections


# Looks like orionutils are not meant to be used in parallel
# @pytest.mark.parallel
@pytest.mark.parallel
def test_content_unit_lifecycle(
ansible_collection_version_api_client, build_and_upload_collection, monitor_task
):
Expand Down
283 changes: 128 additions & 155 deletions pulp_ansible/tests/functional/api/collection/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Tests collection sync functionality that is common to both Galaxy V2 and V3."""
import datetime
import os

import pytest
import unittest

from pulp_ansible.tests.functional.utils import (
gen_ansible_remote,
SyncHelpersMixin,
Expand All @@ -15,157 +14,143 @@
from pulp_ansible.tests.functional.utils import monitor_task


class MirrorTestCase(TestCaseUsingBindings, SyncHelpersMixin):
"""Sync the ansible plugin collections content type."""
@pytest.mark.parallel
def test_sync_supports_mirror_option_true(
ansible_collection_remote_factory, ansible_sync_factory, ansible_collection_version_api_client
):
"""Sync multiple remotes into the same repo with mirror as `True`."""
remote_a = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - robertdebock.ansible_development_environment",
sync_dependencies=False,
)

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",
sync_dependencies=False,
)
remote_a = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote_a.pulp_href)
remote_b = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - testing.k8s_demo_collection",
sync_dependencies=False,
)

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, 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
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), 1)

def test_sync_supports_mirror_option_false(self):
"""Sync multiple remotes into the same repo with mirror as `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)
repository = ansible_sync_factory(remote=remote_a.pulp_href)
assert repository.latest_version_href == f"{repository.versions_href}1/"
repository = ansible_sync_factory(repository, remote=remote_b.pulp_href, mirror=True)
assert repository.latest_version_href == f"{repository.versions_href}2/"

body = gen_ansible_remote(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - testing.k8s_demo_collection",
sync_dependencies=False,
# Assert more CollectionVersion are present in the first sync than the second
if repository.retain_repo_versions and repository.retain_repo_versions > 1:
content_version_one = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/1/"
)
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=False)
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_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)
assert content_version_one.count >= 3
content_version_two = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/2/"
)
assert content_version_two.count == 1

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)


# TODO: Check each collection exists on new galaxy
class UniqueCollectionsTestCase(TestCaseUsingBindings, SyncHelpersMixin):
"""Collection sync tests for collections with unique properties."""

def test_sync_collection_with_long_tag(self):
"""Sync a collection that is known to have "longer" tag information."""
body = gen_ansible_remote(
url="https://old-galaxy.ansible.com/api/",
requirements_file="collections:\n - ibm.ibm_zos_core",
sync_dependencies=False,
)
remote = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)

repo = self._create_repo_and_sync_with_remote(remote)
@pytest.mark.parallel
def test_sync_supports_mirror_option_false(
ansible_collection_remote_factory, ansible_sync_factory, ansible_collection_version_api_client
):
"""Sync multiple remotes into the same repo with mirror as `False`."""
remote_a = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - robertdebock.ansible_development_environment",
sync_dependencies=False,
)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertGreaterEqual(len(content.results), 14)
remote_b = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - testing.k8s_demo_collection",
sync_dependencies=False,
)

def test_sync_collection_with_dot_slash_in_manifest(self):
"""Sync a collection that has a ./Manifest.json instead of Manifest.json."""
body = gen_ansible_remote(
url="https://old-galaxy.ansible.com/api/",
requirements_file="collections:\n - rshad.collection_demo",
sync_dependencies=False,
repository = ansible_sync_factory(remote=remote_a.pulp_href)
assert repository.latest_version_href == f"{repository.versions_href}1/"
repository = ansible_sync_factory(repository, remote=remote_b.pulp_href, mirror=False)
assert repository.latest_version_href == f"{repository.versions_href}2/"

# Assert more CollectionVersion are present in the second sync than the first
if repository.retain_repo_versions and repository.retain_repo_versions > 1:
content_version_one = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/1/"
)
remote = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)
assert content_version_one.count >= 3
content_version_two = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/2/"
)
assert content_version_two.count == 4

repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertGreaterEqual(len(content.results), 6)
def test_sync_mirror_defaults_to_false(
ansible_collection_remote_factory, ansible_sync_factory, ansible_collection_version_api_client
):
"""Sync multiple remotes into the same repo to ensure mirror defaults to `False`."""
remote_a = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - robertdebock.ansible_development_environment",
sync_dependencies=False,
)

def test_sync_collection_with_stranger_version_numbers_to_check_comparisons(self):
"""Sync a collection that has strange version numbers and ensure it syncs correctly."""
body = gen_ansible_remote(
url="https://old-galaxy.ansible.com/api/",
requirements_file="collections:\n - brightcomputing.bcm",
sync_dependencies=False,
remote_b = ansible_collection_remote_factory(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - testing.k8s_demo_collection",
sync_dependencies=False,
)

repository = ansible_sync_factory(remote=remote_a.pulp_href)
assert repository.latest_version_href == f"{repository.versions_href}1/"
repository = ansible_sync_factory(repository, remote=remote_b.pulp_href)
assert repository.latest_version_href == f"{repository.versions_href}2/"

# Assert more CollectionVersion are present in the second sync than the first
if repository.retain_repo_versions and repository.retain_repo_versions > 1:
content_version_one = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/1/"
)
remote = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)
assert content_version_one.count >= 3
content_version_two = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/2/"
)
assert content_version_two.count == 4

repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertGreaterEqual(len(content.results), 5)
@pytest.mark.parallel
@pytest.mark.parametrize(
"collection,old_galaxy,sync_dependencies,min_count",
[
pytest.param("ibm.ibm_zos_core", False, False, 14, id="with_long_tag"),
pytest.param("rshad.collection_demo", False, False, 6, id="with_dot_slash_in_manifest"),
pytest.param("brightcomputing.bcm", True, False, 5, id="with_strange_version_numbers"),
pytest.param("pulp.pulp_installer", False, True, 5, id="simple_dependency"),
],
)
def test_sync_collection_with_specialities(
collection,
old_galaxy,
sync_dependencies,
min_count,
ansible_collection_remote_factory,
ansible_sync_factory,
ansible_collection_version_api_client,
):
"""Sync a collection that is known to be special."""
remote = ansible_collection_remote_factory(
url="https://old-galaxy.ansible.com/api/"
if old_galaxy
else "https://galaxy.ansible.com/api/",
requirements_file=f"collections:\n - {collection}",
sync_dependencies=sync_dependencies,
)

repository = ansible_sync_factory(remote=remote.pulp_href)

content = ansible_collection_version_api_client.list(
repository_version=f"{repository.pulp_href}versions/1/"
)
assert content.count >= min_count


@unittest.skip("Skip until S3 error has been discovered.")
class FullDependenciesSync(TestCaseUsingBindings, SyncHelpersMixin):
"""
Collection sync tests for syncing collections and their dependencies.
Expand Down Expand Up @@ -197,14 +182,16 @@ def tearDownClass(cls):
@classmethod
def _build_and_publish_collections(cls):
"""Builds and publishes the collections to be used in this test."""
from django.conf import settings

cls.collections = []
cls.repo, cls.distro = cls._create_empty_repo_and_distribution(cls(), cleanup=False)

upload_api = PulpAnsibleArtifactsCollectionsV3Api(cls.client)
for cfg in TEST_COLLECTION_CONFIGS:
collection = build_collection("skeleton", config=cfg)
upload_response = upload_api.create(cls.distro.base_path, collection.filename)
api_root = os.environ.get("PULP_API_ROOT", "/pulp/")
api_root = settings.API_ROOT
monitor_task("{}api/v3/tasks/{}/".format(api_root, upload_response.task[-37:-1]))
cls.collections.append(collection)
cls.distro.client_url += "api/"
Expand All @@ -221,7 +208,7 @@ def test_simple_one_level_dependency(self):
repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertEqual(content.count, 2)
assert content.count == 2

def test_simple_multi_level_dependency(self):
"""Sync test.a which should get the dependency chain: test.b -> test.c -> test.d."""
Expand All @@ -236,7 +223,7 @@ def test_simple_multi_level_dependency(self):
repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertEqual(content.count, 4)
assert content.count == 4

def test_complex_one_level_dependency(self):
"""Sync test.f which should get 3 versions of test.h."""
Expand All @@ -251,7 +238,7 @@ def test_complex_one_level_dependency(self):
repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertEqual(content.count, 4)
assert content.count == 4

def test_complex_multi_level_dependency(self):
"""Sync test.e which should get test.f, test.d, test.g and 3 versions of test.h."""
Expand All @@ -266,21 +253,7 @@ def test_complex_multi_level_dependency(self):
repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/")
self.assertEqual(content.count, 7)

def test_v2_simple_dependency(self):
"""Checks that the dependency resolution works on v2 api codepath."""
body = gen_ansible_remote(
url="https://galaxy.ansible.com",
requirements_file="collections:\n - pulp.pulp_installer",
)
remote = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)

repo = self._create_repo_and_sync_with_remote(remote)

content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/", name="posix")
self.assertNotEqual(content.count, 0)
assert content.count == 7


@pytest.mark.skip("Skipped until fixture metadata has a published date")
Expand Down
Loading
Loading