From: "Daniel P. Berrange" <berrange(a)redhat.com>
The test case validates the core lifecycle operations on
persistent domains with snapshots. A persistent domain
should allow snapshots to be created & deleted while both
running and shutoff. It should forbid undefine of the
domain when it has snapshots present.
---
scripts/domain-snapshot/080-persistent-snapshot.t | 112 +++++++++++++++++++++
1 files changed, 112 insertions(+), 0 deletions(-)
create mode 100644 scripts/domain-snapshot/080-persistent-snapshot.t
diff --git a/scripts/domain-snapshot/080-persistent-snapshot.t
b/scripts/domain-snapshot/080-persistent-snapshot.t
new file mode 100644
index 0000000..4064003
--- /dev/null
+++ b/scripts/domain-snapshot/080-persistent-snapshot.t
@@ -0,0 +1,112 @@
+# -*- 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/080-persistent-snapshot.t - lifecycle of persistent domains with snapshots
+
+=head1 DESCRIPTION
+
+The test case validates the core lifecycle operations on
+persistent domains with snapshots. A persistent domain
+should allow snapshots to be created & deleted while both
+running and shutoff. It should forbid undefine of the
+domain when it has snapshots present.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 18;
+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 "Defining a new persistent domain";
+my $dom;
+ok_domain(sub { $dom = $conn->define_domain($domxml) }, "defined persistent
domain object");
+
+my $ss1xml = Sys::Virt::TCK::DomainSnapshotBuilder->new(name =>
"ss1")->as_xml;
+my $ss2xml = Sys::Virt::TCK::DomainSnapshotBuilder->new(name =>
"ss2")->as_xml;
+
+my $domss1;
+my $domss2;
+diag "Taking a snapshot while inactive";
+ok_domain_snapshot(sub { $domss2 = $dom->create_snapshot($ss1xml)}, "created
domain snapshot ss1");
+
+diag "Starting domain";
+lives_ok(sub { $dom->create }, "started domain");
+
+diag "Taking a snapshot while active";
+ok_domain_snapshot(sub { $domss2 = $dom->create_snapshot($ss2xml)}, "created
domain snapshot ss2");
+
+lives_ok(sub { $dom->destroy }, "destroyed domain");
+
+diag "Re-creating the domain";
+lives_ok(sub { $dom->create }, "recreated persistent domain object");
+
+diag "Looking up snapshot";
+$domss1 = undef;
+lives_ok(sub { $domss1 = $dom->get_snapshot_by_name("ss1"); },
"snapshot ss1 still exists");
+lives_ok(sub { $domss2 = $dom->get_snapshot_by_name("ss2"); },
"snapshot ss2 still exists");
+
+diag "Deleting snapshot ss1";
+lives_ok(sub { $domss1->delete }, "deleted snapshot ss1");
+
+diag "Destroying the transient domain";
+lives_ok(sub { $dom->destroy }, "destroyed domain");
+
+diag "Trying to undefine with a snapshot present";
+ok_error(sub { $dom->undefine }, Sys::Virt::Error::ERR_OPERATION_INVALID);
+
+diag "Deleting snapshot ss2";
+lives_ok(sub { $domss2->delete }, "deleted snapshot ss2");
+
+lives_ok(sub { $dom->undefine }, "undefined persistent 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