Skip to content

Commit 35c2069

Browse files
committed
test-volume-encryption.sh: skip iteration on /dev/loop*
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
1 parent 02f2eec commit 35c2069

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

scripts/test/test-volume-encryption.sh

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ check_and_install_commands() {
1515
# List of required commands and their packages (for RHEL/CentOS)
1616
local commands_and_packages=(
1717
"losetup:util-linux"
18-
"parted:parted"
1918
"mount:util-linux"
2019
"umount:util-linux"
2120
)
@@ -136,7 +135,7 @@ setup_config() {
136135
# Create a KBS volume config (using mock values for CI)
137136
cat >"${CONFIG_DIR}/volumes/kbs-test.toml" <<EOF
138137
volume = "kbs-test"
139-
dev = "/dev/loop99p1"
138+
dev = "${LOOP_DEV}"
140139
auto_open = true
141140
makefs = "ext4"
142141
integrity = true
@@ -155,36 +154,18 @@ create_test_disk() {
155154
dd if=/dev/zero of=test-disk.img bs=1M count=100
156155

157156
# Detach loop device if already attached
158-
for i in {0..9}; do
159-
if losetup -a | grep -q "test-disk.img"; then
160-
LOOP_DEV=$(losetup -a | grep "test-disk.img" | cut -d: -f1)
161-
losetup -d "$LOOP_DEV" 2>/dev/null || true
162-
fi
163-
done
157+
LOOP_DEVICE=$(losetup --associated "$IMAGE" | awk '{print $1}')
158+
if [ -n "$LOOP_DEVICE" ]; then
159+
losetup -d "$LOOP_DEV" 2>/dev/null || true
160+
fi
164161

165162
# Set up loop device (try different numbers if /dev/loop99 is busy)
166-
LOOP_DEV=""
167-
for i in {99..90}; do
168-
if ! losetup -P /dev/loop"$i" test-disk.img 2>/dev/null; then
169-
continue
170-
else
171-
LOOP_DEV="/dev/loop$i"
172-
break
173-
fi
174-
done
163+
LOOP_DEV=$(losetup --find)
175164

176165
if [[ -z "$LOOP_DEV" ]]; then
177166
error "Failed to set up loop device"
178167
fi
179168

180-
# Update the config file to use the actual loop device
181-
sed -i "s|/dev/loop99|${LOOP_DEV}|g" ${CONFIG_DIR}/volumes/kbs-test.toml
182-
183-
# Create GPT partition table and one partition
184-
parted --script "$LOOP_DEV" \
185-
mktable gpt \
186-
mkpart primary 1MiB 100%
187-
188169
# Wait for partition to be ready
189170
sleep 2
190171

@@ -298,12 +279,12 @@ main() {
298279

299280
log "Starting KBS volume encryption test"
300281

301-
# Setup config
302-
setup_config
303-
304282
# Create test disk
305283
create_test_disk
306284

285+
# Setup config
286+
setup_config
287+
307288
# Test volume operations
308289
if ! test_volume_init; then
309290
error "Volume initialization failed"

0 commit comments

Comments
 (0)