s20_sysinfo.t 2.48 KB
Newer Older
Francesc Guasch's avatar
Francesc Guasch committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use warnings;
use strict;

use Carp qw(confess);
use Data::Dumper;
use IPC::Run3;
use Test::More;
use XML::LibXML;

use feature qw(signatures);
no warnings "experimental::signatures";

use lib 't/lib';
use Test::Ravada;

use_ok('Ravada');

our $XML = XML::LibXML->new();

###################################################################################3

Francesc Guasch's avatar
Francesc Guasch committed
22
sub test_sysinfo($domain, $domain_name=$domain->name) {
Francesc Guasch's avatar
Francesc Guasch committed
23
24
25
26
27
28
29
30

    my $doc = $XML->load_xml(string => $domain->domain->get_xml_description())
        or die "ERROR: $!\n";

    my $path_smbios = '/domain/os/smbios';
    my ($smbios) = $doc->findnodes($path_smbios);
    ok($smbios,"Expecting $path_smbios entry in XML");

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    SKIP: {
        my $sys_virt_version = $Sys::Virt::VERSION;
        my $req_sys_virt_version = '4.6';
        $sys_virt_version =~ s/(\d+\.\d+).*/$1/;
        skip("Sys::Virt Version > than $req_sys_virt_version required"
                    .", found $sys_virt_version",3)
            if $sys_virt_version < $req_sys_virt_version;
        my $path_oemstrings='/domain/sysinfo/oemStrings';
        my ($oemstrings) = $doc->findnodes($path_oemstrings);
        ok($oemstrings,"Expecting $path_oemstrings entry in XML ") or return;

        my $hostname;
        for my $entry ($oemstrings->findnodes('entry')) {
            $hostname = $entry if $entry->textContent =~ /^hostname/;
        }
        ok($hostname,"Expecting a hostname entry in ".$oemstrings->toString) and do {
            my $hostname_text = $hostname->textContent();
            like($hostname_text, qr{^hostname: $domain_name$});
        };
Francesc Guasch's avatar
Francesc Guasch committed
50
51
52
53
54
    }
}

###################################################################################3

55
56
57
58
59
60
if ($>)  {
    diag("SKIPPED: Test must run as root");
    done_testing();
    exit;
}

Francesc Guasch's avatar
Francesc Guasch committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
init();
clean();

my $vm_name = 'KVM';
my $vm = rvd_back->search_vm($vm_name);

SKIP: {

    my $msg = "SKIPPED: No virtual managers found";
    if ($vm && $vm_name =~ /kvm/i && $>) {
        $msg = "SKIPPED: Test must run as root";
        $vm = undef;
    }

    skip($msg,10)   if !$vm;

    my $domain = create_domain($vm);
    test_sysinfo($domain);

Francesc Guasch's avatar
Francesc Guasch committed
80
81
82
83
84
85
86
87
    my $rename = new_domain_name;
    $domain->rename(name => $rename, user => user_admin);
    test_sysinfo($domain, $rename);

    $domain = Ravada::Domain->open($domain->id);
    test_sysinfo($domain, $rename);

    my $clone_name = new_domain_name;
Francesc Guasch's avatar
Francesc Guasch committed
88
    my $clone = $domain->clone(
Francesc Guasch's avatar
Francesc Guasch committed
89
         name => $clone_name
Francesc Guasch's avatar
Francesc Guasch committed
90
91
        ,user => user_admin
    );
Francesc Guasch's avatar
Francesc Guasch committed
92
    test_sysinfo($clone, $clone_name);
Francesc Guasch's avatar
Francesc Guasch committed
93
94
95

}

96
end();
Francesc Guasch's avatar
Francesc Guasch committed
97
done_testing();