Permalink
Browse files

tests: Use qemu-img to create an overlay for testing, instead of copy…

…ing.

Replace:

  cp tests/guests/fedora.img test.img

with the longer but possibly more space-efficient equivalent:

  qemu-img create -F raw -b tests/guests/fedora.img -f qcow2 test.qcow2
  • Loading branch information...
1 parent ea8421c commit 339f3647f889424af2a2256c4fcad0b44982c275 @rwmjones rwmjones committed Jun 29, 2012
Showing with 18 additions and 16 deletions.
  1. +9 −7 edit/test-virt-edit.sh
  2. +9 −9 tests/md/test-inspect-fstab.sh
View
@@ -3,15 +3,17 @@
export LANG=C
set -e
+rm -f test.qcow2
+
# Make a copy of the Fedora image so we can write to it then
# discard it.
-cp ../tests/guests/fedora.img test.img
+qemu-img create -F raw -b ../tests/guests/fedora.img -f qcow2 test.qcow2
# Edit interactively. We have to simulate this by setting $EDITOR.
# The command will be: echo newline >> /tmp/file
export EDITOR='echo newline >>'
-./virt-edit -a test.img /etc/test3
-if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "a
+./virt-edit -a test.qcow2 /etc/test3
+if [ "$(../cat/virt-cat -a test.qcow2 /etc/test3)" != "a
b
c
d
@@ -25,8 +27,8 @@ unset EDITOR
# Edit non-interactively, only if we have 'perl' binary.
if perl --version >/dev/null 2>&1; then
- ./virt-edit -a test.img /etc/test3 -e 's/^[a-f]/$lineno/'
- if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "1
+ ./virt-edit -a test.qcow2 /etc/test3 -e 's/^[a-f]/$lineno/'
+ if [ "$(../cat/virt-cat -a test.qcow2 /etc/test3)" != "1
2
3
4
@@ -40,12 +42,12 @@ fi
# Verify the mode of /etc/test3 is still 0600 and the UID:GID is 10:11.
# See tests/guests/guest-aux/make-fedora-img.pl and RHBZ#788641.
-if [ "$(../fish/guestfish -i -a test.img --ro lstat /etc/test3 | grep -E '^(mode|uid|gid):' | sort)" != "gid: 11
+if [ "$(../fish/guestfish -i -a test.qcow2 --ro lstat /etc/test3 | grep -E '^(mode|uid|gid):' | sort)" != "gid: 11
mode: 33152
uid: 10" ]; then
echo "$0: error: editing /etc/test3 did not preserve permissions or ownership"
exit 1
fi
# Discard test image.
-rm test.img
+rm test.qcow2
@@ -25,11 +25,11 @@ export LANG=C
guestfish=../../fish/guestfish
canonical="sed s,/dev/vd,/dev/sd,g"
-rm -f test1.img test.fstab test.output
+rm -f test1.qcow2 test.fstab test.output
# Start with the regular (good) fedora image, modify /etc/fstab
# and then inspect it.
-cp ../guests/fedora.img test1.img
+qemu-img create -F raw -b ../guests/fedora.img -f qcow2 test1.qcow2
cat <<'EOF' > test.fstab
/dev/VG/Root / ext2 default 0 0
@@ -44,14 +44,14 @@ cat <<'EOF' > test.fstab
/dev/VG/LV1 /nosuchfile ext2 default 0 0
EOF
-$guestfish -a test1.img <<'EOF'
+$guestfish -a test1.qcow2 <<'EOF'
run
mount-options "" /dev/VG/Root /
upload test.fstab /etc/fstab
EOF
# This will give a warning, but should not fail.
-$guestfish -a test1.img -i <<'EOF' | sort | $canonical > test.output
+$guestfish -a test1.qcow2 -i <<'EOF' | sort | $canonical > test.output
inspect-get-mountpoints /dev/VG/Root
EOF
@@ -73,14 +73,14 @@ cat <<'EOF' > test.fstab
/dev/xvdg1 /boot ext2 default 0 0
EOF
-$guestfish -a test1.img <<'EOF'
+$guestfish -a test1.qcow2 <<'EOF'
run
mount-options "" /dev/VG/Root /
upload test.fstab /etc/fstab
EOF
$guestfish <<'EOF' | $canonical > test.output
- add-drive-opts test1.img readonly:true name:xvdg
+ add-drive-opts test1.qcow2 readonly:true name:xvdg
run
inspect-os
inspect-get-mountpoints /dev/VG/Root
@@ -104,14 +104,14 @@ cat <<'EOF' > test.fstab
/dev/cciss/c1d3 /var ext2 default 0 0
EOF
-$guestfish -a test1.img <<'EOF'
+$guestfish -a test1.qcow2 <<'EOF'
run
mount-options "" /dev/VG/Root /
upload test.fstab /etc/fstab
EOF
$guestfish <<'EOF' | $canonical > test.output
- add-drive-opts test1.img readonly:true name:cciss/c1d3
+ add-drive-opts test1.qcow2 readonly:true name:cciss/c1d3
run
inspect-os
inspect-get-mountpoints /dev/VG/Root
@@ -127,5 +127,5 @@ if [ "$(cat test.output)" != "/dev/VG/Root
fi
rm test.fstab
-rm test1.img
+rm test1.qcow2
rm test.output

0 comments on commit 339f364

Please sign in to comment.