Commit 1a904515 authored by JanFontanet's avatar JanFontanet
Browse files

[#218]Domain/KVM Methods added and tested

parent 1634c074
......@@ -1616,6 +1616,37 @@ sub _remove_controller_usb($self, $index) {
die "ERROR: USB controller ".($index+1)." not removed, only ".($ind)." found\n";
}
sub _generate_snap_template($name) {
return "<domainsnapshot>
<name>$name</name>
</domainsnapshot>";
}
sub create_snapshot($self, $name) {
$self->domain->create_snapshot(_generate_snap_template($name));
return;
}
sub delete_snapshot($self, $name) {
my $snap;
eval{ $snap = $self->domain->get_snapshot_by_name($name) };
$snap->delete();
return;
}
sub list_snapshots($self) {
my @snaps = $self->domain->list_all_snapshots();
return @snaps;
}
sub revert_to_snapshot($self, $name) {
my $snap;
eval{ $snap = $self->domain->get_snapshot_by_name($name) };
die "Not snapshot with name $name" if $@;
$snap->revert_to();
return;
}
=head2 pre_remove
Code to run before removing the domain. It can be implemented in each domain.
......
......@@ -16,7 +16,8 @@ init($test->connector);
clean();
###################################################################################
sub test_snapshots {
sub test_snapshots_pre {
my $vm = shift;
my $domain = create_domain($vm->type);
ok($domain);
......@@ -34,6 +35,27 @@ sub test_snapshots {
ok(!$@, "Deleted Snapshot");
}
sub test_snapshots_post {
my $vm = shift;
my $domain = create_domain($vm->type);
ok($domain);
$domain->start(user_admin) if !$domain->is_active();
my $sname = "test_snap";
eval{ $domain->create_snapshot($sname) };
ok(!$@);
my @snaps = $domain->list_snapshots();
ok(scalar @snaps > 0);
eval{ $domain->delete_snapshot($sname) };
ok(!$@);
eval { $domain->delete_snapshot('fake_name') };
ok($@);
}
###################################################################################
......@@ -55,7 +77,7 @@ for my $vm_name ( q(KVM) ) {
diag("Testing free mem on $vm_name");
test_snapshots($vm);
test_snapshots_post($vm);
}
}
clean();
......
......@@ -230,6 +230,9 @@ sub _remove_old_domains_kvm {
for my $domain ( $vm->vm->list_all_domains ) {
next if $domain->get_name !~ /^$base_name/;
my $domain_name = $domain->get_name;
for my $snap ($domain->list_snapshots){
$snap->delete();
}
eval {
$domain->shutdown();
sleep 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment