n20_nodes_hibernate.t 2.62 KB
Newer Older
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);

use_ok('Ravada');

17
init();
18
19

#######################################################################
20
21
22
sub test_node_down($node, $action, $action_name) {
    diag("Starting domain in remote node ".$node->type."."
        ." Then $action_name domain, down remote node and"
23
24
25
26
        ." check if domain starts in local node."
        );

    start_node($node);
27
28
    is($node->is_active,1) or exit;
    is($node->is_enabled,1) or exit;
29
30
31
32
33
34
35
36
37
38

    my $domain = create_domain($node->type);
    $domain->prepare_base(user_admin);
    $domain->migrate_base(user => user_admin, node => $node);

    my $clone = $domain->clone(
         user => user_admin
        ,name => new_domain_name
    );
    $clone->migrate($node);
39
    is($clone->is_local,0 );
40

41
    $clone->start(user => user_admin, id_vm => $node->id);
42
43
44
45
46
47
48
49
    is($clone->is_local,0 );

    $action->($clone);

    shutdown_node($node);

    eval { $clone->start(user_admin) };
    is($@,'');
50
51
    is($clone->is_active, 1, "Expecting clone ".$clone->name." active");
    is($clone->is_local, 1,"Expecting clone ".$clone->name." local");
52
53
54

    start_node($node);

55
56
57
58
59
60
    is($domain->_vm->is_active, 1);

    eval { $clone->shutdown_now(user_admin) };
    is($@,'');
    eval { $clone->migrate($node) };
    is($@,'');
61
62
63
64
65

    is($clone->is_local, 0);
    is($clone->_vm->id, $node->id);

    $clone->remove(user_admin);
66
67
68
69

    $domain = Ravada::Domain->open($domain->id);
    eval { $domain->remove(user_admin) };
    is(''.$@,'');
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
}

sub _shutdown_domain($domain) {
    $domain->shutdown_now(user_admin);
}

sub _hibernate_domain($domain) {
    $domain->hibernate(user_admin);
}
#######################################################################

clean();
clean_remote();

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

    SKIP: {

        my $msg = "SKIPPED: $vm_name virtual manager not found ".($@ or '');
91
        if ($vm && $>) {
92
93
94
95
96
97
98
99
100
101
            $msg = "SKIPPED: Test must run as root";
            $vm = undef;
        }

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

        diag("Testing remote node in $vm_name");
        my $node = remote_node($vm_name)  or next;

102
103
        test_node_down($node, \&_shutdown_domain, 'shutdown');
        test_node_down($node, \&_hibernate_domain, 'hibernate');
104
105
106
107
108
109
110
111
112
113
114

        start_node($node);
        clean_remote_node($node);
        clean_remote_node($vm);
        remove_node($node);
    }
}

clean();
clean_remote();
done_testing();