Skip to content

Commit 9f7216b

Browse files
committed
quadlet API: fix tar install when non-quadlet file sorts first
QuadletInstall expects the quadlet file to be first in the file list, The API handler passes files in filepath.Walk order (lexicographic). Install would fail if a file like "Containerfile" comes before the quadlet file. Signed-off-by: Nicola Sella <nsella@redhat.com>
1 parent 0344459 commit 9f7216b

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

pkg/api/handlers/libpod/quadlets.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ func InstallQuadlets(w http.ResponseWriter, r *http.Request) {
236236
return
237237
}
238238

239+
// QuadletInstall expects the quadlet file to be first in the list.
240+
// filepath.Walk returns files in lexicographic order, so a non-quadlet
241+
// file (e.g. "Containerfile") may sort before the ".container" file.
242+
for i, filePath := range filePaths {
243+
if quadlet.IsExtSupported(filePath) {
244+
filePaths[0], filePaths[i] = filePaths[i], filePaths[0]
245+
break
246+
}
247+
}
248+
239249
containerEngine := abi.ContainerEngine{Libpod: runtime}
240250
installOptions := entities.QuadletInstallOptions{
241251
Replace: query.Replace,

test/apiv2/36-quadlets.at

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ t POST "libpod/quadlets" "$TMPD/$quadlet_3_4.tar" 400 \
213213
# Scenario: install tar that contains one quadlet file and a non-quadlet file will succeed
214214
# then update the quadlet file, and the non-quadlet file, and verify the update is successful
215215
quadlet_5=quadlet-test-5-$(cat /proc/sys/kernel/random/uuid).container
216-
containerfile_1=quadlet-test-containerfile-1-$(cat /proc/sys/kernel/random/uuid).Containerfile
216+
containerfile_1=quadlet-test-containerfile-1-$(cat /proc/sys/kernel/random/uuid)
217+
configfile_1=quadlet-test-configfile-1-$(cat /proc/sys/kernel/random/uuid).conf
217218

218219
containerfile_1_content=$(cat << EOF
219220
FROM quay.io/podman/hello
@@ -241,17 +242,25 @@ CMD ["echo", "Updated"]
241242
EOF
242243
)
243244

245+
configfile_1_content=$(cat << EOF
246+
[ini]
247+
foo=bar
248+
EOF
249+
)
250+
244251
echo "$quadlet_5_content" > "$TMPD/$quadlet_5"
245252
echo "$containerfile_1_content" > "$TMPD/$containerfile_1"
246-
tar --format=posix -C "$TMPD" -cvf "$TMPD/$quadlet_5$containerfile_1.tar" "$quadlet_5" "$containerfile_1" &> /dev/null
253+
echo "$configfile_1_content" > "$TMPD/$configfile_1"
254+
tar --format=posix -C "$TMPD" -cvf "$TMPD/$quadlet_5$containerfile_1.tar" "$quadlet_5" "$containerfile_1" "$configfile_1" &> /dev/null
247255

248256
t POST "libpod/quadlets" "$TMPD/$quadlet_5$containerfile_1.tar" 200 \
249-
'.InstalledQuadlets|length=2' \
257+
'.InstalledQuadlets|length=3' \
250258
'.QuadletErrors|length=0'
251259

252260
t GET "libpod/quadlets/$quadlet_5/file" 200
253261
is "$output" "$quadlet_5_content" "quadlet-5 should be installed"
254262
is "$(cat "$quadlet_install_dir/$containerfile_1")" "$containerfile_1_content" "containerfile_1 should be installed"
263+
is "$(cat "$quadlet_install_dir/$configfile_1")" "$configfile_1_content" "configfile_1 should be installed"
255264

256265
echo "$quadlet_5_updated_content" > "$TMPD/$quadlet_5"
257266
echo "$containerfile_1_updated_content" > "$TMPD/$containerfile_1"
@@ -273,6 +282,36 @@ t GET "libpod/quadlets/$quadlet_5/file" 200
273282
is "$output" "$quadlet_5_updated_content" "quadlet-5 should be updated"
274283
is "$(cat "$quadlet_install_dir/$containerfile_1")" "$containerfile_1_updated_content" "containerfile_1 should be installed"
275284

285+
# Scenario: install tar where a non-quadlet file sorts lexicographically before the quadlet file.
286+
# "AAA-" sorts before "quadlet-test-", exercising the file ordering in the API handler.
287+
quadlet_7=quadlet-test-7-$(cat /proc/sys/kernel/random/uuid).container
288+
containerfile_3=AAA-containerfile-$(cat /proc/sys/kernel/random/uuid)
289+
290+
quadlet_7_content=$(cat << EOF
291+
[Container]
292+
ContainerName=quadlet-7
293+
Image=quay.io/podman/hello
294+
EOF
295+
)
296+
297+
containerfile_3_content=$(cat << EOF
298+
FROM quay.io/podman/hello
299+
CMD ["echo", "hello"]
300+
EOF
301+
)
302+
303+
echo "$quadlet_7_content" > "$TMPD/$quadlet_7"
304+
echo "$containerfile_3_content" > "$TMPD/$containerfile_3"
305+
tar --format=posix -C "$TMPD" -cvf "$TMPD/$quadlet_7$containerfile_3.tar" "$quadlet_7" "$containerfile_3" &> /dev/null
306+
307+
t POST "libpod/quadlets" "$TMPD/$quadlet_7$containerfile_3.tar" 200 \
308+
'.InstalledQuadlets|length=2' \
309+
'.QuadletErrors|length=0'
310+
311+
t GET "libpod/quadlets/$quadlet_7/file" 200
312+
is "$output" "$quadlet_7_content" "quadlet-7 should be installed"
313+
is "$(cat "$quadlet_install_dir/$containerfile_3")" "$containerfile_3_content" "containerfile_3 should be installed"
314+
276315
# Scenario: test a multipart call, then update without replace, and then replace
277316
quadlet_6=quadlet-test-6-$(cat /proc/sys/kernel/random/uuid).container
278317
containerfile_2=quadlet-test-containerfile-2-$(cat /proc/sys/kernel/random/uuid).Containerfile
@@ -332,10 +371,13 @@ is "$(cat "$quadlet_install_dir/$containerfile_2")" "$containerfile_2_updated_co
332371

333372
podman quadlet rm "$quadlet_1" \
334373
"$quadlet_5" \
335-
"$quadlet_6"
374+
"$quadlet_6" \
375+
"$quadlet_7"
336376

337377
rm -f "$quadlet_install_dir/$containerfile_1"
378+
rm -f "$quadlet_install_dir/$configfile_1"
338379
rm -f "$quadlet_install_dir/$containerfile_2"
380+
rm -f "$quadlet_install_dir/$containerfile_3"
339381
rm -rf $TMPD
340382

341383
# DELETE endpoint tests

0 commit comments

Comments
 (0)