Skip to content

Commit 058d88d

Browse files
committed
fix: selftest
1 parent 8323563 commit 058d88d

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎system/cuos/selftest.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ is_container() {
5252
}
5353

5454
# "<subvolume> <mountpoint>" per line, for every mounted btrfs subvolume.
55+
# -l keeps the list flat: the tree output prefixes nested mountpoints with
56+
# drawing characters, which would end up in the mountpoint field.
5557
subvolumes() {
56-
findmnt -t btrfs -no TARGET,OPTIONS 2>/dev/null \
58+
findmnt -lt btrfs -no TARGET,OPTIONS 2>/dev/null \
5759
| sed -n 's|^\(\S*\)\s.*subvol=/\([^,]*\).*|\2 \1|p'
5860
}
5961

@@ -127,9 +129,11 @@ check_subvolumes() {
127129

128130
local mounted missing=""
129131
mounted="$(subvolumes)"
132+
# The root is a subvolume *below* @os - @os/system-A or @os/system-B - so what
133+
# is wanted is the subvolume or anything under it.
130134
local wanted
131135
for wanted in "@os" "@data"; do
132-
if ! grep -q "^${wanted}[[:space:]]" <<<"${mounted}"; then
136+
if ! grep -qE "^${wanted}(/\S*)?[[:space:]]" <<<"${mounted}"; then
133137
missing+="${missing:+, }${wanted}"
134138
fi
135139
done

‎system/cuos/selftest.test.sh‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ source "${SCRIPT_DIR}/lib-test.sh"
2424
# Nothing here touches a real system: every function that looks outward is
2525
# replaced, and the files the checks read live in a temporary directory.
2626
MOCK_VIRT="none"
27-
MOCK_SUBVOLUMES="@os /
28-
@data /data"
27+
MOCK_SUBVOLUMES="@os/system-A /
28+
@data /data
29+
@swap /swap"
2930
MOCK_ADDRESSES="eth0 10.0.0.5/24"
3031
MOCK_HOSTNAME="my-system"
3132
MOCK_DOCKER_OK=0
@@ -46,8 +47,9 @@ journal_errors() { echo "${MOCK_JOURNAL_ERRORS}"; }
4647
reset_system() {
4748
RESULTS=()
4849
MOCK_VIRT="none"
49-
MOCK_SUBVOLUMES="@os /
50-
@data /data"
50+
MOCK_SUBVOLUMES="@os/system-A /
51+
@data /data
52+
@swap /swap"
5153
MOCK_ADDRESSES="eth0 10.0.0.5/24"
5254
MOCK_HOSTNAME="my-system"
5355
MOCK_DOCKER_OK=0
@@ -117,12 +119,19 @@ break_slot() { echo "C" >"${T_FILE_SLOT}"; }
117119
expect "slot: A or B, nothing else" "failed" status_of slot break_slot
118120
expect "slot: an empty file fails" "failed" status_of slot rm -f "${T_FILE_SLOT}"
119121

120-
drop_data_subvolume() { MOCK_SUBVOLUMES="@os /"; }
122+
drop_data_subvolume() { MOCK_SUBVOLUMES="@os/system-A /"; }
121123
expect "subvolumes: a missing @data fails" "failed" status_of subvolumes \
122124
drop_data_subvolume
123125
expect "subvolumes: the failure names it" "not mounted: @data" detail_of \
124126
subvolumes drop_data_subvolume
125127

128+
# The root is @os/system-A or @os/system-B, never @os itself.
129+
expect "subvolumes: the slot below @os counts as @os" "ok" status_of subvolumes
130+
lose_the_os_subvolume() { MOCK_SUBVOLUMES="@osold/system-A /
131+
@data /data"; }
132+
expect "subvolumes: a subvolume merely starting with @os does not" "failed" \
133+
status_of subvolumes lose_the_os_subvolume
134+
126135
be_a_container() { MOCK_VIRT="lxc"; }
127136
expect "subvolumes: skipped in a container" "skipped" status_of subvolumes \
128137
be_a_container

0 commit comments

Comments
 (0)