Skip to content

Commit 1ba3c5c

Browse files
authored
Merge pull request #731 from gerrod3/patchback/backports/3.11/fc43b4b253dbec5931d6a230296942e4ba52ec3e/pr-717
Backport #717 to 3.11
2 parents b90aa94 + 957f60c commit 1ba3c5c

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

CHANGES/716.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed package name normalization issue preventing syncing packages with "." or "_" in their names.

pulp_python/app/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from pathlib import PurePath
1818
from .utils import (
19+
canonicalize_name,
1920
get_project_metadata_from_artifact,
2021
parse_project_metadata,
2122
python_content_to_json,
@@ -84,6 +85,8 @@ def content_handler(self, path):
8485
).latest("pulp_created")
8586
except ObjectDoesNotExist:
8687
return None
88+
if len(path.parts) == 2:
89+
path = PurePath(f"simple/{canonicalize_name(path.parts[1])}")
8790
rel_path = f"{path}/index.html"
8891
try:
8992
ca = (
@@ -100,8 +103,9 @@ def content_handler(self, path):
100103
return ArtifactResponse(ca.artifact, headers=headers)
101104

102105
if name:
106+
normalized = canonicalize_name(name)
103107
package_content = PythonPackageContent.objects.filter(
104-
pk__in=self.publication.repository_version.content, name__iexact=name
108+
pk__in=self.publication.repository_version.content, name__normalize=normalized
105109
)
106110
# TODO Change this value to the Repo's serial value when implemented
107111
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}

pulp_python/app/pypi/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ def retrieve(self, request, path, meta):
278278
elif meta_path.match("*/json"):
279279
name = meta_path.parts[0]
280280
if name:
281-
package_content = content.filter(name__iexact=name)
281+
normalized = canonicalize_name(name)
282+
package_content = content.filter(name__normalize=normalized)
282283
# TODO Change this value to the Repo's serial value when implemented
283284
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}
284285
json_body = python_content_to_json(path, package_content, version=version)

pulp_python/tests/functional/api/test_download_content.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding=utf-8
22
"""Tests that verify download of content served by Pulp."""
3+
import pytest
34
import hashlib
45
from random import choice
56
from urllib.parse import urljoin
@@ -149,3 +150,32 @@ def test_full_pulp_to_pulp_sync(self):
149150

150151
repo3 = self._create_repo_and_sync_with_remote(remote)
151152
self.assertEqual(get_content_summary(repo3.to_dict()), PYTHON_MD_FIXTURE_SUMMARY)
153+
154+
155+
@pytest.mark.parallel
156+
def test_pulp2pulp_sync_with_oddities(
157+
python_repo_with_sync,
158+
python_remote_factory,
159+
python_publication_factory,
160+
python_distribution_factory,
161+
python_content_summary,
162+
):
163+
"""Test that Pulp can handle syncing packages with wierd names."""
164+
remote = python_remote_factory(includes=["oslo.utils"], url="https://pypi.org")
165+
repo = python_repo_with_sync(remote)
166+
distro = python_distribution_factory(repository=repo.pulp_href)
167+
summary = python_content_summary(repository_version=repo.latest_version_href)
168+
# Test pulp 2 pulp full sync w/ live pypi apis
169+
remote2 = python_remote_factory(includes=[], url=distro.base_url)
170+
repo2 = python_repo_with_sync(remote2)
171+
summary2 = python_content_summary(repository_version=repo2.latest_version_href)
172+
assert summary2.present["python.python"]["count"] > 0
173+
assert summary.present["python.python"]["count"] == summary2.present["python.python"]["count"]
174+
# Test w/ publication
175+
pub = python_publication_factory(repository=repo)
176+
distro2 = python_distribution_factory(publication=pub.pulp_href)
177+
remote3 = python_remote_factory(includes=[], url=distro2.base_url)
178+
repo3 = python_repo_with_sync(remote3)
179+
summary3 = python_content_summary(repository_version=repo3.latest_version_href)
180+
assert summary3.present["python.python"]["count"] > 0
181+
assert summary.present["python.python"]["count"] == summary3.present["python.python"]["count"]

0 commit comments

Comments
 (0)