This tests the 3 main operations in removeable media
- Eject existing media
- Insert new media
- Change existing media (eject followed by insert)
* lib/Sys/Virt/TCK.pm: Allow a specific ostype to be requested
when getting a guest config
* scripts/domain/207-disk-media-change.t: Test media change,
eject, and re-insert
---
lib/Sys/Virt/TCK.pm | 20 +++++-
scripts/domain/207-disk-media-change.t | 95 ++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+), 4 deletions(-)
create mode 100644 scripts/domain/207-disk-media-change.t
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index d32b03d..9f67c08 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -416,6 +416,7 @@ sub match_kernel {
sub best_kernel {
my $self = shift;
my $caps = shift;
+ my $wantostype = shift;
my $kernels = $self->config("kernels", []);
@@ -425,6 +426,11 @@ sub best_kernel {
my @ostype = ref($ostype) ? @{$ostype} : ($ostype);
foreach $ostype (@ostype) {
+ if ((defined $wantostype) &&
+ ($wantostype ne $ostype)) {
+ next;
+ }
+
my ($domain, $emulator, $loader) =
$self->match_kernel($caps, $arch, $ostype);
@@ -440,9 +446,10 @@ sub best_kernel {
sub get_kernel {
my $self = shift;
my $caps = shift;
+ my $wantostype = shift;
my ($cfgindex, $domain, $arch, $ostype, $emulator, $loader) =
- $self->best_kernel($caps);
+ $self->best_kernel($caps, $wantostype);
if (!defined $cfgindex) {
die "cannot find any supported kernel configuration";
@@ -500,8 +507,9 @@ sub generic_machine_domain {
my $self = shift;
my $name = shift;
my $caps = shift;
+ my $ostype = shift;
- my %config = $self->get_kernel($caps);
+ my %config = $self->get_kernel($caps, $ostype);
my $b = Sys::Virt::TCK::DomainBuilder->new(conn => $self->{conn},
name => $name,
@@ -568,15 +576,19 @@ sub generic_container_domain {
sub generic_domain {
my $self = shift;
my $name = @_ ? shift : "tck";
+ my $ostype = @_ ? shift : undef;
my $caps = Sys::Virt::TCK::Capabilities->new(xml =>
$self->conn->get_capabilities);
- my $container = $self->best_container_domain($caps);
+ my $container;
+
+ $container = $self->best_container_domain($caps)
+ unless $ostype && $ostype ne "exe";
if ($container) {
return $self->generic_container_domain($name, $caps, $container);
} else {
- return $self->generic_machine_domain($name, $caps);
+ return $self->generic_machine_domain($name, $caps, $ostype);
}
}
diff --git a/scripts/domain/207-disk-media-change.t
b/scripts/domain/207-disk-media-change.t
new file mode 100644
index 0000000..2976800
--- /dev/null
+++ b/scripts/domain/207-disk-media-change.t
@@ -0,0 +1,95 @@
+# -*- perl -*-
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Copyright (C) 2009 Daniel P. Berrange
+#
+# 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
+
+domain/207-disk-media-change.t - verify disk media change works
+
+=head1 DESCRIPTION
+
+The test case validates that it is possible to change media
+on a CDROM disk in a running domain.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+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;
+}
+
+my $path1 = $tck->create_sparse_disk("200-disk-media-change",
"extra1.img", 100);
+my $path2 = $tck->create_sparse_disk("207-disk-media-change",
"extra2.img", 100);
+
+my $xml = $tck->generic_domain("tck", "wibble")
+ ->disk(src => $path1, dst => "hdc", type => "file",
device => "cdrom")
+ ->as_xml;
+
+diag "Creating a new transient domain";
+my $dom;
+ok_domain(sub { $dom = $conn->create_domain($xml) }, "created transient domain
object");
+
+
+my $diskxml1 = <<EOF;
+<disk type='file' device='cdrom'>
+ <source file='$path1'/>
+ <target dev='hdc'/>
+</disk>
+EOF
+my $diskxml2 = <<EOF;
+<disk type='file' device='cdrom'>
+ <source file='$path2'/>
+ <target dev='hdc'/>
+</disk>
+EOF
+my $diskxml3 = <<EOF;
+<disk type='file' device='cdrom'>
+ <target dev='hdc'/>
+</disk>
+EOF
+
+
+my $initialxml = $dom->get_xml_description;
+
+diag "Changing CDROM to $path2";
+lives_ok(sub { $dom->attach_device($diskxml2); }, "disk media has been
changed");
+
+my $newxml = $dom->get_xml_description;
+
+ok($newxml =~ m|$path2|, "new XML has updated media");
+
+diag "Ejecting CDROM media";
+lives_ok(sub { $dom->attach_device($diskxml3); }, "disk media has been
ejected");
+
+$newxml = $dom->get_xml_description;
+
+ok($newxml !~ m|$path2|, "new XML has no media");
+
+diag "Inserting CDROM media";
+lives_ok(sub { $dom->attach_device($diskxml1); }, "disk media has been
inserted");
+
+my $finalxml = $dom->get_xml_description;
+
+is($initialxml, $finalxml, "final XML matches initial XML");
--
1.6.6.1