Skip to content

Commit 76998df

Browse files
Johan-Liebert1jeckersb
authored andcommitted
tmt: Add tests for etc merge conflict
This was predominantly AI generated with some minor tweaks from me. Makes sure that bootc upgrade/switch fails if merge conflicts are found during three way etc merge. Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 495d723 commit 76998df

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

tmt/plans/integration.fmf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,11 @@ execute:
285285
how: fmf
286286
test:
287287
- /tmt/tests/tests/test-45-composefs-corruped-state-resilience
288+
289+
/plan-46-etc-merge-conflict:
290+
summary: Verify etc merge conflicts are caught during upgrade, not finalization
291+
discover:
292+
how: fmf
293+
test:
294+
- /tmt/tests/tests/test-46-etc-merge-conflict
288295
# END GENERATED PLANS
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# number: 46
2+
# tmt:
3+
# summary: Verify etc merge conflicts are caught during upgrade, not finalization
4+
# duration: 15m
5+
#
6+
# Verifies that file-to-directory and directory-to-file type changes between
7+
# the current /etc and the new image's /etc are detected during `bootc switch`
8+
# (the upgrade phase) and cause it to fail immediately, rather than silently
9+
# staging and failing during finalization at reboot.
10+
#
11+
# No reboot needed: the upgrade is expected to fail before staging.
12+
use std assert
13+
use tap.nu
14+
15+
if not (tap is_composefs) {
16+
exit 0
17+
}
18+
19+
tap begin "etc merge conflict detection during upgrade"
20+
21+
def main [] {
22+
bootc image copy-to-storage
23+
24+
# Test case 1: File in current /etc conflicts with directory in new image's /etc.
25+
# Create a file on the live system; the new image will have a directory at
26+
# the same path.
27+
"local modification" | save /etc/test-etc-merge-conflict
28+
29+
let td = mktemp -d
30+
cd $td
31+
32+
let dockerfile = '
33+
FROM localhost/bootc as base
34+
RUN mkdir -p /etc/test-etc-merge-conflict && \
35+
echo "inner" > /etc/test-etc-merge-conflict/inner.conf
36+
'
37+
(tap make_uki_containerfile $dockerfile) | save Dockerfile
38+
podman build -t localhost/bootc-etc-conflict .
39+
40+
let result = do { bootc switch --transport containers-storage localhost/bootc-etc-conflict } | complete
41+
print $"exit_code: ($result.exit_code)"
42+
print $"stderr: ($result.stderr)"
43+
44+
assert ($result.exit_code != 0) "bootc switch should fail: locally-added file conflicts with directory in new etc"
45+
assert ($result.stderr | str contains "Merge conflicts found in etc") $"Expected 'Merge conflicts found in etc' in stderr, got: ($result.stderr)"
46+
47+
# Verify no deployment was staged - the failure must happen during upgrade,
48+
# not during finalization at reboot.
49+
assert ((bootc status --json | from json | get status.staged) == null) "No deployment should be staged after merge conflict failure"
50+
51+
# Test case 2: Directory in current /etc conflicts with file in new image's /etc.
52+
# Create a directory with a file inside on the live system; the new image
53+
# will have a regular file at the same path.
54+
mkdir /etc/test-etc-merge-dir
55+
"local config" | save /etc/test-etc-merge-dir/local.conf
56+
57+
let td2 = mktemp -d
58+
cd $td2
59+
60+
let dockerfile2 = '
61+
FROM localhost/bootc as base
62+
RUN echo "now a file" > /etc/test-etc-merge-dir
63+
'
64+
(tap make_uki_containerfile $dockerfile2) | save Dockerfile
65+
podman build -t localhost/bootc-etc-conflict-2 .
66+
67+
let result2 = do { bootc switch --transport containers-storage localhost/bootc-etc-conflict-2 } | complete
68+
print $"exit_code: ($result2.exit_code)"
69+
print $"stderr: ($result2.stderr)"
70+
71+
assert ($result2.exit_code != 0) "bootc switch should fail: locally-added directory conflicts with file in new etc"
72+
assert ($result2.stderr | str contains "Merge conflicts found in etc") $"Expected 'Merge conflicts found in etc' in stderr, got: ($result2.stderr)"
73+
74+
# Again verify nothing was staged
75+
assert ((bootc status --json | from json | get status.staged) == null) "No deployment should be staged after directory-to-file conflict failure"
76+
77+
tap ok
78+
}

tmt/tests/tests.fmf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,8 @@ check:
178178
summary: Test composefs backend resilience to state corruption
179179
duration: 30m
180180
test: nu booted/test-composefs-corruped-state-resilience.nu
181+
182+
/test-46-etc-merge-conflict:
183+
summary: Verify etc merge conflicts are caught during upgrade, not finalization
184+
duration: 15m
185+
test: nu booted/test-etc-merge-conflict.nu

0 commit comments

Comments
 (0)