From df8b5ad22dbac8537d427975815e05b4894ed492 Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Mon, 24 Mar 2025 15:49:23 -0400 Subject: [PATCH] Add support for pull-through repository saving fixes: #815 https://issues.redhat.com/browse/PULP-417 --- CHANGES/815.feature | 2 + pulp_python/app/models.py | 1 + pulp_python/app/pypi/views.py | 3 +- .../tests/functional/api/test_full_mirror.py | 47 +++++++++++++++---- 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 CHANGES/815.feature diff --git a/CHANGES/815.feature b/CHANGES/815.feature new file mode 100644 index 00000000..c5457dd4 --- /dev/null +++ b/CHANGES/815.feature @@ -0,0 +1,2 @@ +Added support for automatically saving pull-through content to a repository. +Requires pulpcore 3.74 or later. diff --git a/pulp_python/app/models.py b/pulp_python/app/models.py index c326a54a..39e98d39 100644 --- a/pulp_python/app/models.py +++ b/pulp_python/app/models.py @@ -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) diff --git a/pulp_python/app/pypi/views.py b/pulp_python/app/pypi/views.py index 634c89c5..39a02094 100644 --- a/pulp_python/app/pypi/views.py +++ b/pulp_python/app/pypi/views.py @@ -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 = ( diff --git a/pulp_python/tests/functional/api/test_full_mirror.py b/pulp_python/tests/functional/api/test_full_mirror.py index cc66cfdb..b2e9b404 100644 --- a/pulp_python/tests/functional/api/test_full_mirror.py +++ b/pulp_python/tests/functional/api/test_full_mirror.py @@ -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( @@ -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