35_request_start.t 2.99 KB
Newer Older
Francesc Guasch's avatar
Francesc Guasch committed
1
2
3
4
5
6
7
8
9
10
11
use warnings;
use strict;

use Test::More;
use Test::SQL::Data;

use_ok('Ravada');
use_ok('Ravada::Request');

my $test = Test::SQL::Data->new(config => 't/etc/ravada.conf');

12
13
14
my $ravada;

eval { $ravada = Ravada->new(connector => $test->connector) };
Francesc Guasch's avatar
Francesc Guasch committed
15
16
17
18
19
20
21
22
23
24

my ($DOMAIN_NAME) = $0 =~ m{.*/(.*)\.};

sub test_request_start {
}

sub test_remove_domain {
    my $name = shift;

    my $domain = $name if ref($name);
25
    $domain = $ravada->search_domain($name,1);
Francesc Guasch's avatar
Francesc Guasch committed
26

27
28
    my $disks_not_removed = 0;

Francesc Guasch's avatar
Francesc Guasch committed
29
30
    if ($domain) {
        diag("Removing domain $name");
31
32
33
34
35
        my @disks = $domain->list_disks();
        eval { 
            $domain->remove();
        };
        ok(!$@ , "Error removing domain $name ".ref($domain).": $@") or exit;
Francesc Guasch's avatar
Francesc Guasch committed
36
37
38
39

        ok(! -e $domain->file_base_img ,"Image file was not removed "
                    . $domain->file_base_img )
                if  $domain->file_base_img;
40
41
42
        for (@disks) {
            ok(!-e $_,"Disk $_ should be removed") or $disks_not_removed++;
        }
Francesc Guasch's avatar
Francesc Guasch committed
43
44

    }
45
    $domain = $ravada->search_domain($name,1);
Francesc Guasch's avatar
Francesc Guasch committed
46
    ok(!$domain, "I can't remove old domain $name") or exit;
47
    ok(!$disks_not_removed,"$disks_not_removed disks not removed from domain $name");
Francesc Guasch's avatar
Francesc Guasch committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
}

sub test_new_domain {
    my $name = shift;

    test_remove_domain($name);

    diag("Creating domain $name");
    my $domain = $ravada->create_domain(name => $name, id_iso => 1, active => 0);

    ok($domain,"Domain not created");

    return $domain;
}


sub test_start {
    my ($name) = $0 =~ m{.*/(.*)\.};
    test_remove_domain($name);

    test_new_domain($name);

    my $domain = $ravada->search_domain($name);
    ok(!$domain->is_active,"Domain $name should be inactive") or return;


    my $req = Ravada::Request->start_domain(
        "does not exists"
    );
    $ravada->process_requests();

    ok($req->status eq 'done', "Expecting status done, got ".$req->status);
    ok($req->error && $req->error =~ /unknown/i
            ,"Expecting unknown domain error , got "
                .($req->error or '<NULL>'));
    $req = undef;

Francesc Guasch's avatar
Francesc Guasch committed
85
86
87
88
    #####################################################################3
    #
    # start

Francesc Guasch's avatar
Francesc Guasch committed
89
90
91
92
93
94
95
96
97
98
    my $req2 = Ravada::Request->start_domain($name);
    $ravada->process_requests();

    ok($req2->status eq 'done');

    ok($domain->is_active);

    my $domain2 = $ravada->search_domain($name);
    ok($domain2->is_active);

Francesc Guasch's avatar
Francesc Guasch committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    $req2 = undef;

    #####################################################################3
    #
    # stop

    my $req3 = Ravada::Request->shutdown_domain($name);
    $ravada->process_requests();
    ok($req3->status eq 'done');

    ok(!$domain->is_active);

    my $domain3 = $ravada->search_domain($name);
    ok(!$domain3->is_active);

Francesc Guasch's avatar
Francesc Guasch committed
114
115
116
117
118
}

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

119
120
my $vmm;

Francesc Guasch's avatar
Francesc Guasch committed
121
122
123
124
eval { 
    $vmm = $ravada->search_vm('kvm');
    $vmm = $ravada->search_vm('lxc') if !$vmm;
} if $ravada;
125
126
127
128
129
130
131
132

SKIP: {
    my $msg = "SKIPPED: No virtual managers found";
    diag($msg) if !$vmm;
    skip($msg,10) if !$vmm;

    test_start();
};
Francesc Guasch's avatar
Francesc Guasch committed
133
134
done_testing();