tests: Update miscellaneous tests to use disk-create API.

Instead of calling out to qemu-img / truncate.
This commit is contained in:
Richard W.M. Jones
2014-01-28 15:06:39 +00:00
parent bd12e784e7
commit f02fddc26b
17 changed files with 45 additions and 56 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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");

View File

@@ -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 \

View File

@@ -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"

View File

@@ -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 ();

View File

@@ -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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

View File

@@ -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="

View File

@@ -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 ();