From 64bb9edd527c9c7082721891cb7f090484858ab3 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 19 May 2016 17:52:32 +0200 Subject: [PATCH] tests: specify the image format when possible When possible, make the disk image format explicit when invoking tools or using add-drive. This avoids warnings from qemu about the unspecified format for the image, and also makes qemu slightly faster (skipping the disk image probing). Tests checking the image probing are not touched. This changes also: - old-style invocations of tools (`$tool $filename`) into new style (`$tool -a $filename`) - add-drive-ro/add-drive-with-if guestfish commands into add/add-drive with explicit readonly/iface arguments There should be no change in the tests results. --- align/test-virt-alignment-scan.sh | 2 +- cat/test-virt-cat.sh | 4 ++-- cat/test-virt-filesystems.sh | 4 ++-- cat/test-virt-log.sh | 2 +- cat/test-virt-ls.sh | 4 ++-- customize/test-virt-customize.sh | 2 +- df/test-virt-df.sh | 2 +- diff/test-virt-diff.sh | 4 ++-- edit/test-virt-edit.sh | 6 +++--- fish/test-copy.sh | 2 +- fish/test-inspect.sh | 2 +- fish/test-run.sh | 2 +- format/test-virt-format.sh | 4 ++-- fuse/test-fuse-umount-race.sh | 4 ++-- inspector/test-virt-inspector.sh | 2 +- rescue/test-virt-rescue-suggest.sh | 2 +- sparsify/test-virt-sparsify-in-place.sh | 2 +- sparsify/test-virt-sparsify.sh | 2 +- sysprep/test-virt-sysprep-passwords.sh | 1 + sysprep/test-virt-sysprep-script.sh | 8 ++++---- sysprep/test-virt-sysprep.sh | 2 +- test-data/phony-guests/make-fedora-img.pl | 6 +++--- tests/gdisk/test-expand-gpt.pl | 4 ++-- tests/md/test-inspect-fstab-md.sh | 6 +++--- tests/md/test-inspect-fstab.sh | 8 ++++---- tests/md/test-list-md-devices.sh | 2 +- tests/mountable/test-mountable-inspect.sh | 4 ++-- tests/ntfs/test-ntfscat.sh | 2 +- tests/ntfs/test-ntfsclone.sh | 2 +- tests/regressions/rhbz1011907-1165785.sh | 4 ++-- tests/regressions/rhbz1054761.sh | 2 +- tests/regressions/rhbz1174551.sh | 2 +- tests/regressions/rhbz1285847.sh | 2 +- tests/regressions/rhbz563450.sh | 4 ++-- tests/regressions/rhbz580246.sh | 2 +- tests/regressions/rhbz690819.sh | 2 +- tests/regressions/rhbz789960.sh | 2 +- tests/regressions/rhbz811649.sh | 2 +- tests/regressions/rhbz975797.sh | 6 +++--- tests/tsk/test-download-inode.sh | 2 +- tools/test-virt-list-filesystems.sh | 2 +- 41 files changed, 65 insertions(+), 64 deletions(-) diff --git a/align/test-virt-alignment-scan.sh b/align/test-virt-alignment-scan.sh index 7568f2326..ab44c2695 100755 --- a/align/test-virt-alignment-scan.sh +++ b/align/test-virt-alignment-scan.sh @@ -18,7 +18,7 @@ export LANG=C -$VG virt-alignment-scan -a ../test-data/phony-guests/fedora.img +$VG virt-alignment-scan --format=raw -a ../test-data/phony-guests/fedora.img r=$? # 0, 2 and 3 are reasonable non-error exit codes. Others are errors. diff --git a/cat/test-virt-cat.sh b/cat/test-virt-cat.sh index fc055d5f9..14b4a65eb 100755 --- a/cat/test-virt-cat.sh +++ b/cat/test-virt-cat.sh @@ -20,11 +20,11 @@ export LANG=C set -e # Read out the test files from the image using virt-cat. -if [ "$($VG virt-cat ../test-data/phony-guests/fedora.img /etc/test1)" != "abcdefg" ]; then +if [ "$($VG virt-cat --format=raw -a ../test-data/phony-guests/fedora.img /etc/test1)" != "abcdefg" ]; then echo "$0: error: mismatch in file test1" exit 1 fi -if [ "$($VG virt-cat ../test-data/phony-guests/fedora.img /etc/test2)" != "" ]; then +if [ "$($VG virt-cat --format=raw -a ../test-data/phony-guests/fedora.img /etc/test2)" != "" ]; then echo "$0: error: mismatch in file test2" exit 1 fi diff --git a/cat/test-virt-filesystems.sh b/cat/test-virt-filesystems.sh index 6f13bd79d..6c300dff6 100755 --- a/cat/test-virt-filesystems.sh +++ b/cat/test-virt-filesystems.sh @@ -19,7 +19,7 @@ export LANG=C set -e -output="$($VG virt-filesystems -a ../test-data/phony-guests/fedora.img | sort)" +output="$($VG virt-filesystems --format=raw -a ../test-data/phony-guests/fedora.img | sort)" expected="/dev/VG/LV1 /dev/VG/LV2 /dev/VG/LV3 @@ -32,7 +32,7 @@ if [ "$output" != "$expected" ]; then exit 1 fi -output="$($VG virt-filesystems -a ../test-data/phony-guests/fedora.img --all --long --uuid -h --no-title | awk '{print $1}' | sort -u)" +output="$($VG virt-filesystems --format=raw -a ../test-data/phony-guests/fedora.img --all --long --uuid -h --no-title | awk '{print $1}' | sort -u)" expected="/dev/VG /dev/VG/LV1 /dev/VG/LV2 diff --git a/cat/test-virt-log.sh b/cat/test-virt-log.sh index c1bf3e71a..4e08115ed 100755 --- a/cat/test-virt-log.sh +++ b/cat/test-virt-log.sh @@ -47,7 +47,7 @@ for f in ../test-data/phony-guests/{fedora,debian,ubuntu}.img; do echo continue fi - $VG virt-log -a "$f" &> $tmpfile + $VG virt-log --format=raw -a "$f" &> $tmpfile cat $tmpfile echo done diff --git a/cat/test-virt-ls.sh b/cat/test-virt-ls.sh index 4ea800864..4b7d927bc 100755 --- a/cat/test-virt-ls.sh +++ b/cat/test-virt-ls.sh @@ -20,7 +20,7 @@ export LANG=C set -e # Read out the test directory using virt-ls. -if [ "$($VG virt-ls ../test-data/phony-guests/fedora.img /bin)" != "ls +if [ "$($VG virt-ls --format=raw -a ../test-data/phony-guests/fedora.img /bin)" != "ls test1 test2 test3 @@ -33,7 +33,7 @@ test7" ]; then fi # Try the -lR option. -output="$($VG virt-ls -lR ../test-data/phony-guests/fedora.img /boot | awk '{print $1 $2 $4}')" +output="$($VG virt-ls -lR --format=raw -a ../test-data/phony-guests/fedora.img /boot | awk '{print $1 $2 $4}')" expected="d0755/boot d0755/boot/grub -0644/boot/grub/grub.conf diff --git a/customize/test-virt-customize.sh b/customize/test-virt-customize.sh index 00d1978b3..f98eccd31 100755 --- a/customize/test-virt-customize.sh +++ b/customize/test-virt-customize.sh @@ -26,7 +26,7 @@ for f in ../test-data/phony-guests/{debian,fedora,ubuntu}.img; do # Ignore zero-sized windows.img if ntfs-3g is not installed. if [ -s "$f" ]; then # Add --no-network so UML works. - $VG virt-customize -n -a $f \ + $VG virt-customize -n --format=raw -a $f \ --no-network \ --write /etc/motd:HELLO \ --chmod 0600:/etc/motd \ diff --git a/df/test-virt-df.sh b/df/test-virt-df.sh index 0c2fa6b72..cd068e929 100755 --- a/df/test-virt-df.sh +++ b/df/test-virt-df.sh @@ -20,7 +20,7 @@ export LANG=C set -e # Run virt-df. -output=$($VG virt-df ../test-data/phony-guests/fedora.img) +output=$($VG virt-df --format=raw -a ../test-data/phony-guests/fedora.img) # Check title is the first line. if [[ ! $output =~ ^Filesystem.* ]]; then diff --git a/diff/test-virt-diff.sh b/diff/test-virt-diff.sh index d15804377..5a635150d 100755 --- a/diff/test-virt-diff.sh +++ b/diff/test-virt-diff.sh @@ -36,12 +36,12 @@ guestfish -- \ disk-create fedora.qcow2 qcow2 -1 \ backingfile:../test-data/phony-guests/fedora.img backingformat:raw -guestfish -a fedora.qcow2 -i < "actual-$b.xml" + $VG virt-inspector --format=raw -a "$f" > "actual-$b.xml" # This 'diff' command will fail (because of -e option) if there # are any differences. diff -ur $diff_ignore "expected-$b.xml" "actual-$b.xml" diff --git a/rescue/test-virt-rescue-suggest.sh b/rescue/test-virt-rescue-suggest.sh index e49b38f24..a8b41e22c 100755 --- a/rescue/test-virt-rescue-suggest.sh +++ b/rescue/test-virt-rescue-suggest.sh @@ -28,7 +28,7 @@ fi rm -f virt-rescue-suggest.out -$VG virt-rescue --suggest "$guest" | +$VG virt-rescue --suggest --format=raw -a "$guest" | grep '^mount ' | sed -r 's,/dev/[abce-ln-z]+d,/dev/sd,' > virt-rescue-suggest.out diff --git a/sparsify/test-virt-sparsify-in-place.sh b/sparsify/test-virt-sparsify-in-place.sh index 456ae3a6f..8797c27a3 100755 --- a/sparsify/test-virt-sparsify-in-place.sh +++ b/sparsify/test-virt-sparsify-in-place.sh @@ -49,7 +49,7 @@ EOF size_before=$(du -s test-virt-sparsify-in-place.img | awk '{print $1}') -$VG virt-sparsify --debug-gc --in-place test-virt-sparsify-in-place.img || { +$VG virt-sparsify --debug-gc --in-place --format raw test-virt-sparsify-in-place.img || { if [ "$?" -eq 3 ]; then rm test-virt-sparsify-in-place.img echo "$0: discard not supported in virt-sparsify" diff --git a/sparsify/test-virt-sparsify.sh b/sparsify/test-virt-sparsify.sh index 040442449..7d18bf684 100755 --- a/sparsify/test-virt-sparsify.sh +++ b/sparsify/test-virt-sparsify.sh @@ -42,7 +42,7 @@ rm /boot/big umount-all EOF -$VG virt-sparsify --debug-gc test-virt-sparsify-1.img --convert qcow2 test-virt-sparsify-2.img +$VG virt-sparsify --debug-gc --format raw test-virt-sparsify-1.img --convert qcow2 test-virt-sparsify-2.img size_before=$(du -s test-virt-sparsify-1.img | awk '{print $1}') size_after=$(du -s test-virt-sparsify-2.img | awk '{print $1}') diff --git a/sysprep/test-virt-sysprep-passwords.sh b/sysprep/test-virt-sysprep-passwords.sh index ba34b0c5d..5e185e398 100755 --- a/sysprep/test-virt-sysprep-passwords.sh +++ b/sysprep/test-virt-sysprep-passwords.sh @@ -58,6 +58,7 @@ echo 123456 > password # Run virt-sysprep password operation. virt-sysprep \ + --format qcow2 \ -a passwords.qcow2 \ --enable customize \ --password test01:password:123456 \ diff --git a/sysprep/test-virt-sysprep-script.sh b/sysprep/test-virt-sysprep-script.sh index 409a9b766..49d075640 100755 --- a/sysprep/test-virt-sysprep-script.sh +++ b/sysprep/test-virt-sysprep-script.sh @@ -32,7 +32,7 @@ fi # Check that multiple scripts can run. rm -f stamp-script1.sh stamp-script2.sh stamp-script4.sh -if ! virt-sysprep -q -n -a ../test-data/phony-guests/fedora.img --enable script \ +if ! virt-sysprep -q -n --format raw -a ../test-data/phony-guests/fedora.img --enable script \ --script $abs_srcdir/script1.sh --script $abs_srcdir/script2.sh; then echo "$0: virt-sysprep wasn't expected to exit with error." exit 1 @@ -43,19 +43,19 @@ if [ ! -f stamp-script1.sh -o ! -f stamp-script2.sh ]; then fi # Check that if a script fails, virt-sysprep exits with an error. -if virt-sysprep -q -n -a ../test-data/phony-guests/fedora.img --enable script \ +if virt-sysprep -q -n --format raw -a ../test-data/phony-guests/fedora.img --enable script \ --script $abs_srcdir/script3.sh; then echo "$0: virt-sysprep didn't exit with an error." exit 1 fi # Check that virt-sysprep uses a new temporary directory every time. -if ! virt-sysprep -q -n -a ../test-data/phony-guests/fedora.img --enable script \ +if ! virt-sysprep -q -n --format raw -a ../test-data/phony-guests/fedora.img --enable script \ --script $abs_srcdir/script4.sh; then echo "$0: virt-sysprep (script4.sh, try #1) wasn't expected to exit with error." exit 1 fi -if ! virt-sysprep -q -n -a ../test-data/phony-guests/fedora.img --enable script \ +if ! virt-sysprep -q -n --format raw -a ../test-data/phony-guests/fedora.img --enable script \ --script $abs_srcdir/script4.sh; then echo "$0: virt-sysprep (script4.sh, try #2) wasn't expected to exit with error." exit 1 diff --git a/sysprep/test-virt-sysprep.sh b/sysprep/test-virt-sysprep.sh index e9dd9a9b3..802f9b69e 100755 --- a/sysprep/test-virt-sysprep.sh +++ b/sysprep/test-virt-sysprep.sh @@ -41,7 +41,7 @@ for f in ../test-data/phony-guests/{debian,fedora,ubuntu,windows}.img; do # Ignore zero-sized windows.img if ntfs-3g is not installed. if [ -s "$f" ]; then echo "Running virt-sysprep on $f ..." - $VG virt-sysprep -q -n --enable "$operations" -a $f + $VG virt-sysprep -q -n --enable "$operations" --format raw -a $f echo fi done diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl index 192f48f23..5a6adab25 100755 --- a/test-data/phony-guests/make-fedora-img.pl +++ b/test-data/phony-guests/make-fedora-img.pl @@ -62,7 +62,7 @@ EOF $g->disk_create ("fedora.img-t", "raw", $IMAGE_SIZE); - $g->add_drive ("fedora.img-t"); + $g->add_drive ("fedora.img-t", format => "raw"); $g->launch (); $g->part_init ('/dev/sda', 'mbr'); @@ -87,7 +87,7 @@ EOF foreach my $img (@images) { $g->disk_create ($img, "raw", $IMAGE_SIZE); - $g->add_drive ($img); + $g->add_drive ($img, format => "raw"); } $g->launch (); @@ -137,7 +137,7 @@ EOF $g->disk_create ("fedora-btrfs.img-t", "raw", $IMAGE_SIZE); - $g->add_drive ("fedora-btrfs.img-t"); + $g->add_drive ("fedora-btrfs.img-t", format => "raw"); $g->launch (); $g->part_init ('/dev/sda', 'mbr'); diff --git a/tests/gdisk/test-expand-gpt.pl b/tests/gdisk/test-expand-gpt.pl index 637b90e9b..4d647f1af 100755 --- a/tests/gdisk/test-expand-gpt.pl +++ b/tests/gdisk/test-expand-gpt.pl @@ -25,7 +25,7 @@ sub tests { foreach ("gpt", "mbr") { $g->disk_create ("disk_$_.img", "qcow2", 50 * 1024 * 1024); - $g->add_drive ("disk_$_.img"); + $g->add_drive ("disk_$_.img", format => "qcow2"); } $g->launch (); @@ -40,7 +40,7 @@ sub tests { $g = Sys::Guestfs->new (); foreach ("gpt", "mbr") { - $g->add_drive ("disk_$_.img"); + $g->add_drive ("disk_$_.img", format => "qcow2"); } $g->launch (); diff --git a/tests/md/test-inspect-fstab-md.sh b/tests/md/test-inspect-fstab-md.sh index 6c1842f57..3c25dac6f 100755 --- a/tests/md/test-inspect-fstab-md.sh +++ b/tests/md/test-inspect-fstab-md.sh @@ -32,7 +32,7 @@ rm -f inspect-fstab-md-{1,2}.img inspect-fstab-md.fstab inspect-fstab-md.output cp ../../test-data/phony-guests/fedora-md1.img inspect-fstab-md-1.img cp ../../test-data/phony-guests/fedora-md2.img inspect-fstab-md-2.img -guestfish -i inspect-fstab-md-[12].img <<'EOF' | sort > inspect-fstab-md.output +guestfish -i --format=raw -a inspect-fstab-md-1.img --format=raw -a inspect-fstab-md-2.img <<'EOF' | sort > inspect-fstab-md.output exists /boot/grub/grub.conf EOF @@ -47,13 +47,13 @@ cat <<'EOF' > inspect-fstab-md.fstab /dev/md/boot /boot ext2 default 0 0 EOF -guestfish -a inspect-fstab-md-1.img -a inspect-fstab-md-2.img <<'EOF' +guestfish --format=raw -a inspect-fstab-md-1.img --format=raw -a inspect-fstab-md-2.img <<'EOF' run mount /dev/VG/Root / upload inspect-fstab-md.fstab /etc/fstab EOF -guestfish -i inspect-fstab-md-[12].img <<'EOF' | sort > inspect-fstab-md.output +guestfish -i --format=raw -a inspect-fstab-md-1.img --format=raw -a inspect-fstab-md-2.img <<'EOF' | sort > inspect-fstab-md.output exists /boot/grub/grub.conf EOF diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh index 007ea0840..07391938f 100755 --- a/tests/md/test-inspect-fstab.sh +++ b/tests/md/test-inspect-fstab.sh @@ -55,14 +55,14 @@ cat <<'EOF' > inspect-fstab.fstab /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part3 /id3 ext2 default 0 0 EOF -guestfish -a inspect-fstab-1.qcow2 <<'EOF' +guestfish --format=qcow2 -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / upload inspect-fstab.fstab /etc/fstab EOF # This will give a warning, but should not fail. -guestfish -a inspect-fstab-1.qcow2 -i <<'EOF' | sort | $canonical > inspect-fstab.output +guestfish --format=qcow2 -a inspect-fstab-1.qcow2 -i <<'EOF' | sort | $canonical > inspect-fstab.output inspect-get-mountpoints /dev/VG/Root EOF @@ -87,7 +87,7 @@ cat <<'EOF' > inspect-fstab.fstab /dev/xvdg1 /boot ext2 default 0 0 EOF -guestfish -a inspect-fstab-1.qcow2 <<'EOF' +guestfish --format=qcow2 -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / upload inspect-fstab.fstab /etc/fstab @@ -118,7 +118,7 @@ cat <<'EOF' > inspect-fstab.fstab /dev/cciss/c1d3 /var ext2 default 0 0 EOF -guestfish -a inspect-fstab-1.qcow2 <<'EOF' +guestfish --format=qcow2 -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / upload inspect-fstab.fstab /etc/fstab diff --git a/tests/md/test-list-md-devices.sh b/tests/md/test-list-md-devices.sh index 5a9cbe814..3019f33eb 100755 --- a/tests/md/test-list-md-devices.sh +++ b/tests/md/test-list-md-devices.sh @@ -49,7 +49,7 @@ fi # Ensure list-md-devices now returns the newly created md device output=$( -guestfish -a list-md-devices-1.img -a list-md-devices-2.img < test.output +guestfish --format=qcow2 -a test.qcow2 -i <<'EOF' | sort | $canonical > test.output inspect-get-roots | head -1 > root.tmp test.output +guestfish --format=qcow2 -a test.qcow2 -i <<'EOF' > test.output inspect-get-roots | head -1 > root.tmp test.error +$VG guestfish --ro --format=raw -a ../../test-data/phony-guests/fedora.img -i <test.error # valid invocations lstatlist /etc "fedora-release sysconfig" lstatnslist /etc "fedora-release sysconfig" diff --git a/tests/regressions/rhbz1285847.sh b/tests/regressions/rhbz1285847.sh index f34fe54f0..0aa0611ae 100755 --- a/tests/regressions/rhbz1285847.sh +++ b/tests/regressions/rhbz1285847.sh @@ -59,7 +59,7 @@ truncate -s 10G rhbz1285847-2.img virt-resize rhbz1285847.img rhbz1285847-2.img --expand /dev/sda2 # Check that the filesystems made it across. -guestfish -a rhbz1285847-2.img run : list-filesystems > rhbz1285847.out +guestfish --format=raw -a rhbz1285847-2.img run : list-filesystems > rhbz1285847.out if [ "$(cat rhbz1285847.out)" != "/dev/sda1: ext4 /dev/sda2: unknown diff --git a/tests/regressions/rhbz563450.sh b/tests/regressions/rhbz563450.sh index 521567660..3c53da6c7 100755 --- a/tests/regressions/rhbz563450.sh +++ b/tests/regressions/rhbz563450.sh @@ -30,9 +30,9 @@ fi rm -f rhbz563450.out guestfish --ro > rhbz563450.out <&1 <<'EOF' -add rhbz580246.img +add rhbz580246.img format:raw run mkfs ext2 /dev/sda mount /dev/sda / diff --git a/tests/regressions/rhbz690819.sh b/tests/regressions/rhbz690819.sh index 0af0b646a..9c8d39edc 100755 --- a/tests/regressions/rhbz690819.sh +++ b/tests/regressions/rhbz690819.sh @@ -54,7 +54,7 @@ rm -f rhbz690819.img guestfish sparse rhbz690819.img 100M guestfish < rhbz789960.out < rhbz789960.out <