Skip to content

Commit a97af04

Browse files
committed
Fix flatpak TLS config and remote cleanup
- Edit the OSTree repo config file directly to set tls-ca-path, instead of using `ostree config --group` which is not supported in the ostree version shipping with RHEL9 el9 flatpak - Wrap flatpak install in try/finally so remote cleanup always runs, preventing "Remote pulptest already exists" failures on subsequent tests - Delete any leftover remote at the start of run_flatpak_commands to handle re-runs after aborted tests Made-with: Cursor
1 parent 7f3a3d5 commit a97af04

1 file changed

Lines changed: 52 additions & 66 deletions

File tree

pulp_container/tests/functional/api/test_flatpak.py

Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
def run_flatpak_commands(host):
12-
# Install flatpak:
12+
# Remove any leftover remote from a previous failed run before starting.
13+
subprocess.run(["flatpak", "--user", "remote-delete", "--force", "pulptest"], check=False)
14+
1315
subprocess.check_call(
1416
[
1517
"flatpak",
@@ -27,72 +29,56 @@ def run_flatpak_commands(host):
2729
if urlparse(host).scheme == "https":
2830
flatpak_user_repo = os.path.expanduser("~/.local/share/flatpak/repo")
2931
ca_cert = "/etc/pulp/certs/pulp_webserver.crt"
30-
if os.path.exists(ca_cert):
31-
subprocess.run(
32-
[
33-
"ostree",
34-
"config",
35-
"--repo",
36-
flatpak_user_repo,
37-
"--group",
38-
'remote "pulptest"',
39-
"set",
40-
"tls-ca-path",
41-
ca_cert,
42-
],
43-
check=False,
44-
)
45-
else:
46-
subprocess.run(
47-
[
48-
"ostree",
49-
"config",
50-
"--repo",
51-
flatpak_user_repo,
52-
"--group",
53-
'remote "pulptest"',
54-
"set",
55-
"tls-permissive",
56-
"true",
57-
],
58-
check=False,
32+
tls_option = f"tls-ca-path={ca_cert}" if os.path.exists(ca_cert) else "tls-permissive=true"
33+
config_path = os.path.join(flatpak_user_repo, "config")
34+
try:
35+
with open(config_path) as f:
36+
content = f.read()
37+
content = content.replace(
38+
'[remote "pulptest"]',
39+
f'[remote "pulptest"]\n{tls_option}',
5940
)
60-
61-
# See <https://pagure.io/fedora-lorax-templates/c/cc1155372046baa58f9d2cc27a9e5473bf05a3fb>
62-
# "lorax-embed-flatpaks.tmpl: Run the flatpak-install under dbus-run-session" for the need for
63-
# dbus-run-session to avoid "error: Cannot autolaunch D-Bus without X11 $DISPLAY":
64-
subprocess.check_call(
65-
[
66-
"dbus-run-session",
67-
"flatpak",
68-
"--user",
69-
"install",
70-
"--noninteractive",
71-
"pulptest",
72-
"net.fishsoup.Hello",
73-
]
74-
)
75-
76-
# Clean up flatpak:
77-
subprocess.run(
78-
[
79-
"flatpak",
80-
"--user",
81-
"uninstall",
82-
"--noninteractive",
83-
"net.fishsoup.Hello",
84-
]
85-
)
86-
subprocess.run(
87-
[
88-
"flatpak",
89-
"--user",
90-
"uninstall",
91-
"--noninteractive",
92-
"net.fishsoup.BusyBoxPlatform",
93-
]
94-
)
95-
subprocess.run(["flatpak", "--user", "remote-delete", "pulptest"])
41+
with open(config_path, "w") as f:
42+
f.write(content)
43+
except OSError:
44+
pass
45+
46+
try:
47+
# See <https://pagure.io/fedora-lorax-templates/c/cc1155372046baa58f9d2cc27a9e5473bf05a3fb>
48+
# "lorax-embed-flatpaks.tmpl: Run the flatpak-install under dbus-run-session" for the need
49+
# for dbus-run-session to avoid "error: Cannot autolaunch D-Bus without X11 $DISPLAY":
50+
subprocess.check_call(
51+
[
52+
"dbus-run-session",
53+
"flatpak",
54+
"--user",
55+
"install",
56+
"--noninteractive",
57+
"pulptest",
58+
"net.fishsoup.Hello",
59+
]
60+
)
61+
finally:
62+
# Clean up flatpak — runs even if install fails so the next test starts clean.
63+
subprocess.run(
64+
[
65+
"flatpak",
66+
"--user",
67+
"uninstall",
68+
"--noninteractive",
69+
"net.fishsoup.Hello",
70+
]
71+
)
72+
subprocess.run(
73+
[
74+
"flatpak",
75+
"--user",
76+
"uninstall",
77+
"--noninteractive",
78+
"net.fishsoup.BusyBoxPlatform",
79+
]
80+
)
81+
subprocess.run(["flatpak", "--user", "remote-delete", "pulptest"])
9682

9783

9884
def test_flatpak_install(

0 commit comments

Comments
 (0)