30_start_stop.t 2.19 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
use warnings;
use strict;

use Carp qw(confess);
use Data::Dumper;
use Digest::MD5;
use Test::More;

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

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


##################################################################
17
18
19
20
21
22
23
24
25
26
27
if ($>)  {
    my $msg = "SKIPPED: Test must run as root";
    diag($msg);
    SKIP: {
        skip($msg,10);
    }
    done_testing();
    exit;
}

init();
Francesc Guasch's avatar
Francesc Guasch committed
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

for my $vm_name ( 'KVM') {
    my $vm;
    eval { $vm = rvd_back->search_vm($vm_name) };

    SKIP: {

        my $msg = "SKIPPED: $vm_name virtual manager not found ".($@ or '');
        my $REMOTE_CONFIG = remote_config($vm_name);
        if (!keys %$REMOTE_CONFIG) {
            my $msg = "skipped, missing the remote configuration for $vm_name in the file "
                .$Test::Ravada::FILE_CONFIG_REMOTE;
            diag($msg);
            skip($msg,10);
        }

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

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

        diag("Testing WOL node in $vm_name");
        my $node = remote_node($vm_name)  or next;
        for ( 1 .. 60 ) {
            diag("[$_] Waiting for ".$node->name." to answer ping") if $ENV{TERM};
            last if $node->ping;
            sleep 1;
        }
59
        like($node->_data('mac'),qr([\da-f][\da-f]:[\da-f][\da-f]:[\da-f][\da-f]:[\da-f][\da-f]:[\da-f][\da-f]:)) or next;
Francesc Guasch's avatar
Francesc Guasch committed
60
61
62
63
64

        is( $node->is_active, 1 );
        $node->shutdown();
        for ( 1 .. 60 ) {
            sleep 1;
65
            last if !$node->_ping_nocache();
Francesc Guasch's avatar
Francesc Guasch committed
66
        }
67
68
69
        my $node2 = Ravada::VM->open(id => $node->id);
        is( $node2->_ping_nocache(), 0 );
        is( $node2->is_active(1), 0 );
Francesc Guasch's avatar
Francesc Guasch committed
70
71
72

        # it actually dows nothing on virtual machines, just check it won't fail
        eval { $node->_wake_on_lan() };
73
        is($@,'',"Expecting no error on wake on lan");
Francesc Guasch's avatar
Francesc Guasch committed
74
75
76
77
78
79
80
81
82
83
84
#        KVM testing machines can't Wake On LAN
#        sleep 1;
#        $node->start();
#        for ( 1 .. 60 ) {
#            last if $node->is_active;
#            sleep 1;
#        }
#        is( $node->is_active, 1 );

    }
}
85
end();
Francesc Guasch's avatar
Francesc Guasch committed
86
done_testing();