Skip to content

Commit

Permalink
Merge pull request #693 from pulp/patchback/backports/3.11/a37d040b90…
Browse files Browse the repository at this point in the history
…1d70a527c208fab9edef486039a205/pr-692

[PR #692/a37d040b backport][3.11] Fix package_types filter breaking others
  • Loading branch information
gerrod3 authored Jun 27, 2024
2 parents 099089b + 580c676 commit 88a1d87
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/691.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the `package_types` filter breaking other remote filters.
2 changes: 1 addition & 1 deletion pulp_python/app/tasks/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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)
Expand Down
17 changes: 17 additions & 0 deletions pulp_python/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
92 changes: 92 additions & 0 deletions pulp_python/tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest
import subprocess
import uuid

from pulp_smash.pulp3.utils import gen_distribution
from pulp_python.tests.functional.utils import gen_python_remote
from pulp_python.tests.functional.constants import PYTHON_URL, PYTHON_EGG_FILENAME

from pulpcore.client.pulp_python import (
ApiClient,
Expand Down Expand Up @@ -110,3 +112,93 @@ 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 download_python_file(tmp_path, http_get):
"""Download a Python file and return its path."""
def _download_python_file(relative_path, url):
file_path = tmp_path / relative_path
with open(file_path, mode="wb") as f:
f.write(http_get(url))
return file_path

yield _download_python_file


@pytest.fixture
def python_file(download_python_file):
"""Get a default (shelf-reader.tar.gz) Python file."""
return download_python_file(PYTHON_EGG_FILENAME, PYTHON_URL)


@pytest.fixture
def python_content_factory(python_content_api_client, download_python_file, monitor_task):
"""A factory to create a Python Package Content."""
def _gen_python_content(relative_path=PYTHON_EGG_FILENAME, url=None, **body):
body["relative_path"] = relative_path
if url:
body["file"] = download_python_file(relative_path, url)
elif not any(x in body for x in ("artifact", "file", "upload")):
body["file"] = download_python_file(PYTHON_EGG_FILENAME, PYTHON_URL)
if repo := body.get("repository"):
repo_href = repo if isinstance(repo, str) else repo.pulp_href
body["repository"] = repo_href

task = python_content_api_client.create(**body).task
response = monitor_task(task)
return python_content_api_client.read(response.created_resources[0])

yield _gen_python_content


# Utility fixtures


@pytest.fixture
def shelf_reader_cleanup():
"""Take care of uninstalling shelf-reader before/after the test."""
cmd = ("pip", "uninstall", "shelf-reader", "-y")
subprocess.run(cmd)
yield
subprocess.run(cmd)


@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
1 change: 1 addition & 0 deletions pulp_python/tests/functional/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"latest_3": 49,
"sdist": 27,
"bdist_wheel": 63,
"multi": 33, # keep_latest=1, package_types="bdist_wheel", prereleases=False
}

DJANGO_LATEST_3 = 4 # latest version has 2 dists, each other has 1
Expand Down

0 comments on commit 88a1d87

Please sign in to comment.