[libvirt] [PATCH][TCK] Add new case for domain suspend/resume

Kyla Zhang weizhan at redhat.com
Thu Aug 9 12:11:38 UTC 2012


This case tests the domain suspend and resume, and domain info
checking include state, control and os type.
---
 scripts/domain/140-transient-suspend-resume.t |   91 +++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 scripts/domain/140-transient-suspend-resume.t

diff --git a/scripts/domain/140-transient-suspend-resume.t b/scripts/domain/140-transient-suspend-resume.t
new file mode 100644
index 0000000..a1c6f91
--- /dev/null
+++ b/scripts/domain/140-transient-suspend-resume.t
@@ -0,0 +1,91 @@
+# -*- perl -*-
+#
+# Copyright (C) 2012 Red Hat, Inc.
+# Copyright (C) 2012 Kyla Zhang <weizhan at redhat.com>
+# 
+# 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/130-transient-suspend-resume.t - Transient domain suspend/resume
+
+=head1 DESCRIPTION
+
+The test case validates that it is possible to pause and resume transient
+domain without error.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 14;
+
+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; }
+
+# Create a new transient domain and check status
+my $xml = $tck->generic_domain("tck")->as_xml;
+
+diag "Creating a new transient domain";
+my $dom;
+ok_domain(sub { $dom = $conn->create_domain($xml) }, "created transient domain object");
+
+diag "Get domain os type";
+my $os_type = xpath($dom, "string(/domain/os/type)");
+is($dom->get_os_type(), $os_type, "domain os type is $os_type");
+
+diag "Check domain state and reason";
+my($state, $reason)=$dom->get_state();
+is($state, Sys::Virt::Domain::STATE_RUNNING, "domain state is running");
+is($reason, Sys::Virt::Domain::STATE_RUNNING_BOOTED, "domain is running after being booted");
+
+diag "Get domain control info";
+is($dom->get_control_info->{state}, Sys::Virt::Domain::CONTROL_OK, "domain control info is ok");
+
+# Do suspend/resume and check status
+diag "Suspend domain";
+lives_ok(sub { $dom->suspend() }, "domain has been suspended");
+
+diag "Get domain state and reason";
+($state, $reason)=$dom->get_state();
+is($state, Sys::Virt::Domain::STATE_PAUSED, "domain state is paused");
+is($reason, Sys::Virt::Domain::STATE_PAUSED_USER, "domain is paused at admin request");
+
+diag "Get domain control info";
+is($dom->get_control_info->{state}, Sys::Virt::Domain::CONTROL_OK, "domain control info is ok");
+
+diag "Resume domain";
+lives_ok( sub { $dom->resume() }, "domain has been resumed");
+
+diag "Get domain state and reason";
+($state, $reason)=$dom->get_state();
+is($state, Sys::Virt::Domain::STATE_RUNNING, "domain state is running");
+is($reason, Sys::Virt::Domain::STATE_RUNNING_UNPAUSED, "domain is running after a resume");
+
+diag "Get domain control info";
+is($dom->get_control_info->{state}, Sys::Virt::Domain::CONTROL_OK, "domain control info is ok");
+
+# Destroy domain
+diag "Destroying the transient domain";
+$dom->destroy;
+
+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);
+
+# end
-- 
1.7.1




More information about the libvir-list mailing list