Instead of calling out to qemu-img / truncate.
---
diff/test-virt-diff.sh | 4 +++-
edit/test-virt-edit.sh | 4 +++-
fish/test-a.sh | 2 +-
fish/test-add-domain.sh | 2 +-
fish/test-d.sh | 2 +-
fuse/test-fuse-umount-race.sh | 4 +++-
python/t/810-rhbz811650.py | 6 ++----
resize/test-virt-resize.sh | 4 +++-
sysprep/test-virt-sysprep-passwords.sh | 4 +++-
tests/guests/guest-aux/make-fedora-img.pl | 15 ++++-----------
tests/hotplug/test-hot-add.pl | 13 ++++---------
tests/hotplug/test-hot-remove.pl | 13 ++++---------
tests/hotplug/test-hotplug-repeated.pl | 7 +------
tests/md/test-inspect-fstab.sh | 4 +++-
tests/mountable/test-mountable-inspect.sh | 4 +++-
tests/qemu/qemu-snapshot-isolation.sh | 3 ++-
tests/syslinux/test-syslinux.pl | 10 ++++------
17 files changed, 45 insertions(+), 56 deletions(-)
diff --git a/diff/test-virt-diff.sh b/diff/test-virt-diff.sh
index 95778d8..3a3a1aa 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 <<EOF
touch /diff
diff --git a/edit/test-virt-edit.sh b/edit/test-virt-edit.sh
index 572ad22..99c2e7c 100755
--- a/edit/test-virt-edit.sh
+++ b/edit/test-virt-edit.sh
@@ -28,7 +28,9 @@ rm -f test.qcow2
# 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
# Edit interactively. We have to simulate this by setting $EDITOR.
# The command will be: echo newline >> /tmp/file
diff --git a/fish/test-a.sh b/fish/test-a.sh
index df892fe..52194c2 100755
--- a/fish/test-a.sh
+++ b/fish/test-a.sh
@@ -30,7 +30,7 @@ $VG ./guestfish -x -a test-a.img </dev/null >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 </dev/null >test-a.out 2>&1
diff --git a/fish/test-add-domain.sh b/fish/test-add-domain.sh
index 419c5cf..a6b0e10 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 b891505..1e16bdc 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 67dbac9..7624219 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 128f3b5..56d8062 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 944301c..29c1e4c 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 </dev/null
-qemu-img create -f qcow2 -o preallocation=metadata test-virt-resize-2.img 500M
+$VG ../fish/guestfish \
+ disk-create test-virt-resize-2.img qcow2 500M preallocation:metadata
+
$VG ./virt-resize -d --debug-gc \
--expand /dev/sda2 \
--lv-expand /dev/VG/LV \
diff --git a/sysprep/test-virt-sysprep-passwords.sh
b/sysprep/test-virt-sysprep-passwords.sh
index f606501..488187c 100755
--- a/sysprep/test-virt-sysprep-passwords.sh
+++ b/sysprep/test-virt-sysprep-passwords.sh
@@ -35,7 +35,9 @@ fi
# so we fake that now.
rm -f passwords.qcow2 password
-qemu-img create -F raw -b ../tests/guests/fedora.img -f qcow2 passwords.qcow2
+../fish/guestfish -- \
+ disk-create passwords.qcow2 qcow2 -1 \
+ backingfile:../tests/guests/fedora.img backingformat:raw
../fish/guestfish -a passwords.qcow2 -i <<'EOF'
write-append /etc/shadow "test01::15677:0:99999:7:::\n"
diff --git a/tests/guests/guest-aux/make-fedora-img.pl
b/tests/guests/guest-aux/make-fedora-img.pl
index 0537bd2..4eb08b5 100755
--- a/tests/guests/guest-aux/make-fedora-img.pl
+++ b/tests/guests/guest-aux/make-fedora-img.pl
@@ -60,9 +60,7 @@ EOF
$bootdev = '/dev/sda1';
- open (my $img, '>', "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 310440e..2496e08 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 c9e4146..aa6ab93 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 635bf41..306bceb 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 635c06c..04ee9d1 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 10d1e9f..b248b01 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 360e999..82b3892 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 9844883..d86c095 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 ();
--
1.8.4.2