Skip to content

Commit

Permalink
use dmsetup remove instead of luksClose
Browse files Browse the repository at this point in the history
test

Signed-off-by: flouthoc <[email protected]>
  • Loading branch information
flouthoc committed Feb 14, 2025
1 parent e8a8c8b commit 3261d84
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Binary file modified internal/mkcw/embed/entrypoint_amd64.gz
Binary file not shown.
27 changes: 26 additions & 1 deletion tests/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,35 @@ function rm() {
#################
#
function run_with_log() {
local expected_rc=0
local cmd="$*"
case "$1" in
[0-9]) expected_rc=$1; shift;;
[1-9][0-9]) expected_rc=$1; shift;;
[12][0-9][0-9]) expected_rc=$1; shift;;
'?') expected_rc= ; shift;; # ignore exit code
esac
echo "$_LOG_PROMPT $cmd"
run -0 "$@"
run "$@"
echo "$output"
if [ "$status" -ne 0 ]; then
echo -n "[ rc=$status ";
if [ -n "$expected_rc" ]; then
if [ "$status" -eq "$expected_rc" ]; then
echo -n "(expected) ";
else
echo -n "(** EXPECTED $expected_rc **) ";
fi
fi
echo "]"
fi
if [ -n "$expected_rc" ]; then
if [ "$status" -eq "$expected_rc" ]; then
return
else
die "exit code is $status; expected $expected_rc"
fi
fi
}

#################
Expand Down
11 changes: 10 additions & 1 deletion tests/mkcw.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ function mkcw_check_image() {

# Decrypt, mount, and take a look around.
uuid=$(cryptsetup luksUUID "$mountpoint"/disk.img)
run_with_log echo "-----------Check who is using mountpoint------"
run_with_log '?' fuser -v "$mountpoint"
run_with_log cryptsetup luksOpen --key-file "$TEST_SCRATCH_DIR"/key "$mountpoint"/disk.img "$uuid"
mkdir -p "$TEST_SCRATCH_DIR"/mount
run_with_log echo "-----------Check who is using device------"
run_with_log '?' fuser -v /dev/mapper/"$uuid"
run_with_log mount /dev/mapper/"$uuid" "$TEST_SCRATCH_DIR"/mount
# Should have a not-empty config file with parts of an image's config.
test -s "$TEST_SCRATCH_DIR"/mount/.krun_config.json
Expand All @@ -42,7 +46,12 @@ function mkcw_check_image() {
fi

# Clean up.
run_with_log umount -f -l "$TEST_SCRATCH_DIR"/mount
run_with_log echo "-----------Check who is using device------"
run_with_log '?' fuser -v /dev/mapper/"$uuid"
run_with_log umount -f "$TEST_SCRATCH_DIR"/mount
# Check what is keeping the device busy
run_with_log echo "-----------Check who is using device------"
run_with_log '?' fuser -v /dev/mapper/"$uuid"
run_with_log cryptsetup luksClose "$uuid"
run_buildah umount "$ctrID"
}
Expand Down

0 comments on commit 3261d84

Please sign in to comment.