30_disable_node.t 2.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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');
init();

##################################################################################

sub test_disable_node($vm, $node) {
    my $base = create_domain($vm);
    $base->prepare_base(user_admin);
    $base->set_base_vm(user => user_admin, node => $node);

    my $clone = $base->clone(user => user_admin, name => new_domain_name);
    $clone->migrate($node);
    $clone->start(user_admin);
Francesc Guasch's avatar
Francesc Guasch committed
29
30
31
    sleep 2;
    for (1 .. 10 ) {
        last if$clone->is_active;
32
        sleep 1;
Francesc Guasch's avatar
Francesc Guasch committed
33
34
    }
    is($clone->is_active,1,"Expecting clone active") or return;
35

36
    $node->enabled(0);
37
38
39

    is($clone->_vm->name, $node->name);

Francesc Guasch's avatar
Francesc Guasch committed
40
    my $timeout = 4;
41
42
    my $req = Ravada::Request->shutdown_domain(
                uid => user_admin->id
Francesc Guasch's avatar
Francesc Guasch committed
43
           ,timeout => $timeout
44
45
46
47
48
49
        , id_domain => $clone->id
    );
    rvd_back->_process_requests_dont_fork();
    is($req->status,'done');
    is($req->error,'');

50
    for ( 0 .. $timeout * 2 ) {
51
52
53
54
        last if !$clone->is_active;
        sleep 1;
        rvd_back->_process_requests_dont_fork();
    }
55
    is($clone->is_active, 0,$clone->type." ".$clone->name ) or exit;
56
57
58
59
60
61
62
63
64
65
    if ( $vm->type eq 'KVM' ) {
        is($clone->domain->is_active, 0);
    } else {
        diag("TODO check internal is active ".$vm->type);
    }
    $clone->remove(user_admin);
    $base->remove(user_admin);
}

##################################################################################
66
67
68
69
70
71
if ($>)  {
    diag("SKIPPED: Test must run as root");
    done_testing();
    exit;
}

72
73
74
75
clean();

$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;

76
for my $vm_name ( vm_names() ) {
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    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 && $>) {
            $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;
        clean_remote_node($node);

        ok($node->vm,"[$vm_name] expecting a VM inside the node") or do {
            remove_node($node);
            next;
        };
        is($node->is_local,0,"Expecting ".$node->name." ".$node->ip." is remote" ) or BAIL_OUT();
        test_disable_node($vm,$node);

        NEXT:
        clean_remote_node($node);
        remove_node($node);
    }

}

END: {
118
    end();
119
120
    done_testing();
}