From a739f318829beb7ef5761b18a2b3fe182af29d09 Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Mon, 23 Nov 2026 13:42:32 -0500 Subject: [PATCH] Use plain filename pull-through links when Redis is available Store the upstream url and digests of the files on a pull-through simple page in Redis, grouped per project, and link to the plain filenames. The wheel and its metadata then have different request paths, so the content cache can no longer serve one for the other. The entries are cleared when the remote's url, includes or excludes change, or the remote is deleted. Signed links remain the fallback without Redis, which the s3 runner now tests. fixes #1428 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/scripts/install.sh | 6 + CHANGES/1428.bugfix | 1 + pulp_python/app/models.py | 43 +++++-- pulp_python/app/pypi/views.py | 42 ++++--- pulp_python/app/utils.py | 85 ++++++++++++- .../tests/functional/api/test_full_mirror.py | 112 ++++++++++++++++-- .../tests/functional/api/test_simple_cache.py | 8 +- pulp_python/tests/unit/test_pull_through.py | 65 ++++++++++ template_config.yml | 3 +- 9 files changed, 321 insertions(+), 44 deletions(-) create mode 100644 CHANGES/1428.bugfix diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index f79ca0235..abbb8d1a5 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -57,3 +57,9 @@ fi # Needed for some functional tests cmd_prefix bash -c "echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nopasswd" cmd_prefix bash -c "usermod -a -G wheel pulp" + +# In some scenarios we want to simulate a failed redis cache. +if [[ " s3 " =~ " ${TEST} " ]]; then + cmd_prefix bash -c "s6-rc -d change redis" + echo "The Redis service was disabled for $TEST" +fi diff --git a/CHANGES/1428.bugfix b/CHANGES/1428.bugfix new file mode 100644 index 000000000..b5bf381fa --- /dev/null +++ b/CHANGES/1428.bugfix @@ -0,0 +1 @@ +Fixed pip intermittently receiving a pull-through wheel instead of its metadata, or the reverse, when Redis caching is enabled. diff --git a/pulp_python/app/models.py b/pulp_python/app/models.py index 0cb4ba30b..f1f6bb5fe 100644 --- a/pulp_python/app/models.py +++ b/pulp_python/app/models.py @@ -10,6 +10,7 @@ from django.db import models, transaction from django_lifecycle import ( AFTER_UPDATE, + BEFORE_DELETE, BEFORE_SAVE, hook, ) @@ -41,6 +42,8 @@ artifact_to_metadata_artifact, artifact_to_python_content_data, canonicalize_name, + clear_pull_through_entries, + lookup_pull_through_entry, python_content_to_json, unsign_pull_through_token, ) @@ -360,19 +363,21 @@ class PythonRemote(Remote, AutoAddObjPermsMixin): vulnerabilities = models.BooleanField(default=False) def get_remote_artifact_url(self, relative_path=None, request=None): - """Get url for remote_artifact, content app requests need a signed pull-through token.""" + """Get url for remote_artifact, content app requests need a stored or signed entry.""" if request is None: return super().get_remote_artifact_url(relative_path) - if not (token := request.query.get(PULL_THROUGH_PARAM)): - return None filename = PurePath(relative_path or "").name - # pip adds ".metadata" to the end of the url (the token) instead of the url path - if token.endswith(".metadata"): - token = token.removesuffix(".metadata") - if not filename.endswith(".metadata"): - filename = f"{filename}.metadata" - setattr(self, "_real_relative_path", filename) - if resolved := unsign_pull_through_token(self, token, filename): + if token := request.query.get(PULL_THROUGH_PARAM): + # pip adds ".metadata" to the end of the url (the token) instead of the url path + if token.endswith(".metadata"): + token = token.removesuffix(".metadata") + if not filename.endswith(".metadata"): + filename = f"{filename}.metadata" + setattr(self, "_real_relative_path", filename) + resolved = unsign_pull_through_token(self, token, filename) + else: + resolved = lookup_pull_through_entry(self, filename) + if resolved: url, sha256 = resolved if sha256: self.__dict__.setdefault("_pull_through_digests", {})[url] = sha256 @@ -388,7 +393,7 @@ def get_remote_artifact_content_type(self, relative_path=None): return PythonPackageContent def get_downloader(self, remote_artifact=None, url=None, download_factory=None, **kwargs): - """Validate pull-through downloads against the sha256 from their signed path.""" + """Validate pull-through downloads against the sha256 from their pull-through entry.""" digests = self.__dict__.get("_pull_through_digests", {}) if remote_artifact and not remote_artifact.sha256: remote_artifact.sha256 = digests.get(remote_artifact.url) @@ -398,8 +403,20 @@ def get_downloader(self, remote_artifact=None, url=None, download_factory=None, @hook(AFTER_UPDATE, when_any=["url", "includes", "excludes"], has_changed=True) def invalidate_pull_through_cache(self): - """Rebuild cached simple pages after the signed links they list are invalidated.""" - transaction.on_commit(self.invalidate_cache) + """Rebuild the pull-through simple pages and entries when the files they list change.""" + + def invalidate(): + self.invalidate_cache() + clear_pull_through_entries(self.pk) + + transaction.on_commit(invalidate) + + @hook(BEFORE_DELETE) + def clear_pull_through_cache(self): + """Drop the pull-through entries of a deleted remote.""" + # The pk is cleared on delete before the transaction commits + remote_pk = self.pk + transaction.on_commit(lambda: clear_pull_through_entries(remote_pk)) class Meta: default_related_name = "%(app_label)s_%(model_name)s" diff --git a/pulp_python/app/pypi/views.py b/pulp_python/app/pypi/views.py index 5bec4e0fd..a1c944ed7 100644 --- a/pulp_python/app/pypi/views.py +++ b/pulp_python/app/pypi/views.py @@ -57,6 +57,7 @@ get_remote_simple_page, python_content_to_json, sign_pull_through_path, + store_pull_through_entries, write_simple_detail, write_simple_detail_json, write_simple_index, @@ -390,16 +391,21 @@ def list(self, request, path): def pull_through_package_simple(self, package, path, remote): """Gets the package's simple page from remote.""" - def parse_package(release_package): + def upstream_url(release_package): parsed = urlparse(release_package.url) - stripped_url = urlunsplit(chain(parsed[:3], ("", ""))) - pt_path = sign_pull_through_path( - remote, - release_package.filename, - stripped_url, - sha256=release_package.digests.get("sha256"), - metadata_sha256=(release_package.metadata_digests or {}).get("sha256"), - ) + return urlunsplit(chain(parsed[:3], ("", ""))) + + def parse_package(release_package, stored): + if stored: + pt_path = release_package.filename + else: + pt_path = sign_pull_through_path( + remote, + release_package.filename, + upstream_url(release_package), + sha256=release_package.digests.get("sha256"), + metadata_sha256=(release_package.metadata_digests or {}).get("sha256"), + ) d_url = urljoin(self.base_content_url, f"{path}/{pt_path}") return { "filename": release_package.filename, @@ -423,11 +429,19 @@ def parse_package(release_package): if not page: log.info(f"Failed to fetch {package} simple page from {remote.url}") return {} - return { - p.filename: parse_package(p) - for p in page.packages - if rfilter.filter_release(package, p.version) - } + packages = [p for p in page.packages if rfilter.filter_release(package, p.version)] + stored = store_pull_through_entries( + remote, + { + p.filename: { + "url": upstream_url(p), + "sha256": p.digests.get("sha256"), + "metadata_sha256": (p.metadata_digests or {}).get("sha256"), + } + for p in packages + }, + ) + return {p.filename: parse_package(p, stored) for p in packages} @extend_schema(operation_id="pypi_simple_package_read", summary="Get package simple page") @method_decorator(cache_control(max_age=600, public=True)) diff --git a/pulp_python/app/utils.py b/pulp_python/app/utils.py index 3fac71d7b..021d0db86 100644 --- a/pulp_python/app/utils.py +++ b/pulp_python/app/utils.py @@ -17,10 +17,11 @@ from django.db.utils import IntegrityError from jinja2 import Template from packaging.requirements import Requirement -from packaging.utils import canonicalize_name +from packaging.utils import canonicalize_name, parse_sdist_filename, parse_wheel_filename from packaging.version import InvalidVersion, parse from pypi_simple import ACCEPT_JSON_PREFERRED, ProjectPage +from pulpcore.plugin.cache import SyncContentCache from pulpcore.plugin.exceptions import TimeoutException from pulpcore.plugin.models import Artifact, Remote, VulnerabilityReport from pulpcore.plugin.util import get_domain @@ -39,6 +40,9 @@ PULL_THROUGH_PARAM = "pt" PULL_THROUGH_SALT = "pulp_python.pull_through" +_CACHE_TTL = settings.CACHE_SETTINGS["EXPIRES_TTL"] +# Outlive both the cached simple pages and their max-age in client caches, None never expires +PULL_THROUGH_TTL = None if _CACHE_TTL is None else _CACHE_TTL + 600 PYPI_SIMPLE_V1_HTML = "application/vnd.pypi.simple.v1+html" PYPI_SIMPLE_V1_JSON = "application/vnd.pypi.simple.v1+json" @@ -776,7 +780,7 @@ async def aget_remote_simple_page(package, remote, max_retries=1): def _pull_through_signer(remote): - # Changing what the remote lists invalidates its tokens. + # Changing what the remote lists invalidates its tokens, like it clears its stored entries listing = json.dumps([remote.url, remote.includes, remote.excludes]) salt = f"{PULL_THROUGH_SALT}:{remote.pk}:{hashlib.sha256(listing.encode()).hexdigest()}" return signing.Signer(salt=salt) @@ -810,3 +814,80 @@ def unsign_pull_through_token(remote, token, filename): if filename == f"{data['f']}.metadata" and data.get("m"): return f"{data['u']}.metadata", data["m"] return None + + +def _pull_through_key(remote, filename): + # Group entries per project so each expires on its own, falling back to the filename for + # legacy names that can't be parsed + try: + if filename.endswith(".whl"): + bucket = parse_wheel_filename(filename)[0] + else: + bucket = parse_sdist_filename(filename)[0] + except ValueError: + bucket = filename + return f"pulp_python:pull_through:{remote.pk}:{bucket}" + + +def store_pull_through_entries(remote, entries): + """ + Stores filename -> {url, sha256, metadata_sha256} entries of a remote in Redis. + + Returns True if the entries were stored, so plain filename links can be used for them. + """ + if not settings.CACHE_ENABLED: + return False + if not entries: + return True + buckets = defaultdict(dict) + for filename, entry in entries.items(): + buckets[_pull_through_key(remote, filename)][filename] = json.dumps(entry) + try: + pipe = SyncContentCache().redis.pipeline(transaction=False) + for key, mapping in buckets.items(): + pipe.hset(key, mapping=mapping) + if PULL_THROUGH_TTL is not None: + pipe.expire(key, PULL_THROUGH_TTL) + pipe.execute() + except Exception as e: + log.warning("Failed to store pull-through entries: %s", e) + return False + return True + + +def clear_pull_through_entries(remote_pk): + """Deletes all the stored pull-through entries of a remote.""" + if not settings.CACHE_ENABLED: + return + try: + redis = SyncContentCache().redis + keys = list(redis.scan_iter(match=f"pulp_python:pull_through:{remote_pk}:*", count=1000)) + if keys: + redis.delete(*keys) + except Exception as e: + log.warning("Failed to clear pull-through entries: %s", e) + + +def lookup_pull_through_entry(remote, filename): + """ + Returns the upstream (url, sha256) for a file stored by store_pull_through_entries. + + filename can be a stored package's filename or its PEP 658 metadata file. + """ + if not settings.CACHE_ENABLED: + return None + is_metadata = filename.endswith(".metadata") + filename = filename.removesuffix(".metadata") + try: + raw = SyncContentCache().redis.hget(_pull_through_key(remote, filename), filename) + except Exception as e: + log.warning("Failed to look up pull-through entry: %s", e) + return None + if not raw: + return None + entry = json.loads(raw) + if not is_metadata: + return entry["url"], entry.get("sha256") + if entry.get("metadata_sha256"): + return f"{entry['url']}.metadata", entry["metadata_sha256"] + return None diff --git a/pulp_python/tests/functional/api/test_full_mirror.py b/pulp_python/tests/functional/api/test_full_mirror.py index c7a06a64a..4fbea7dd8 100644 --- a/pulp_python/tests/functional/api/test_full_mirror.py +++ b/pulp_python/tests/functional/api/test_full_mirror.py @@ -16,6 +16,12 @@ ) +@pytest.fixture +def signed_links(redis_status): + """Pull-through links carry a signed token only when Redis is not available.""" + return not redis_status + + def test_pull_through_install( python_bindings, python_remote_factory, python_distribution_factory, delete_orphans_pre ): @@ -43,7 +49,9 @@ def test_pull_through_install( @pytest.mark.parallel -def test_pull_through_simple(python_remote_factory, python_distribution_factory, pulp_content_url): +def test_pull_through_simple( + python_remote_factory, python_distribution_factory, pulp_content_url, signed_links +): """Tests that the simple page is properly modified when requesting a pull-through.""" remote = python_remote_factory(url=PYPI_URL, includes=["shelf-reader"]) distro = python_distribution_factory(remote=remote.pulp_href) @@ -54,8 +62,11 @@ def test_pull_through_simple(python_remote_factory, python_distribution_factory, assert len(project_page.packages) == 2 for package in project_page.packages: assert package.filename in PYTHON_XS_FIXTURE_CHECKSUMS - relative_path = f"{distro.base_path}/{package.filename}?pt=" - assert urljoin(pulp_content_url, relative_path) in package.url + expected = urljoin(pulp_content_url, f"{distro.base_path}/{package.filename}") + if signed_links: + assert package.url.startswith(f"{expected}?pt=") + else: + assert package.url == expected assert PYTHON_XS_FIXTURE_CHECKSUMS[package.filename] == package.digests["sha256"] @@ -124,6 +135,7 @@ def test_pull_through_with_repo( pulpcore_bindings, monitor_task, has_pulp_plugin, + signed_links, ): """Tests that content is saved to repository.""" remote = python_remote_factory(includes=[]) @@ -134,7 +146,7 @@ def test_pull_through_with_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 "?pt=" in package.url + assert ("?pt=" in package.url) == signed_links r = requests.get(package.url) assert r.status_code == 200 @@ -161,7 +173,7 @@ def test_pull_through_with_repo( @pytest.mark.parallel def test_pull_through_local_only( - python_remote_factory, python_distribution_factory, python_repo_with_sync + python_remote_factory, python_distribution_factory, python_repo_with_sync, signed_links ): """Tests that pull-through checks the repository if the package is not present on the remote.""" remote = python_remote_factory(url=PYPI_URL, includes=["pulpcore"]) @@ -177,7 +189,8 @@ def test_pull_through_local_only( url = f"{distro.base_url}simple/shelf-reader/" r = requests.get(url) assert r.status_code == 200 - assert "?pt=" in r.text + assert "shelf-reader-0.1.tar.gz" in r.text + assert ("?pt=" in r.text) == signed_links url = f"{distro.base_url}simple/pulp_python/" r = requests.get(url) @@ -240,8 +253,46 @@ def test_pull_through_metadata(python_remote_factory, python_distribution_factor @pytest.mark.parallel -def test_pull_through_rejects_bad_links(python_remote_factory, python_distribution_factory): +def test_pull_through_rejects_unknown_files( + python_remote_factory, python_distribution_factory, signed_links +): + """Tests that pull-through only downloads files listed on a simple page of the distro's remote.""" + if signed_links: + pytest.skip("Pull-through links are signed when Redis is not available") + remote = python_remote_factory(includes=["shelf-reader"]) + distro = python_distribution_factory(remote=remote.pulp_href) + remote2 = python_remote_factory(includes=["shelf-reader"]) + distro2 = python_distribution_factory(remote=remote2.pulp_href) + + # Not listed on any simple page yet + r = requests.get(f"{distro.base_url}shelf-reader-0.1.tar.gz") + assert r.status_code == 404 + + url = f"{distro.base_url}simple/shelf-reader/" + package = ProjectPage.from_response(requests.get(url), "shelf-reader").packages[0] + + # Listed on a simple page of another remote + r = requests.get(package.url.replace(f"/{distro.base_path}/", f"/{distro2.base_path}/")) + assert r.status_code == 404 + + # Old unsigned redirect links + upstream_url = urljoin(remote.url, "simple/shelf-reader/") + upstream = ProjectPage.from_response(requests.get(upstream_url), "shelf-reader").packages[0] + r = requests.get(f"{distro.base_url}shelf_reader-9.9.tar.gz?redirect={upstream.url}") + assert r.status_code == 404 + + r = requests.get(package.url) + assert r.status_code == 200 + assert sha256(r.content).hexdigest() == package.digests["sha256"] + + +@pytest.mark.parallel +def test_pull_through_rejects_bad_links( + python_remote_factory, python_distribution_factory, signed_links +): """Tests that pull-through only downloads files from links signed for the distro's remote.""" + if not signed_links: + pytest.skip("Pull-through links are only signed when Redis is not available") remote = python_remote_factory(includes=["shelf-reader"]) distro = python_distribution_factory(remote=remote.pulp_href) remote2 = python_remote_factory(includes=["shelf-reader"]) @@ -275,11 +326,50 @@ def test_pull_through_rejects_bad_links(python_remote_factory, python_distributi assert sha256(r.content).hexdigest() == package1.digests["sha256"] +@pytest.mark.parallel +def test_pull_through_remote_update( + python_bindings, python_remote_factory, python_distribution_factory, monitor_task, signed_links +): + """Tests that changing what the remote lists refreshes its pull-through pages and entries.""" + if signed_links: + pytest.skip("Pull-through entries are only stored when Redis is available") + remote = python_remote_factory(includes=["shelf-reader"]) + distro = python_distribution_factory(remote=remote.pulp_href) + + url = f"{distro.base_url}simple/shelf-reader/" + assert requests.get(url).headers["X-PULP-CACHE"] == "MISS" + r = requests.get(url) + assert r.headers["X-PULP-CACHE"] == "HIT" + package1, package2 = ProjectPage.from_response(r, "shelf-reader").packages + + # Other edits keep the cached page and its links + body = {"download_concurrency": 5} + monitor_task(python_bindings.RemotesPythonApi.partial_update(remote.pulp_href, body).task) + assert requests.get(url).headers["X-PULP-CACHE"] == "HIT" + r = requests.get(package1.url) + assert r.status_code == 200 + assert sha256(r.content).hexdigest() == package1.digests["sha256"] + + # Files listed by the old url need the simple page to be fetched again + body = {"url": PYPI_URL} + monitor_task(python_bindings.RemotesPythonApi.partial_update(remote.pulp_href, body).task) + assert requests.get(package2.url).status_code == 404 + r = requests.get(url) + assert r.headers["X-PULP-CACHE"] == "MISS" + packages = ProjectPage.from_response(r, "shelf-reader").packages + package2 = next(p for p in packages if p.filename == package2.filename) + r = requests.get(package2.url) + assert r.status_code == 200 + assert sha256(r.content).hexdigest() == package2.digests["sha256"] + + @pytest.mark.parallel def test_pull_through_signed_links_remote_update( - python_bindings, python_remote_factory, python_distribution_factory, monitor_task + python_bindings, python_remote_factory, python_distribution_factory, monitor_task, signed_links ): """Tests that changing what the remote lists invalidates its signed pull-through links.""" + if not signed_links: + pytest.skip("Pull-through links are only signed when Redis is not available") remote = python_remote_factory(includes=["shelf-reader"]) distro = python_distribution_factory(remote=remote.pulp_href) @@ -309,6 +399,7 @@ def test_pull_through_metadata_with_repo( python_remote_factory, python_distribution_factory, pulpcore_bindings, + signed_links, ): """Tests that metadata is correctly saved when using pull-through with a repository.""" remote = python_remote_factory(url=PYPI_URL, includes=["pip"]) @@ -320,7 +411,7 @@ def test_pull_through_metadata_with_repo( filename = "pip-26.0.1-py3-none-any.whl" package = next(p for p in project_page.packages if p.filename == filename) assert package.has_metadata - assert "?pt=" in package.url + assert ("?pt=" in package.url) == signed_links # Retrieve the metadata and assert the content was not saved to the repository parts = urlsplit(package.url) @@ -331,11 +422,12 @@ def test_pull_through_metadata_with_repo( project_page = ProjectPage.from_response(requests.get(pip_url), "pip") package = next(p for p in project_page.packages if p.filename == filename) assert package.has_metadata - assert "?pt=" in package.url + assert ("?pt=" in package.url) == signed_links # Now retrieve the package and assert the content was saved with metadata r = requests.get(package.url) assert r.status_code == 200 + assert sha256(r.content).hexdigest() == package.digests["sha256"] pa = pulpcore_bindings.ArtifactsApi.list(sha256=package.digests["sha256"]) assert pa.count == 1 ma = pulpcore_bindings.ArtifactsApi.list(sha256=package.metadata_digests["sha256"]) diff --git a/pulp_python/tests/functional/api/test_simple_cache.py b/pulp_python/tests/functional/api/test_simple_cache.py index bb57b7d16..7424697ae 100644 --- a/pulp_python/tests/functional/api/test_simple_cache.py +++ b/pulp_python/tests/functional/api/test_simple_cache.py @@ -13,12 +13,12 @@ @pytest.fixture -def skip_without_cache(pulp_settings): +def skip_without_cache(redis_status): """ - Skip test if server-side caching is not enabled. + Skip test if server-side caching is not enabled or Redis is unreachable. """ - if not pulp_settings.CACHE_ENABLED: - pytest.skip("CACHE_ENABLED is not set") + if not redis_status: + pytest.skip("Redis is not available") @pytest.fixture diff --git a/pulp_python/tests/unit/test_pull_through.py b/pulp_python/tests/unit/test_pull_through.py index c69d89f53..421f37da4 100644 --- a/pulp_python/tests/unit/test_pull_through.py +++ b/pulp_python/tests/unit/test_pull_through.py @@ -2,10 +2,17 @@ from uuid import uuid4 import pytest +from django.conf import settings +from pulpcore.plugin.cache import SyncContentCache + +from pulp_python.app import utils from pulp_python.app.utils import ( PULL_THROUGH_PARAM, + clear_pull_through_entries, + lookup_pull_through_entry, sign_pull_through_path, + store_pull_through_entries, unsign_pull_through_token, ) @@ -21,6 +28,18 @@ def _remote(**kwargs): return SimpleNamespace(**kwargs) +def _redis_available(): + if not settings.CACHE_ENABLED: + return False + try: + return SyncContentCache().redis.ping() + except Exception: + return False + + +requires_redis = pytest.mark.skipif(not _redis_available(), reason="Redis is not available") + + def _token(remote, **kwargs): path = sign_pull_through_path(remote, FILENAME, URL, **kwargs) filename, token = path.split(f"?{PULL_THROUGH_PARAM}=") @@ -79,3 +98,49 @@ def test_rejects_tampered_token(): assert unsign_pull_through_token(remote, tampered, FILENAME) is None assert unsign_pull_through_token(remote, "not-a-token", FILENAME) is None + + +@requires_redis +def test_stored_entries(): + remote = _remote() + sdist = "shelf-reader-0.1.tar.gz" + legacy = "pytz-2011k.tar.bz2" + entry = {"url": URL, "sha256": "a" * 64, "metadata_sha256": None} + assert store_pull_through_entries( + remote, + {FILENAME: entry, sdist: {"url": f"{URL}/{sdist}"}, legacy: {"url": f"{URL}/{legacy}"}}, + ) + + assert lookup_pull_through_entry(remote, FILENAME) == (URL, "a" * 64) + assert lookup_pull_through_entry(remote, f"{FILENAME}.metadata") is None + assert lookup_pull_through_entry(remote, sdist) == (f"{URL}/{sdist}", None) + assert lookup_pull_through_entry(remote, legacy) == (f"{URL}/{legacy}", None) + assert lookup_pull_through_entry(remote, "evil-1.0-py3-none-any.whl") is None + assert lookup_pull_through_entry(_remote(), FILENAME) is None + + entry["metadata_sha256"] = "b" * 64 + assert store_pull_through_entries(remote, {FILENAME: entry}) + assert lookup_pull_through_entry(remote, f"{FILENAME}.metadata") == ( + f"{URL}.metadata", + "b" * 64, + ) + assert lookup_pull_through_entry(remote, sdist) == (f"{URL}/{sdist}", None) + + clear_pull_through_entries(remote.pk) + assert lookup_pull_through_entry(remote, FILENAME) is None + assert lookup_pull_through_entry(remote, legacy) is None + + +@requires_redis +@pytest.mark.parametrize("ttl", [1200, None]) +def test_stored_entries_ttl(monkeypatch, ttl): + monkeypatch.setattr(utils, "PULL_THROUGH_TTL", ttl) + remote = _remote() + assert store_pull_through_entries(remote, {FILENAME: {"url": URL}}) + + redis_ttl = SyncContentCache().redis.ttl(utils._pull_through_key(remote, FILENAME)) + if ttl is None: + assert redis_ttl == -1 + else: + assert 0 < redis_ttl <= ttl + clear_pull_through_entries(remote.pk) diff --git a/template_config.yml b/template_config.yml index ef109f66b..d9007914f 100644 --- a/template_config.yml +++ b/template_config.yml @@ -18,7 +18,8 @@ core_import_allowed: [] deploy_client_to_pypi: true deploy_client_to_rubygems: true deploy_to_pypi: true -disabled_redis_runners: [] +disabled_redis_runners: + - "s3" docker_fixtures: false extra_files: - destination: "/etc/pki/attestation/test-key.pem"