Skip to content
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
2 changes: 2 additions & 0 deletions CHANGES/815.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added support for automatically saving pull-through content to a repository.
Requires pulpcore 3.74 or later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the lower bound bump? pyproject.toml needs updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't. If you have >=3.74 then you get the new behavior, else you don't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that wasn't clear. Thanks

1 change: 1 addition & 0 deletions pulp_python/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class PythonRepository(Repository, AutoAddObjPermsMixin):
TYPE = "python"
CONTENT_TYPES = [PythonPackageContent]
REMOTE_TYPES = [PythonRemote]
PULL_THROUGH_SUPPORTED = True

autopublish = models.BooleanField(default=False)

Expand Down
3 changes: 1 addition & 2 deletions pulp_python/app/pypi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ def retrieve(self, request, path, package):
# Should I redirect if the normalized name is different?
normalized = canonicalize_name(package)
if self.distribution.remote:
if not repo_ver or not content.filter(name__normalize=normalized).exists():
return self.pull_through_package_simple(normalized, path, self.distribution.remote)
return self.pull_through_package_simple(normalized, path, self.distribution.remote)
if self.should_redirect(repo_version=repo_ver):
return redirect(urljoin(self.base_content_url, f'{path}/simple/{normalized}/'))
packages = (
Expand Down
47 changes: 37 additions & 10 deletions pulp_python/tests/functional/api/test_full_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pypi_simple import ProjectPage
from packaging.version import parse
from urllib.parse import urljoin, urlsplit
from random import sample


def test_pull_through_install(
Expand Down Expand Up @@ -97,17 +98,43 @@ def test_pull_through_filter(python_remote_factory, python_distribution_factory)

@pytest.mark.parallel
def test_pull_through_with_repo(
python_repo_with_sync, python_remote_factory, python_distribution_factory
python_repo_factory,
python_remote_factory,
python_distribution_factory,
python_bindings,
pulpcore_bindings,
monitor_task,
has_pulp_plugin,
):
"""Tests that if content is already in repository, pull-through isn't used."""
remote = python_remote_factory()
repo = python_repo_with_sync(remote)
"""Tests that content is saved to repository."""
remote = python_remote_factory(includes=[])
repo = python_repo_factory()
distro = python_distribution_factory(repository=repo.pulp_href, remote=remote.pulp_href)

url = urljoin(distro.base_url, "simple/shelf-reader/")
project_page = ProjectPage.from_response(requests.get(url), "shelf-reader")
# Perform a download of aiohttp to ensure it's saved to the repo
url = urljoin(distro.base_url, "simple/aiohttp/")
project_page = ProjectPage.from_response(requests.get(url), "aiohttp")
for package in sample(project_page.packages, 3):
assert "?redirect=" in package.url
r = requests.get(package.url)
assert r.status_code == 200

assert len(project_page.packages) == 2
for package in project_page.packages:
assert package.filename in PYTHON_XS_FIXTURE_CHECKSUMS
assert "?redirect=" not in package.url
if has_pulp_plugin("core", max="3.73"):
pytest.skip("Pull-through repository save added in 3.74")

tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn)
assert tasks.count == 3

for task in tasks.results:
monitor_task(task.pulp_href)

repo = python_bindings.RepositoriesPythonApi.read(repo.pulp_href)
assert repo.latest_version_href[-2] == "3"
content = python_bindings.ContentPackagesApi.list(repository_version=repo.latest_version_href)
assert content.count == 3

# Check that getting content that is already present doesn't trigger a task
r = requests.get(package.url)
assert r.status_code == 200
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn)
assert tasks.count == 3