diff --git a/diff/test-virt-diff.sh b/diff/test-virt-diff.sh index 95778d810..3a3a1aaf8 100755 --- a/diff/test-virt-diff.sh +++ b/diff/test-virt-diff.sh @@ -32,7 +32,9 @@ fi rm -f fedora.qcow2 # Modify a copy of the image. -qemu-img create -f qcow2 -b ../tests/guests/fedora.img fedora.qcow2 +../fish/guestfish -- \ + disk-create fedora.qcow2 qcow2 -1 \ + backingfile:../tests/guests/fedora.img backingformat:raw ../fish/guestfish -a fedora.qcow2 -i <> /tmp/file diff --git a/fish/test-a.sh b/fish/test-a.sh index df892fe85..52194c2ea 100755 --- a/fish/test-a.sh +++ b/fish/test-a.sh @@ -30,7 +30,7 @@ $VG ./guestfish -x -a test-a.img test-a.out 2>&1 ! grep -sq 'add_drive.*format' test-a.out rm test-a.img -qemu-img create -f qcow2 test-a.img 100M +$VG ./guestfish disk-create test-a.img qcow2 100M $VG ./guestfish -x --format=qcow2 -a test-a.img test-a.out 2>&1 diff --git a/fish/test-add-domain.sh b/fish/test-add-domain.sh index 419c5cfe2..a6b0e1011 100755 --- a/fish/test-add-domain.sh +++ b/fish/test-add-domain.sh @@ -27,7 +27,7 @@ cwd="$(pwd)" $VG ./guestfish sparse test-add-domain-1.img 1M $VG ./guestfish sparse test-add-domain-2.img 1M -qemu-img create -f qcow2 test-add-domain-3.img 1M +$VG ./guestfish disk-create test-add-domain-3.img qcow2 1M $VG ./guestfish sparse test-add-domain-4.img 1M # Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml diff --git a/fish/test-d.sh b/fish/test-d.sh index b8915055e..1e16bdc3c 100755 --- a/fish/test-d.sh +++ b/fish/test-d.sh @@ -27,7 +27,7 @@ cwd="$(pwd)" $VG ./guestfish sparse test-d-1.img 1M $VG ./guestfish sparse test-d-2.img 1M -qemu-img create -f qcow2 test-d-3.img 1M +$VG ./guestfish disk-create test-d-3.img qcow2 1M $VG ./guestfish sparse test-d-4.img 1M # Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml diff --git a/fuse/test-fuse-umount-race.sh b/fuse/test-fuse-umount-race.sh index 67dbac90a..762421950 100755 --- a/fuse/test-fuse-umount-race.sh +++ b/fuse/test-fuse-umount-race.sh @@ -42,7 +42,9 @@ rm -f test.qcow2 test-copy.qcow2 test.pid rm -rf mp # Make a copy of the Fedora image so we can write to it then discard it. -qemu-img create -F raw -b ../tests/guests/fedora.img -f qcow2 test.qcow2 +../fish/guestfish -- \ + disk-create test.qcow2 qcow2 -1 \ + backingfile:../tests/guests/fedora.img backingformat:raw mkdir mp ./guestmount -a test.qcow2 -m /dev/VG/Root --pid-file test.pid mp diff --git a/python/t/810-rhbz811650.py b/python/t/810-rhbz811650.py index 128f3b5e8..56d806254 100644 --- a/python/t/810-rhbz811650.py +++ b/python/t/810-rhbz811650.py @@ -18,12 +18,10 @@ import os import guestfs -f = open ("rhbz811650.img", "w") -f.truncate (500 * 1024 * 1024) -f.close () - g = guestfs.GuestFS (python_return_dict=True) +g.disk_create ("rhbz811650.img", "raw", 500 * 1024 * 1024) + # Deliberate error: the disk format is supposed to be raw. g.add_drive ("rhbz811650.img", format="qcow2"); diff --git a/resize/test-virt-resize.sh b/resize/test-virt-resize.sh index 944301cda..29c1e4c2e 100755 --- a/resize/test-virt-resize.sh +++ b/resize/test-virt-resize.sh @@ -32,7 +32,9 @@ fi $VG ../fish/guestfish \ -N test-virt-resize-1.img=bootrootlv:/dev/VG/LV:ext2:ext4:400M:32M:gpt ', "fedora.img.tmp.$$") or die; - truncate ($img, $IMAGE_SIZE) or die; - close ($img) or die; + $g->disk_create ("fedora.img.tmp.$$", "raw", $IMAGE_SIZE); $g->add_drive ("fedora.img.tmp.$$"); $g->launch (); @@ -88,11 +86,8 @@ EOF $bootdev = '/dev/md/boot'; foreach my $img (@images) { - open (my $fh, '>', $img) or die; - truncate ($fh, $IMAGE_SIZE) or die; - close ($fh) or die; - - $g->add_drive ($img); + $g->disk_create ($img, "raw", $IMAGE_SIZE); + $g->add_drive ($img); } $g->launch (); @@ -140,9 +135,7 @@ EOF $bootdev = '/dev/sda1'; - open (my $img, '>', "fedora-btrfs.img.tmp.$$") or die; - truncate ($img, $IMAGE_SIZE) or die; - close ($img) or die; + $g->disk_create ("fedora-btrfs.img.tmp.$$", "raw", $IMAGE_SIZE); $g->add_drive ("fedora-btrfs.img.tmp.$$"); $g->launch (); diff --git a/tests/hotplug/test-hot-add.pl b/tests/hotplug/test-hot-add.pl index 310440e3a..2496e0877 100755 --- a/tests/hotplug/test-hot-add.pl +++ b/tests/hotplug/test-hot-add.pl @@ -36,15 +36,10 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { $g->launch (); # Create some temporary disks. -open FILE, ">test-hot-add-1.img" or die "test-hot-add-1.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test-hot-add-1.img: truncate: $!"; -close FILE; - -open FILE, ">test-hot-add-2.img" or die "test-hot-add-2.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test-hot-add-2.img: truncate: $!"; -close FILE; - -die unless system ("qemu-img create -f qcow2 -o preallocation=metadata test-hot-add-3.img 1G") == 0; +$g->disk_create ("test-hot-add-1.img", "raw", 512 * 1024 * 1024); +$g->disk_create ("test-hot-add-2.img", "raw", 512 * 1024 * 1024); +$g->disk_create ("test-hot-add-3.img", "qcow2", 1024 * 1024 * 1024, + preallocation => "metadata"); # Hot-add them. Labels are required. $g->add_drive ("test-hot-add-1.img", label => "a"); # autodetect format diff --git a/tests/hotplug/test-hot-remove.pl b/tests/hotplug/test-hot-remove.pl index c9e4146dc..aa6ab93fe 100755 --- a/tests/hotplug/test-hot-remove.pl +++ b/tests/hotplug/test-hot-remove.pl @@ -33,15 +33,10 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { } # Create some temporary disks. -open FILE, ">test-hot-remove-1.img" or die "test-hot-remove-1.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test-hot-remove-1.img: truncate: $!"; -close FILE; - -open FILE, ">test-hot-remove-2.img" or die "test-hot-remove-2.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test-hot-remove-2.img: truncate: $!"; -close FILE; - -die unless system ("qemu-img create -f qcow2 -o preallocation=metadata test-hot-remove-3.img 1G") == 0; +$g->disk_create ("test-hot-remove-1.img", "raw", 512 * 1024 * 1024); +$g->disk_create ("test-hot-remove-2.img", "raw", 512 * 1024 * 1024); +$g->disk_create ("test-hot-remove-3.img", "qcow2", 1024 * 1024 * 1024, + preallocation => "metadata"); # Hot-add them. Labels are required. $g->add_drive ("test-hot-remove-1.img", label => "a"); # autodetect format diff --git a/tests/hotplug/test-hotplug-repeated.pl b/tests/hotplug/test-hotplug-repeated.pl index 635bf41b5..306bcebc1 100755 --- a/tests/hotplug/test-hotplug-repeated.pl +++ b/tests/hotplug/test-hotplug-repeated.pl @@ -35,12 +35,7 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { $g->launch (); # Create a temporary disk. -open FILE, ">test-hotplug-repeated.img" or - die "test-hotplug-repeated.img: $!"; -truncate FILE, 512 * 1024 * 1024 or - die "test-hotplug-repeated.img: truncate: $!"; -close FILE or - die "test-hotplug-repeated.img: close: $!"; +$g->disk_create ("test-hotplug-repeated.img", "raw", 512 * 1024 * 1024); my $start_t = time (); while (time () - $start_t <= 60) { diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh index 635c06c87..04ee9d16d 100755 --- a/tests/md/test-inspect-fstab.sh +++ b/tests/md/test-inspect-fstab.sh @@ -34,7 +34,9 @@ rm -f inspect-fstab-1.qcow2 inspect-fstab.fstab inspect-fstab.output # Start with the regular (good) fedora image, modify /etc/fstab # and then inspect it. -qemu-img create -F raw -b ../guests/fedora.img -f qcow2 inspect-fstab-1.qcow2 +$guestfish -- \ + disk-create inspect-fstab-1.qcow2 qcow2 -1 \ + backingfile:../guests/fedora.img backingformat:raw cat <<'EOF' > inspect-fstab.fstab /dev/VG/Root / ext2 default 0 0 diff --git a/tests/mountable/test-mountable-inspect.sh b/tests/mountable/test-mountable-inspect.sh index 10d1e9f38..b248b01eb 100755 --- a/tests/mountable/test-mountable-inspect.sh +++ b/tests/mountable/test-mountable-inspect.sh @@ -43,7 +43,9 @@ rm -f root.tmp test.qcow2 test.output # Start with the regular (good) fedora image, modify /etc/fstab # and then inspect it. -qemu-img create -F raw -b ../guests/fedora-btrfs.img -f qcow2 test.qcow2 +$guestfish -- \ + disk-create test.qcow2 qcow2 -1 \ + backingfile:../guests/fedora-btrfs.img backingformat:raw # Test that basic inspection works and the expected filesystems are # found diff --git a/tests/qemu/qemu-snapshot-isolation.sh b/tests/qemu/qemu-snapshot-isolation.sh index 360e999c1..82b3892f8 100755 --- a/tests/qemu/qemu-snapshot-isolation.sh +++ b/tests/qemu/qemu-snapshot-isolation.sh @@ -38,7 +38,8 @@ isolation1_md5sum="$(md5sum isolation1.img | awk '{print $1}')" isolation2_md5sum="$(md5sum isolation2.img | awk '{print $1}')" if [ "$supports_qcow2" = "yes" ]; then - qemu-img create -f qcow2 -o preallocation=metadata isolation3.img 100M + ../../fish/guestfish \ + disk-create isolation3.img qcow2 100M preallocation:metadata isolation3_md5sum="$(md5sum isolation3.img | awk '{print $1}')" add3="add-drive-opts isolation3.img format:qcow2 readonly:true" cmds3=" diff --git a/tests/syslinux/test-syslinux.pl b/tests/syslinux/test-syslinux.pl index 9844883f6..d86c0957d 100755 --- a/tests/syslinux/test-syslinux.pl +++ b/tests/syslinux/test-syslinux.pl @@ -55,13 +55,11 @@ unless ($kernel) { } print "kernel: $kernel\n"; -# Create the disk. -unlink "$disk"; -open DISK, ">$disk" or die "$disk: $!"; -truncate DISK, 100*1024*1024; -close DISK; - my $g = Sys::Guestfs->new (); + +# Create the disk. +$g->disk_create ($disk, "raw", 100*1024*1024); + $g->add_drive ($disk, format => "raw"); $g->launch ();