add test for get and define save image xml and there are types of save image file covered in the test: persistent, transient and invalid domain save image --- scripts/qemu/400-save-image-xml.t | 107 +++++++++++++++++++++++++++++++++++++ 1 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 scripts/qemu/400-save-image-xml.t diff --git a/scripts/qemu/400-save-image-xml.t b/scripts/qemu/400-save-image-xml.t new file mode 100644 index 0000000..d584de1 --- /dev/null +++ b/scripts/qemu/400-save-image-xml.t @@ -0,0 +1,107 @@ +# -*- perl -*- +# +# Copyright (C) 2012-2013 Red Hat, Inc. +# Copyright (C) 2012-2013 Xiaoqiang Hu <xhu@xxxxxxxxxx> +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=pod + +=head1 NAME + +qemu/400-save-image-xml.t: test get and define xml from save image + +=head1 DESCRIPTION + +The test case validates that it is possible to define and get domain xml +from save image. There are three types of save image file covered in the +test: persistent, transient and invalid domain save image +=cut + +use strict; +use warnings; + +use Test::More tests => 10; + +use Sys::Virt::TCK; +use Test::Exception; + +my $tck = Sys::Virt::TCK->new(); +my $conn = eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { + $tck->cleanup if $tck; + unlink "tck.img" if -f "tck.img"; +} + +SKIP:{ + skip "Only relevant to QEMU driver", 10 unless $conn->get_type() eq "QEMU"; + + # scenario 1 - get/define xml from transient domain save image + my $xml = $tck->generic_domain("tck")->as_xml; + diag "Creating a new transient domain"; + my $dom; + ok_domain(sub { $dom = $conn->create_domain($xml) }, "created transient domain object"); + + unlink "tck.img" if -f "tck.img"; + eval { $dom->save("tck.img"); }; + SKIP: { + skip "save/restore not implemented", 9 if $@ && err_not_implemented($@); + ok(!$@, "domain saved"); + die $@ if $@; + + my ($savedxmldesc, $savefile); + $savefile = "tck.img"; + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error raised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + eval { $savedxmldesc = $conn->get_save_image_xml_description($savefile, 0); }; + SKIP: { + skip "get/define save img xml not implemented", 7 if $@ && err_not_implemented($@); + $savedxmldesc = $conn->get_save_image_xml_description($savefile, 0); + $savedxmldesc =~ s/destroy/restart/g; + $conn->define_save_image_xml($savefile, $savedxmldesc, 0); + + $savedxmldesc = $conn->get_save_image_xml_description($savefile, 0); + ok(!($savedxmldesc =~ m/destroy/), "the transient domain save image xml has been updated"); + + # scenario 2 - get/define xml from persistent domain save image + my $xml = $tck->generic_domain("tck")->as_xml; + diag "Creating a new persistent domain"; + ok_domain(sub { $dom = $conn->define_domain($xml) }, "created persistent domain object"); + + unlink "tck.img" if -f "tck.img"; + diag "Starting inactive domain"; + $dom->create; + + $dom->save("tck.img"); + diag "Checking that persistent domain is stopped"; + ok_domain(sub { $conn->get_domain_by_name("tck") }, "persistent domain is still there", "tck"); + is($dom->get_id, -1, "running domain with ID == -1"); + + $savedxmldesc = $conn->get_save_image_xml_description($savefile, 0); + $savedxmldesc =~ s/destroy/restart/g; + $conn->define_save_image_xml($savefile, $savedxmldesc, 0); + + $savedxmldesc = $conn->get_save_image_xml_description($savefile, 0); + ok(!($savedxmldesc =~ m/destroy/), "the persistent save image xml has been updated"); + + # scenario 3 - get/define xml from invalid domain save image + unlink "tck.img" if -f "tck.img"; + diag "Creating an invalid save img file"; + `dd if=/dev/null of=tck.img bs=1M count=100 >& /dev/null 2>&1`; + ok($? == 0, "created 100M raw img file: test.img"); + $savefile = "tck.img"; + diag "Getting xml from invalid save image"; + ok_error(sub { $conn->get_save_image_xml_description($savefile, 0) }, "failed to get invalid domain save image xml" ); + } + } +} +# end -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list