File: Add-tests-for-snapshot-operations-on-persistent-doma.patch

package info (click to toggle)
libvirt-tck 0.1.0~2.git890d1c-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,128 kB
  • sloc: perl: 2,885; sh: 1,180; xml: 992; makefile: 6
file content (171 lines) | stat: -rw-r--r-- 6,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Sun, 30 Oct 2011 14:54:28 +0100
Subject: Add tests for snapshot operations on persistent domains

---
 Build.PL                                  |    2 +-
 perl-Sys-Virt-TCK.spec.PL                 |    2 +-
 scripts/domain/400-snapshots-persistent.t |  127 +++++++++++++++++++++++++++++
 3 files changed, 129 insertions(+), 2 deletions(-)
 create mode 100644 scripts/domain/400-snapshots-persistent.t

diff --git a/Build.PL b/Build.PL
index e682c3a..858c73b 100644
--- a/Build.PL
+++ b/Build.PL
@@ -86,7 +86,7 @@ my $b = $class->new(
 	'Test::Builder' => 0,
 	'Test::More' => 0,
 	'Sub::Uplevel' => 0,
-	'Sys::Virt' => '0.2.0',
+	'Sys::Virt' => '0.9.5',
 	'XML::Twig' => 0,
 	'XML::Writer' => 0,
 	'XML::XPath' => 0,
diff --git a/perl-Sys-Virt-TCK.spec.PL b/perl-Sys-Virt-TCK.spec.PL
index 6986ea8..bf2ae46 100644
--- a/perl-Sys-Virt-TCK.spec.PL
+++ b/perl-Sys-Virt-TCK.spec.PL
@@ -64,7 +64,7 @@ BuildRequires: perl(TAP::Harness::Archive)
 BuildRequires: perl(Test::Builder)
 BuildRequires: perl(Test::More)
 BuildRequires: perl(Sub::Uplevel)
-BuildRequires: perl(Sys::Virt) >= 0.2.0
+BuildRequires: perl(Sys::Virt) >= 0.9.5
 BuildRequires: perl(XML::Twig)
 BuildRequires: perl(XML::Writer)
 # RPM autoprovides misses these 3
diff --git a/scripts/domain/400-snapshots-persistent.t b/scripts/domain/400-snapshots-persistent.t
new file mode 100644
index 0000000..141d314
--- /dev/null
+++ b/scripts/domain/400-snapshots-persistent.t
@@ -0,0 +1,127 @@
+# -*- perl -*-
+#
+# Copyright (C) 2011 Univention GmbH
+# Author: Guido Guenther <agx@sigxcpu.org>
+#
+# 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/400-snapshot.t - Check snapshot operations for persistent domains
+
+=head1 DESCRIPTION
+
+Check if snapshots can be created and deleted. Check if a snapshot gets
+associated with the right vm metadata when reverting snapshots.
+
+=cut
+
+use strict;
+use warnings;
+use Test::More tests => 23;
+
+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; }
+
+SKIP: {
+    my ($pool, $vol, $dom, $snap1, $snap2);
+    my $minmem = 64 * 1024;
+    my $maxmem = $minmem * 2;
+    my $snapshots = 0;
+
+    my $poolxml = $tck->generic_pool("dir")
+                      ->mode("0755")->as_xml;
+
+    diag "Defining transient storage pool $poolxml";
+    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.img", "qcow2", 1024*1024*50)
+                     ->allocation(0)->as_xml;
+    ok_volume(sub { $vol = $pool->create_volume($volxml) }, "creating qcow2 volume $volxml");
+    my $pathvol = xpath($vol, "string(/volume/target/path)");
+
+    my $gd = $tck->generic_domain("tck")
+                 ->memory($minmem);
+    $gd->rmdisk;
+    my $domxml = $gd->disk(format => { name => "qemu", type => "qcow2" },
+                           type => "file",
+                           src => $pathvol,
+                           dst => "vda")->as_xml;
+
+    ok_domain(sub { $dom = $conn->define_domain($domxml) }, "defined persistent domain");
+    lives_ok(sub {$dom->create() }, "started domain");
+
+    my $currmem = int(xpath($dom, "number(/domain/currentMemory)"));
+    is($currmem, $minmem, "XML description has memory set to $minmem");
+
+    my $snap1xml = <<EOF;
+<domainsnapshot>
+   <name>Snapshot1</name>
+   <description>First snapshot</description>
+</domainsnapshot>
+EOF
+    diag "Create first snapshot";
+    eval { $snap1 = $dom->create_snapshot($snap1xml); };
+    skip "Snapshots not implemented", 16 if $@ && err_not_implemented($@);
+    ok(!$@, "Snapshot created");
+    die $@ if $@;
+    $snapshots++;
+
+    lives_ok( sub { $dom->destroy() }, "Domain destroyed");
+    lives_ok(sub { $dom->set_max_memory($maxmem) }, "Doubled memory to $maxmem");
+    lives_ok(sub {$dom->create() }, "started domain");
+
+    $currmem = int(xpath($dom, "number(/domain/currentMemory)"));
+    is($currmem, $maxmem, "XML description has memory set to $maxmem");
+
+    my $snap2xml = <<EOF;
+<domainsnapshot>
+   <name>Snapshot2</name>
+   <description>Second snapshot</description>
+</domainsnapshot>
+EOF
+    ok_domain_snapshot( sub { $snap2 = $dom->create_snapshot($snap2xml) }, "create second snapshot $snap2xml");
+    $snapshots++;
+    is($dom->num_of_snapshots(), $snapshots, "We have $snapshots snapshots");
+
+    # Reverting to the same vm configuration is o.k.
+    lives_ok( sub { $snap2->revert_to() }, "Reverting to snapshot snapshot 2");
+
+    # Reverting to another vm configuration would involve killing qemu so this
+    # is rejected:
+    ok_error( sub { $snap1->revert_to() }, "Reverting to changed vm configuration is risky",
+                    Sys::Virt::Error::ERR_SNAPSHOT_REVERT_RISKY);
+
+    # Reverting to another vm configiguration while shut off is o.k.:
+    lives_ok( sub { $dom->destroy() }, "Domain destroyed");
+    lives_ok( sub { $snap1->revert_to() }, "Reverting to snapshot snapshot 1 with vm shutoff");
+    $currmem = int(xpath($dom, "number(/domain/currentMemory)"));
+    is($currmem, $minmem, "Memory is $minmem");
+
+    is($dom->num_of_snapshots(), $snapshots, "We have $snapshots snapshots");
+
+    $snap1->delete();
+    $snapshots--;
+    is($dom->num_of_snapshots(), $snapshots, "We have $snapshots snapshots");
+
+    $snap2->delete();
+    $snapshots--;
+    is($dom->num_of_snapshots(), $snapshots, "We have $snapshots snapshots");
+    is($snapshots, 0, "All snapshots are gone");
+}
--