Skip to content

Commit 3d8e5b0

Browse files
gerrod3patchback[bot]
authored andcommitted
Fix 500 error when using flatpak with reclaimed content
fixes: #1887 (cherry picked from commit 88b2002)
1 parent c1739c3 commit 3d8e5b0

File tree

4 files changed

+125
-35
lines changed

4 files changed

+125
-35
lines changed

Diff for: CHANGES/1887.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed flatpak index returning 500 when Manifest content was on_demand or had been reclaimed.

Diff for: pulp_container/app/registry_api.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,32 @@ def recurse_through_manifest_lists(self, tag, manifest, oss, architectures, mani
580580
tag, mlm.manifest_list, oss, architectures, manifests
581581
)
582582

583+
def get_manifest_config(self, manifest):
584+
# Special handling for the manifest's config options not being fully stored on the model yet
585+
# See migrations 38 & 43
586+
config = {
587+
"labels": manifest.labels,
588+
"architecture": manifest.architecture,
589+
"os": manifest.os,
590+
}
591+
if any(not config[value] for value in ("labels", "architecture", "os")):
592+
# Try to read the original config blob, could be missing if user did a reclaim :(
593+
if manifest.config_blob:
594+
try:
595+
config_artifact = manifest.config_blob._artifacts.get()
596+
except Artifact.DoesNotExist:
597+
log.warning(f"Manifest {manifest.pk}'s config blob was not found.")
598+
else:
599+
with storage.open(config_artifact.file.name) as file:
600+
raw_data = file.read()
601+
config_data = json.loads(raw_data)
602+
config["labels"] = config_data.get("config", {}).get("Labels")
603+
config["os"] = config_data["os"]
604+
config["architecture"] = config_data["architecture"]
605+
else:
606+
log.warning(f"Manifest {manifest.pk} has no config blob.")
607+
return config
608+
583609
def get(self, request):
584610
req_repositories = None
585611
req_tags = None
@@ -636,10 +662,8 @@ def get(self, request):
636662
tag.name, tag.tagged_manifest, req_oss, req_architectures, manifests
637663
)
638664
for manifest, tagged in manifests.items():
639-
with storage.open(manifest.config_blob._artifacts.get().file.name) as file:
640-
raw_data = file.read()
641-
config_data = json.loads(raw_data)
642-
labels = config_data.get("config", {}).get("Labels")
665+
config_data = self.get_manifest_config(manifest)
666+
labels = config_data["labels"]
643667
if not labels:
644668
continue
645669
if any(label not in labels.keys() for label in req_label_exists):

Diff for: pulp_container/tests/functional/api/test_flatpak.py

+85-31
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,18 @@
33
import pytest
44
import subprocess
55

6-
from django.conf import settings
7-
86
from pulp_container.tests.functional.constants import REGISTRY_V2
97

108

11-
def test_flatpak_install(
12-
add_to_cleanup,
13-
registry_client,
14-
local_registry,
15-
container_namespace_api,
16-
container_push_repository_api,
17-
container_tag_api,
18-
container_manifest_api,
19-
):
20-
if not settings.FLATPAK_INDEX:
21-
pytest.skip("This test requires FLATPAK_INDEX to be enabled")
22-
23-
image_path1 = f"{REGISTRY_V2}/pulp/oci-net.fishsoup.busyboxplatform:latest"
24-
registry_client.pull(image_path1)
25-
local_registry.tag_and_push(image_path1, "pulptest/oci-net.fishsoup.busyboxplatform:latest")
26-
image_path2 = f"{REGISTRY_V2}/pulp/oci-net.fishsoup.hello:latest"
27-
registry_client.pull(image_path2)
28-
local_registry.tag_and_push(image_path2, "pulptest/oci-net.fishsoup.hello:latest")
29-
namespace = container_namespace_api.list(name="pulptest").results[0]
30-
add_to_cleanup(container_namespace_api, namespace.pulp_href)
31-
32-
repo = container_push_repository_api.list(name="pulptest/oci-net.fishsoup.hello").results[0]
33-
tag = container_tag_api.list(repository_version=repo.latest_version_href).results[0]
34-
manifest = container_manifest_api.read(tag.tagged_manifest)
35-
36-
assert manifest.is_flatpak
37-
assert not manifest.is_bootable
38-
9+
def run_flatpak_commands(pulp_settings):
3910
# Install flatpak:
4011
subprocess.check_call(
4112
[
4213
"flatpak",
4314
"--user",
4415
"remote-add",
4516
"pulptest",
46-
"oci+" + settings.CONTENT_ORIGIN,
17+
"oci+" + pulp_settings.CONTENT_ORIGIN,
4718
]
4819
)
4920
# See <https://pagure.io/fedora-lorax-templates/c/cc1155372046baa58f9d2cc27a9e5473bf05a3fb>
@@ -81,3 +52,86 @@ def test_flatpak_install(
8152
]
8253
)
8354
subprocess.run(["flatpak", "--user", "remote-delete", "pulptest"])
55+
56+
57+
def test_flatpak_install(
58+
add_to_cleanup,
59+
registry_client,
60+
local_registry,
61+
container_namespace_api,
62+
container_push_repository_api,
63+
container_tag_api,
64+
container_manifest_api,
65+
pulp_settings,
66+
):
67+
if not pulp_settings.FLATPAK_INDEX:
68+
pytest.skip("This test requires FLATPAK_INDEX to be enabled")
69+
70+
image_path1 = f"{REGISTRY_V2}/pulp/oci-net.fishsoup.busyboxplatform:latest"
71+
registry_client.pull(image_path1)
72+
local_registry.tag_and_push(image_path1, "pulptest/oci-net.fishsoup.busyboxplatform:latest")
73+
image_path2 = f"{REGISTRY_V2}/pulp/oci-net.fishsoup.hello:latest"
74+
registry_client.pull(image_path2)
75+
local_registry.tag_and_push(image_path2, "pulptest/oci-net.fishsoup.hello:latest")
76+
namespace = container_namespace_api.list(name="pulptest").results[0]
77+
add_to_cleanup(container_namespace_api, namespace.pulp_href)
78+
79+
repo = container_push_repository_api.list(name="pulptest/oci-net.fishsoup.hello").results[0]
80+
tag = container_tag_api.list(repository_version=repo.latest_version_href).results[0]
81+
manifest = container_manifest_api.read(tag.tagged_manifest)
82+
83+
assert manifest.is_flatpak
84+
assert not manifest.is_bootable
85+
86+
run_flatpak_commands(pulp_settings)
87+
88+
89+
def test_flatpak_on_demand(
90+
container_tag_api,
91+
container_manifest_api,
92+
container_repository_factory,
93+
container_remote_factory,
94+
container_sync,
95+
container_distribution_factory,
96+
container_namespace_api,
97+
pulpcore_bindings,
98+
monitor_task,
99+
add_to_cleanup,
100+
pulp_settings,
101+
):
102+
if not pulp_settings.FLATPAK_INDEX:
103+
pytest.skip("This test requires FLATPAK_INDEX to be enabled")
104+
105+
# Set up repositories with immediate sync
106+
remote1 = container_remote_factory(
107+
upstream_name="pulp/oci-net.fishsoup.busyboxplatform", include_tags=["latest"]
108+
)
109+
remote2 = container_remote_factory(
110+
upstream_name="pulp/oci-net.fishsoup.hello", include_tags=["latest"]
111+
)
112+
repo1 = container_repository_factory(remote=remote1.pulp_href)
113+
repo2 = container_repository_factory(remote=remote2.pulp_href)
114+
container_sync(repo1)
115+
container_sync(repo2)
116+
container_distribution_factory(
117+
base_path="pulptest/oci-net.fishsoup.busyboxplatform", repository=repo1.pulp_href
118+
)
119+
container_distribution_factory(
120+
base_path="pulptest/oci-net.fishsoup.hello", repository=repo2.pulp_href
121+
)
122+
namespace = container_namespace_api.list(name="pulptest").results[0]
123+
add_to_cleanup(container_namespace_api, namespace.pulp_href)
124+
125+
# Assert the repos were set up correctly
126+
tag = container_tag_api.list(repository_version=f"{repo2.versions_href}1/").results[0]
127+
manifest = container_manifest_api.read(tag.tagged_manifest)
128+
assert manifest.is_flatpak
129+
assert not manifest.is_bootable
130+
131+
# reclaim disk space to turn the manifests + config-blogs into on-demand
132+
reclaim_response = pulpcore_bindings.RepositoriesReclaimSpaceApi.reclaim(
133+
{"repo_hrefs": [repo1.pulp_href, repo2.pulp_href]}
134+
)
135+
monitor_task(reclaim_response.task)
136+
137+
run_flatpak_commands(pulp_settings)

Diff for: pulp_container/tests/functional/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@ def _sync(repo, remote=None):
434434
return _sync
435435

436436

437+
@pytest.fixture
438+
def container_distribution_factory(container_distribution_api, gen_object_with_cleanup):
439+
def _container_distribution_factory(**kwargs):
440+
distro = {"name": str(uuid4()), "base_path": str(uuid4())}
441+
if kwargs:
442+
distro.update(kwargs)
443+
return gen_object_with_cleanup(container_distribution_api, distro)
444+
445+
return _container_distribution_factory
446+
447+
437448
@pytest.fixture
438449
def pull_through_distribution(
439450
gen_object_with_cleanup,

0 commit comments

Comments
 (0)