| 1 |
# -*- perl -*- |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 25; |
| 7 |
use XML::XPath; |
| 8 |
use XML::XPath::XMLParser; |
| 9 |
use Sys::Hostname; |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
use_ok('Sys::Virt'); |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
my $conn = Sys::Virt->new(uri => "test:///default"); |
| 17 |
|
| 18 |
isa_ok($conn, "Sys::Virt"); |
| 19 |
|
| 20 |
|
| 21 |
my $info = $conn->get_node_info(); |
| 22 |
|
| 23 |
is($info->{model}, "i686", "model"); |
| 24 |
is($info->{cpus}, 16, "cpus"); |
| 25 |
is($info->{mhz}, 1400, "mhz"); |
| 26 |
is($info->{sockets}, 2, "sockets"); |
| 27 |
is($info->{nodes}, 2, "nodes"); |
| 28 |
is($info->{cores}, 2, "cores"); |
| 29 |
is($info->{threads}, 2, "threads"); |
| 30 |
is($info->{memory}, 3145728, "memory"); |
| 31 |
|
| 32 |
|
| 33 |
my $caps = $conn->get_capabilities; |
| 34 |
|
| 35 |
my $xp = XML::XPath->new(xml => $caps); |
| 36 |
|
| 37 |
my $arch = $xp->find("string(/capabilities/host/cpu/arch)"); |
| 38 |
is($arch, "i686", "host"); |
| 39 |
|
| 40 |
|
| 41 |
my $guestos = $xp->find("string(/capabilities/guest[1]/os_type)"); |
| 42 |
is($guestos, "hvm", "os"); |
| 43 |
my $guestarch = $xp->find("string(/capabilities/guest[1]/arch/\@name)"); |
| 44 |
is($guestarch, "i686", "arch"); |
| 45 |
my $guestword = $xp->find("string(/capabilities/guest[1]/arch/wordsize)"); |
| 46 |
is($guestword, "32", "wordsize"); |
| 47 |
my $guesttype = $xp->find("string(/capabilities/guest[1]/arch/domain/\@type)"); |
| 48 |
is($guesttype, "test", "type"); |
| 49 |
my $guestpae = int($xp->find("count(/capabilities/guest[1]/features/pae)")); |
| 50 |
is($guestpae, 1, "pae"); |
| 51 |
my $guestnonpae = int($xp->find("count(/capabilities/guest[1]/features/nonpae)")); |
| 52 |
is($guestnonpae, 1, "nonpae"); |
| 53 |
|
| 54 |
my $ver = $conn->get_version(); |
| 55 |
my $major = $conn->get_major_version(); |
| 56 |
my $minor = $conn->get_minor_version(); |
| 57 |
my $micro = $conn->get_micro_version(); |
| 58 |
|
| 59 |
is(($ver - (int($ver % 1000000)))/1000000, $major, "major"); |
| 60 |
is((($ver - $major) - (($ver - $major) % 1000))/ 1000, $minor, "minor"); |
| 61 |
is(($ver - $major - $minor), $micro, "micro"); |
| 62 |
|
| 63 |
|
| 64 |
my $max = $conn->get_max_vcpus("linux"); |
| 65 |
is($max, 32, "max cpus"); |
| 66 |
|
| 67 |
|
| 68 |
SKIP: { |
| 69 |
skip "Too hard to figure out matchiing hostnames in test suite", 1; |
| 70 |
|
| 71 |
my $thishost = hostname(); |
| 72 |
my ($canonhost, $other) = gethostbyname($thishost); |
| 73 |
$canonhost = $thishost unless $canonhost; |
| 74 |
my $host = $conn->get_hostname(); |
| 75 |
is($host, $canonhost, "hostname"); |
| 76 |
} |
| 77 |
|
| 78 |
ok($conn->is_secure(), "connection is secure"); |
| 79 |
ok(!$conn->is_encrypted(), "connection is not encrypted"); |
| 80 |
|
| 81 |
my @models = $conn->get_cpu_model_names($info->{model}); |
| 82 |
|
| 83 |
ok($#models > -1, "got some cpu models"); |