From 291eaa6bf69aefca647ea2205ba7753be14cb91a Mon Sep 17 00:00:00 2001 From: Gerrod Date: Thu, 27 Jun 2024 10:03:41 -0400 Subject: [PATCH] Merge pull request #692 from gerrod3/package-type-filter-fix Fix package_types filter breaking others (cherry picked from commit a37d040b901d70a527c208fab9edef486039a205) --- CHANGES/691.bugfix | 1 + pulp_python/app/tasks/sync.py | 2 +- pulp_python/tests/functional/api/test_sync.py | 17 ++++++ pulp_python/tests/functional/conftest.py | 58 +++++++++++++++++++ pulp_python/tests/functional/constants.py | 1 + 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 CHANGES/691.bugfix diff --git a/CHANGES/691.bugfix b/CHANGES/691.bugfix new file mode 100644 index 00000000..448af729 --- /dev/null +++ b/CHANGES/691.bugfix @@ -0,0 +1 @@ +Fixed the `package_types` filter breaking other remote filters. diff --git a/pulp_python/app/tasks/sync.py b/pulp_python/app/tasks/sync.py index c4f93dfa..f2ba69c7 100644 --- a/pulp_python/app/tasks/sync.py +++ b/pulp_python/app/tasks/sync.py @@ -80,7 +80,7 @@ def create_bandersnatch_config(remote): config["plugins"]["enabled"] += "prerelease_release\n" if remote.package_types: rrfm = "regex_release_file_metadata" - config["plugins"]["enabled"] += rrfm + config["plugins"]["enabled"] += f"{rrfm}\n" if not config.has_section(rrfm): config.add_section(rrfm) config[rrfm]["any:release_file.packagetype"] = "\n".join(remote.package_types) diff --git a/pulp_python/tests/functional/api/test_sync.py b/pulp_python/tests/functional/api/test_sync.py index b64e8404..79a07b0c 100644 --- a/pulp_python/tests/functional/api/test_sync.py +++ b/pulp_python/tests/functional/api/test_sync.py @@ -641,6 +641,23 @@ def test_no_platform_sync(self): ) +@pytest.mark.parallel +def test_sync_multiple_filters( + python_repo_with_sync, python_remote_factory, python_content_summary +): + """Tests sync with multiple filters.""" + remote = python_remote_factory( + includes=PYTHON_LG_PROJECT_SPECIFIER, + package_types=["bdist_wheel"], + keep_latest_packages=1, + prereleases=False + ) + repo = python_repo_with_sync(remote) + + summary = python_content_summary(repository_version=repo.latest_version_href) + assert summary.present["python.python"]["count"] == PYTHON_LG_FIXTURE_COUNTS["multi"] + + @pytest.mark.parallel def test_proxy_sync( python_repo, diff --git a/pulp_python/tests/functional/conftest.py b/pulp_python/tests/functional/conftest.py index d3674530..408f46a9 100644 --- a/pulp_python/tests/functional/conftest.py +++ b/pulp_python/tests/functional/conftest.py @@ -1,4 +1,5 @@ import pytest +import uuid from pulp_smash.pulp3.utils import gen_distribution, gen_repo from pulp_python.tests.functional.utils import gen_python_remote @@ -9,6 +10,7 @@ DistributionsPypiApi, PublicationsPypiApi, RepositoriesPythonApi, + RepositoriesPythonVersionsApi, RemotesPythonApi, ) @@ -29,6 +31,12 @@ def python_repo_api_client(python_bindings_client): return RepositoriesPythonApi(python_bindings_client) +@pytest.fixture +def python_repo_version_api_client(python_bindings_client): + """Provides the Python Repository Version API client object.""" + return RepositoriesPythonVersionsApi(python_bindings_client) + + @pytest.fixture def python_distro_api_client(python_bindings_client): """Provides the Python Distribution API client object.""" @@ -55,6 +63,16 @@ def python_publication_api_client(python_bindings_client): # Object Generation Fixtures +@pytest.fixture +def python_repo_factory(python_repo_api_client, gen_object_with_cleanup): + """A factory to generate a Python Repository with auto-cleanup.""" + def _gen_python_repo(**kwargs): + kwargs.setdefault("name", str(uuid.uuid4())) + return gen_object_with_cleanup(python_repo_api_client, kwargs) + + return _gen_python_repo + + @pytest.fixture def python_repo(python_repo_api_client, gen_object_with_cleanup): """Creates a Python Repository and deletes it at test cleanup time.""" @@ -92,3 +110,43 @@ def _gen_python_remote(**kwargs): return gen_object_with_cleanup(python_remote_api_client, body) yield _gen_python_remote + + +@pytest.fixture +def python_repo_with_sync( + python_repo_api_client, python_repo_factory, python_remote_factory, monitor_task +): + """A factory to generate a Python Repository synced with the passed in Remote.""" + def _gen_python_repo_sync(remote=None, mirror=False, repository=None, **body): + kwargs = {} + if pulp_domain := body.get("pulp_domain"): + kwargs["pulp_domain"] = pulp_domain + remote = remote or python_remote_factory(**kwargs) + repo = repository or python_repo_factory(**body) + sync_body = {"mirror": mirror, "remote": remote.pulp_href} + monitor_task(python_repo_api_client.sync(repo.pulp_href, sync_body).task) + return python_repo_api_client.read(repo.pulp_href) + + yield _gen_python_repo_sync + + +@pytest.fixture +def python_content_summary(python_repo_api_client, python_repo_version_api_client): + """Get a summary of the repository version's content.""" + def _gen_summary(repository_version=None, repository=None, version=None): + if repository_version is None: + repo_href = get_href(repository) + if version: + repo_ver_href = f"{repo_href}versions/{version}/" + else: + repo_ver_href = python_repo_api_client.read(repo_href).latest_version_href + else: + repo_ver_href = get_href(repository_version) + return python_repo_version_api_client.read(repo_ver_href).content_summary + + yield _gen_summary + + +def get_href(item): + """Tries to get the href from the given item, whether it is a string or object.""" + return item if isinstance(item, str) else item.pulp_href diff --git a/pulp_python/tests/functional/constants.py b/pulp_python/tests/functional/constants.py index 698464ce..b04b79ac 100644 --- a/pulp_python/tests/functional/constants.py +++ b/pulp_python/tests/functional/constants.py @@ -155,6 +155,7 @@ "latest_3": 37, "sdist": 24, "bdist_wheel": 54, + "multi": 26, # keep_latest=1, package_types="bdist_wheel", prereleases=False } DJANGO_LATEST_3 = 4 # latest version has 2 dists, each other has 1