n20_nodes_hibernate.t 2.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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);

15
init();
16
17

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

    start_node($node);
25
    is($node->is_active,1) or exit;
26
    is($node->enabled,1) or exit;
27
28
29
30

    my $domain = create_domain($node->type);
    $domain->prepare_base(user_admin);
    $domain->migrate_base(user => user_admin, node => $node);
31
    is($domain->base_in_vm($node->id),1);
32
33
34
35
36
37

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

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

    $action->($clone);

    shutdown_node($node);
Francesc Guasch's avatar
Francesc Guasch committed
46
47
48
    $node->_clean_cache();

    $clone = Ravada::Domain->open($clone->id);
49
50

    eval { $clone->start(user_admin) };
Francesc Guasch's avatar
Francesc Guasch committed
51
    is(''.$@,'');
52
53
    is($clone->is_active, 1, "Expecting clone ".$clone->name." active");
    is($clone->is_local, 1,"Expecting clone ".$clone->name." local");
Francesc Guasch's avatar
Francesc Guasch committed
54
    is($domain->base_in_vm($node->id),1);
55

56
    $node->_clean_cache();
57
    start_node($node);
58
59
    is($node->is_active,1);
    wait_request(debug => 0);
60

61
62
63
64
65
66
    is($domain->_vm->is_active, 1);

    eval { $clone->shutdown_now(user_admin) };
    is($@,'');
    eval { $clone->migrate($node) };
    is($@,'');
67
68
69
70
71

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

    $clone->remove(user_admin);
72
73
74
75

    $domain = Ravada::Domain->open($domain->id);
    eval { $domain->remove(user_admin) };
    is(''.$@,'');
76
77
78
79
80
81
82
83
84
85
86
87
}

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

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

clean();
88
clean_remote() if !$>;
89

90
for my $vm_name ( vm_names() ) {
91
92
93
94
95
96
    my $vm;
    eval { $vm = rvd_back->search_vm($vm_name) };

    SKIP: {

        my $msg = "SKIPPED: $vm_name virtual manager not found ".($@ or '');
97
        if ($vm && $>) {
98
99
100
101
102
103
104
105
106
107
            $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;

108
109
        test_node_down($node, \&_shutdown_domain, 'shutdown');
        test_node_down($node, \&_hibernate_domain, 'hibernate');
110
111
112
113
114
115
116
117

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

118
end();
119
done_testing();