Skip to content
Snippets Groups Projects
Unverified Commit 886a1598 authored by Michal Hrusecky's avatar Michal Hrusecky :mouse:
Browse files

fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Basic functional tests

parent 1e94e63f
Branches shell-test
No related merge requests found
Pipeline #52220 failed with stage
in 22 seconds
......@@ -2,7 +2,7 @@ image: "ubuntu:latest"
before_script:
- apt-get update
- apt-get install -y btrfs-progs bats sudo
- apt-get install -y btrfs-progs bats sudo uml-utilities
test:
script:
......
......@@ -70,8 +70,8 @@ format_drive() {
reload_partitions "$disk"
# Try to get UUID
UUID="$(echo "$RES" | sed -n 's|Filesystem UUID: \([0-9a-f-]*\)|\1|p')"
[ -n "$UUID" ] || UUID="$(blkid "$disk" -s UUID -o value)"
UUID="$(echo "$RES" | sed -n 's|.*UUID:[[:blank:]]*\([0-9a-f-]*\)|\1|p')"
[ -n "$UUID" ] || UUID="$(blkid -c /dev/null "$disk" -s UUID -o value)"
[ -n "$UUID" ] || die "Can't get UUID of your newly formatted drive."
# Prepare snapshot on the drive
......@@ -84,7 +84,7 @@ format_drive() {
# Does the disk have srv UUID
has_uuid() {
[ "$(blkid "$1" -s UUID -o value)" = "$UUID" ]
[ "$(blkid -c /dev/null "$1" -s UUID -o value)" = "$UUID" ]
}
# Check syntax
......@@ -131,7 +131,7 @@ if [ -z "$UUID" ]; then
SRV_UUID="rootfs"
else
[ -z "$SRV" ] || SRV_DEV="$(sed -n 's|^\(/dev/[^[:blank:]]*\) '"$SRV"' .*|\1|p' /proc/mounts)"
[ -z "$SRV_DEV" ] || SRV_UUID="$(blkid "$SRV_DEV" -s UUID -o value)"
[ -z "$SRV_DEV" ] || SRV_UUID="$(blkid -c /dev/null "$SRV_DEV" -s UUID -o value)"
fi
[ -n "$SRV_UUID" ] || die "Can't find your current srv location"
uci set storage.srv.uuid="$UUID"
......@@ -143,7 +143,7 @@ fi
if [ "$(stat -c %m /srv/)" = "$(stat -c %m /)" ]; then
SRV_MNT_PNT="/tmp/storage_plugin/tmpdir"
mkdir -p "$SRV_MNT_PNT"
DEV="$(blkid -U "$UUID")"
DEV="$(blkid -c /dev/null -U "$UUID")"
[ -n "$DEV" ] || die "Can't find device with UUID $UUID"
mount -t btrfs -o subvol=@ "$DEV" "$SRV_MNT_PNT" || die "Can't mount $DEV"
fi
......@@ -183,7 +183,7 @@ elif [ "$RAID" = raid1 ]; then
# Check is some data/metadata are still not in RAID configuration
if btrfs device usage "$SRV_MNT_PNT" | grep -q -E '(Data,single|Metadata,DUP)'; then
set_state "Converting to RAID1 configuration"
RES="$(btrfs balance start -dconvert=raid10 -mconvert=raid10 "$SRV_MNT_PNT" 2>&1)"||\
RES="$(btrfs balance start -dconvert=raid1 -mconvert=raid1 "$SRV_MNT_PNT" 2>&1)"||\
die "Converting raid profile failed." "$RES"
CHANGED=""
fi
......
......@@ -2,7 +2,6 @@
setup() {
for i in $(seq 0 3); do
[ -b /dev/loop$i ] || mknod /dev/loop0 b 7 0
truncate -s 1G /tmp/storage-test-drive-$i
losetup /dev/loop$i /tmp/storage-test-drive-$i
done
......@@ -10,6 +9,7 @@ setup() {
echo "#!/bin/sh" > /lib/functions.sh
cat >> /lib/functions.sh << EOF
config_load() { :; }
create_notification() { :; }
config_get() { :; }
config_get_bool() { :; }
uci() {
......@@ -20,12 +20,6 @@ setup() {
EOF
}
get_df() {
mkdir -p /tmp/storage-test-mount
mount -t btrfs -o subvol=@ "$1" /tmp/storage-test-mount || return 2
df -BM -P /tmp/storage-test-mount | sed -n 's|.*[[:blank:]]\([0-9]*\)M[[:blank:]][^M]*$|\1|p'
}
teardown() {
umount -fl /tmp/storage-test-mount 2> /dev/null
rm -rf /tmp/storage-test-mount
......@@ -33,13 +27,22 @@ teardown() {
losetup -d /dev/loop$i
rm -f /tmp/storage-test-drive-$i
done
rm -f /lib/functions.sh
rm -f /tmp/storage_debug
}
get_df() {
mkdir -p /tmp/storage-test-mount
mount -t btrfs -o subvol=@ "$1" /tmp/storage-test-mount || return 2
df -BM -P /tmp/storage-test-mount | sed -n 's|.*[[:blank:]]\([0-9]*\)M[[:blank:]][^M]*$|\1|p'
umount -fl /tmp/storage-test-mount
}
@test "Format one drive" {
format_and_set_srv.sh -d /dev/loop0
run get_df /dev/loop0
[ "$status" -eq 0 ]
[ "$output" -gt 800 ]
[ "$output" -gt 500 ]
}
@test "Format multiple drives in JBOD mode" {
......@@ -47,14 +50,31 @@ teardown() {
format_and_set_srv.sh -d /dev/loop0 /dev/loop1
run get_df /dev/loop0
[ "$status" -eq 0 ]
[ "$output" -gt 1800 ]
[ "$output" -gt 1500 ]
}
@test "Format multiple drives in RADI10 mode" {
echo "RAID=raid10" >> /lib/functions.sh
@test "Format multiple drives in RADI1 mode" {
echo "RAID=raid1" >> /lib/functions.sh
format_and_set_srv.sh -d /dev/loop0 /dev/loop1
run get_df /dev/loop0
echo "Got free space of $output"
[ "$status" -eq 0 ]
[ "$output" -lt 1800 ]
[ "$output" -gt 800 ]
[ "$output" -lt 1500 ]
[ "$output" -gt 500 ]
}
@test "Make sure that data survives various reconfigurations" {
TEST_PATTERN="Testing whether drives are working"
format_and_set_srv.sh -d /dev/loop0 /dev/loop1
run get_df /dev/loop0
[ "$status" -eq 0 ]
[ "$output" -gt 1500 ]
mount -t btrfs -o subvol=@ /dev/loop0 /tmp/storage-test-mount
echo "$TEST_PATTERN" > /tmp/storage-test-mount/testfile
format_and_set_srv.sh -d /dev/loop0 /dev/loop1 /dev/loop2 /dev/loop3
format_and_set_srv.sh -d /dev/loop2 /dev/loop3
[ "$(cat /tmp/storage-test-mount/testfile)" = "$TEST_PATTERN" ]
format_and_set_srv.sh -d /dev/loop0 /dev/loop1
[ "$(cat /tmp/storage-test-mount/testfile)" = "$TEST_PATTERN" ]
umount /tmp/storage-test-mount
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment