Skip to content

Commit 2ab568b

Browse files
authored
Merge pull request #748 from pulp/patchback/backports/3.12/4382aa63a57673b59d471554e8df053b7eceaa44/pr-746
[PR #746/4382aa63 backport][3.12] Fix upstream on-demand replicates failing
2 parents 5560926 + e7ba0a4 commit 2ab568b

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

CHANGES/718.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed replicate failing on upstream on-demand repositories

pulp_python/app/replica.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def remote_extra_fields(self, upstream_distribution):
2828
# strain the upstream Pulp.
2929
return {"policy": "immediate", "prereleases": True}
3030

31+
def url(self, upstream_distribution):
32+
# Ignore distributions that are only pull-through
33+
repo, pub = upstream_distribution["repository"], upstream_distribution["publication"]
34+
if repo or pub:
35+
return super().url(upstream_distribution)
36+
37+
return None
38+
3139
def repository_extra_fields(self, remote):
3240
# Use autopublish since publications result in faster serving times
3341
return {"autopublish": True}

pulp_python/app/tasks/sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ async def create_content(self, pkg):
256256
for package in dists:
257257
entry = parse_metadata(pkg.info, version, package)
258258
url = entry.pop("url")
259+
size = package["size"] or None
259260

260-
artifact = Artifact(sha256=entry["sha256"])
261+
artifact = Artifact(sha256=entry["sha256"], size=size)
261262
package = PythonPackageContent(**entry)
262263

263264
da = DeclarativeArtifact(

pulp_python/app/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,21 @@ def find_artifact():
284284
if domain:
285285
components.insert(2, domain.name)
286286
url = "/".join(components)
287+
md5 = artifact.md5 if artifact and artifact.md5 else ""
288+
size = artifact.size if artifact and artifact.size else 0
287289
return {
288290
"comment_text": "",
289-
"digests": {"md5": artifact.md5, "sha256": artifact.sha256},
291+
"digests": {"md5": md5, "sha256": content.sha256},
290292
"downloads": -1,
291293
"filename": content.filename,
292294
"has_sig": False,
293-
"md5_digest": artifact.md5,
295+
"md5_digest": md5,
294296
"packagetype": content.packagetype,
295297
"python_version": content.python_version,
296298
"requires_python": content.requires_python or None,
297-
"size": artifact.size,
298-
"upload_time": str(artifact.pulp_created),
299-
"upload_time_iso_8601": str(artifact.pulp_created.isoformat()),
299+
"size": size,
300+
"upload_time": str(content.pulp_created),
301+
"upload_time_iso_8601": str(content.pulp_created.isoformat()),
300302
"url": url,
301303
"yanked": False,
302304
"yanked_reason": None

pulp_python/tests/functional/api/test_domains.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
from pulpcore.app import settings
77

8-
from pulp_python.tests.functional.constants import PYTHON_URL, PYTHON_EGG_FILENAME
8+
from pulp_python.tests.functional.constants import (
9+
PYTHON_URL,
10+
PYTHON_EGG_FILENAME,
11+
PYTHON_SM_PROJECT_SPECIFIER,
12+
PYTHON_SM_PACKAGE_COUNT,
13+
)
914
from urllib.parse import urlsplit
1015

1116

@@ -144,7 +149,7 @@ def test_domain_content_replication(
144149
python_bindings,
145150
python_file,
146151
python_repo_factory,
147-
python_publication_factory,
152+
python_remote_factory,
148153
python_distribution_factory,
149154
monitor_task,
150155
monitor_task_group,
@@ -154,13 +159,12 @@ def test_domain_content_replication(
154159
"""Test replication feature through the usage of domains."""
155160
# Set up source domain to replicate from
156161
source_domain = domain_factory()
157-
repo = python_repo_factory(pulp_domain=source_domain.name)
162+
repo = python_repo_factory(pulp_domain=source_domain.name, autopublish=True)
158163
body = {"relative_path": PYTHON_EGG_FILENAME, "file": python_file, "repository": repo.pulp_href}
159164
monitor_task(
160165
python_bindings.ContentPackagesApi.create(pulp_domain=source_domain.name, **body).task
161166
)
162-
pub = python_publication_factory(repository=repo, pulp_domain=source_domain.name)
163-
python_distribution_factory(publication=pub.pulp_href, pulp_domain=source_domain.name)
167+
python_distribution_factory(repository=repo, pulp_domain=source_domain.name)
164168

165169
# Create the replica domain
166170
replica_domain = domain_factory()
@@ -171,6 +175,7 @@ def test_domain_content_replication(
171175
"domain": source_domain.name,
172176
"username": bindings_cfg.username,
173177
"password": bindings_cfg.password,
178+
"tls_validation": False,
174179
}
175180
upstream_pulp = gen_object_with_cleanup(
176181
pulpcore_bindings.UpstreamPulpsApi, upstream_pulp_body, pulp_domain=replica_domain.name
@@ -194,6 +199,25 @@ def test_domain_content_replication(
194199

195200
assert all(1 == x for x in counts.values()), f"Replica had more than 1 object {counts}"
196201

202+
# Test that we can replicate from an Upstream on-demand source (syncs are on-demand by default)
203+
remote = python_remote_factory(
204+
includes=PYTHON_SM_PROJECT_SPECIFIER, pulp_domain=source_domain.name
205+
)
206+
body = {"remote": remote.pulp_href}
207+
monitor_task(python_bindings.RepositoriesPythonApi.sync(repo.pulp_href, body).task)
208+
209+
response = pulpcore_bindings.UpstreamPulpsApi.replicate(upstream_pulp.pulp_href)
210+
monitor_task_group(response.task_group)
211+
212+
response = python_bindings.ContentPackagesApi.list(pulp_domain=replica_domain.name)
213+
assert PYTHON_SM_PACKAGE_COUNT + 1 == response.count
214+
response = python_bindings.PublicationsPypiApi.list(pulp_domain=replica_domain.name)
215+
assert 2 == response.count
216+
add_to_cleanup(python_bindings.PublicationsPypiApi, response.results[0])
217+
assert 1 == python_bindings.RepositoriesPythonApi.list(pulp_domain=replica_domain.name).count
218+
assert 1 == python_bindings.DistributionsPypiApi.list(pulp_domain=replica_domain.name).count
219+
assert 1 == python_bindings.RemotesPythonApi.list(pulp_domain=replica_domain.name).count
220+
197221

198222
@pytest.fixture
199223
def shelf_reader_cleanup():

0 commit comments

Comments
 (0)