From: "Daniel P. Berrange" <berrange(a)redhat.com>
The test case validates the core lifecycle operations on
persistent domains with snapshots. A transient domain
should allow snapshots to be created while running. It
should be possible to destory and restart the domain
and still have snapshots present.
---
scripts/domain-snapshot/050-transient-snapshot.t | 97 ++++++++++++++++++++++
1 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 scripts/domain-snapshot/050-transient-snapshot.t
diff --git a/scripts/domain-snapshot/050-transient-snapshot.t
b/scripts/domain-snapshot/050-transient-snapshot.t
new file mode 100644
index 0000000..a314248
--- /dev/null
+++ b/scripts/domain-snapshot/050-transient-snapshot.t
@@ -0,0 +1,97 @@
+# -*- perl -*-
+#
+# Copyright (C) 2011 Red Hat, Inc.
+#
+# 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/050-transient-snapshot.t - lifecycle of transient domains with snapshots
+
+=head1 DESCRIPTION
+
+The test case validates the core lifecycle operations on
+persistent domains with snapshots. A transient domain
+should allow snapshots to be created while running. It
+should be possible to destory and restart the domain
+and still have snapshots present.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 12;
+use Test::Exception;
+use Sys::Virt::TCK;
+use Sys::Virt::TCK::DomainSnapshotBuilder;
+
+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 $poolxml = $tck->generic_pool("dir")->as_xml;
+
+diag "Defining transient storage pool";
+my $pool;
+ok_pool(sub { $pool = $conn->define_storage_pool($poolxml) }, "define transient
storage pool");
+lives_ok(sub { $pool->build(0) }, "built storage pool");
+lives_ok(sub { $pool->create }, "started storage pool");
+
+my $volxml = $tck->generic_volume("tck", "qcow2",
1024*1024*50)->as_xml;
+my $vol;
+ok_volume(sub { $vol = $pool->create_volume($volxml) }, "create qcow2
volume");
+
+my $volpath = xpath($vol, "string(/volume/target/path)");
+diag "Vol path $volpath";
+my $domb = $tck->generic_domain("tck");
+$domb->{disks} = [];
+my $domxml = $domb->disk(type => "file", src => $volpath, dst =>
"hdb",
+ format => {name => "qemu", type =>
"qcow2"})->as_xml;
+
+diag "Creating a new transient domain";
+my $dom;
+ok_domain(sub { $dom = $conn->create_domain($domxml) }, "created transient domain
object");
+
+
+
+my $ssxml = Sys::Virt::TCK::DomainSnapshotBuilder->new(name =>
"ss1")->as_xml;
+
+my $domss;
+diag "Taking a snapshot";
+ok_domain_snapshot(sub { $domss = $dom->create_snapshot($ssxml)}, "created domain
snapshot");
+
+lives_ok(sub { $dom->destroy }, "destroyed domain");
+
+diag "Re-creating the domain";
+ok_domain(sub { $dom = $conn->create_domain($domxml) }, "created transient domain
object");
+
+diag "Looking up snapshot";
+$domss = undef;
+lives_ok(sub { $domss = $dom->get_snapshot_by_name("ss1"); }, "snapshot
still exists");
+
+diag "Deleting snapshot";
+lives_ok(sub { $domss->delete }, "deleted snapshot");
+
+diag "Destroying the transient domain";
+lives_ok(sub { $dom->destroy }, "destroyed domain");
+
+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);
+
+$vol->delete;
+$pool->destroy;
+$pool->delete;
+
+# end
--
1.7.6