Skip to content

Commit 14208f4

Browse files
committed
Add support for pull-through repository saving
fixes: #815 https://issues.redhat.com/browse/PULP-417
1 parent 1530d2f commit 14208f4

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

CHANGES/815.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added support for automatically saving pull-through content to a repository.
2+
Requires pulpcore 3.74 or later.

pulp_python/app/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class PythonRepository(Repository, AutoAddObjPermsMixin):
275275
TYPE = "python"
276276
CONTENT_TYPES = [PythonPackageContent]
277277
REMOTE_TYPES = [PythonRemote]
278+
PULL_THROUGH_SUPPORTED = True
278279

279280
autopublish = models.BooleanField(default=False)
280281

pulp_python/app/pypi/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ def retrieve(self, request, path, package):
275275
# Should I redirect if the normalized name is different?
276276
normalized = canonicalize_name(package)
277277
if self.distribution.remote:
278-
if not repo_ver or not content.filter(name__normalize=normalized).exists():
279-
return self.pull_through_package_simple(normalized, path, self.distribution.remote)
278+
return self.pull_through_package_simple(normalized, path, self.distribution.remote)
280279
if self.should_redirect(repo_version=repo_ver):
281280
return redirect(urljoin(self.base_content_url, f'{path}/simple/{normalized}/'))
282281
packages = (

pulp_python/tests/functional/api/test_full_mirror.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import requests
33
import subprocess
4-
4+
import time
55
from pulp_python.tests.functional.constants import (
66
PYPI_URL,
77
PYTHON_XS_FIXTURE_CHECKSUMS,
@@ -12,6 +12,7 @@
1212
from pypi_simple import ProjectPage
1313
from packaging.version import parse
1414
from urllib.parse import urljoin, urlsplit
15+
from random import sample
1516

1617

1718
def test_pull_through_install(
@@ -97,17 +98,48 @@ def test_pull_through_filter(python_remote_factory, python_distribution_factory)
9798

9899
@pytest.mark.parallel
99100
def test_pull_through_with_repo(
100-
python_repo_with_sync, python_remote_factory, python_distribution_factory
101+
python_repo_factory,
102+
python_remote_factory,
103+
python_distribution_factory,
104+
python_bindings,
105+
pulpcore_bindings,
106+
monitor_task,
107+
has_pulp_plugin,
101108
):
102-
"""Tests that if content is already in repository, pull-through isn't used."""
103-
remote = python_remote_factory()
104-
repo = python_repo_with_sync(remote)
109+
"""Tests that content is saved to repository."""
110+
remote = python_remote_factory(includes=[])
111+
repo = python_repo_factory()
105112
distro = python_distribution_factory(repository=repo.pulp_href, remote=remote.pulp_href)
106113

107-
url = urljoin(distro.base_url, "simple/shelf-reader/")
108-
project_page = ProjectPage.from_response(requests.get(url), "shelf-reader")
109-
110-
assert len(project_page.packages) == 2
111-
for package in project_page.packages:
112-
assert package.filename in PYTHON_XS_FIXTURE_CHECKSUMS
113-
assert "?redirect=" not in package.url
114+
# Perform a download of aiohttp to ensure it's saved to the repo
115+
url = urljoin(distro.base_url, "simple/aiohttp/")
116+
project_page = ProjectPage.from_response(requests.get(url), "aiohttp")
117+
for package in sample(project_page.packages, 3):
118+
assert "?redirect=" in package.url
119+
r = requests.get(package.url)
120+
assert r.status_code == 200
121+
122+
if has_pulp_plugin("core", max="3.73"):
123+
pytest.skip("Pull-through repository save added in 3.74")
124+
125+
for _ in range(15):
126+
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn)
127+
if tasks.count == 3:
128+
break
129+
time.sleep(1) # Wait for tasks to be created
130+
else:
131+
assert tasks.count == 3
132+
133+
for task in tasks.results:
134+
monitor_task(task.pulp_href)
135+
136+
repo = python_bindings.RepositoriesPythonApi.read(repo.pulp_href)
137+
assert repo.latest_version_href[-2] == "3"
138+
content = python_bindings.ContentPackagesApi.list(repository_version=repo.latest_version_href)
139+
assert content.count == 3
140+
141+
# Check that getting content that is already present doesn't trigger a task
142+
r = requests.get(package.url)
143+
assert r.status_code == 200
144+
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn)
145+
assert tasks.count == 3

0 commit comments

Comments
 (0)