a20_xml.t 2.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
use warnings;
use strict;

use Carp qw(confess);
use Data::Dumper;
use IPC::Run3;
use Test::More;

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

use_ok('Ravada');

Francesc Guasch's avatar
Francesc Guasch committed
14
15
my $RVD_BACK = rvd_back();
my $RVD_FRONT= rvd_front();
16

17
my @VMS = vm_names();
18
my $USER = create_user("foo","bar", 1);
19
20
21
22
23
24
25
26
27
28
29
30

sub test_create_domain {
    my $vm_name = shift;

    my $vm = rvd_back->search_vm($vm_name);
    ok($vm,"I can't find VM $vm_name") or return;

    my $name = new_domain_name();

    my $domain;
    eval { $domain = $vm->create_domain(name => $name
                    , id_owner => $USER->id
Francesc Guasch's avatar
Francesc Guasch committed
31
                    , disk => 1024 * 1024
32
                    , arg_create_dom($vm_name))
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    };

    ok($domain,"No domain $name created with ".ref($vm)." ".($@ or '')) or exit;
    ok($domain->name
        && $domain->name eq $name,"Expecting domain name '$name' , got "
        .($domain->name or '<UNDEF>')
        ." for VM $vm_name"
    );

    return $domain;

}


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

49
50
51
52
53
54
if ($>)  {
    diag("SKIPPED: Test must run as root");
    done_testing();
    exit;
}

55
56
clean();

57
my $vm_name = 'KVM';
58
59
60
61
62
63
64
65
66
67
68
69
70
my $vm = rvd_back->search_vm($vm_name);

SKIP: {

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

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

    my $domain = test_create_domain($vm_name);
71
    $domain->is_public(1);
72
    my $clone = $domain->clone(user => user_admin , name => new_domain_name());
73
74
75
76
77

    ok($clone);
    my @volumes = $clone->list_volumes();
    is(scalar @volumes,1);

78
    $domain->add_volume( name => $domain->name.'.vdb' , size => 1000 *1024);
79
80

    my @volumes_domain = $domain->list_volumes();
Francesc Guasch's avatar
Francesc Guasch committed
81
    is(scalar @volumes_domain, 3);
82
83
84
85
86
87
88
89
90
91
92

    my $clone2;
    eval  { $clone2 = $domain->clone(user => $USER, name => new_domain_name()) };
    is($@,'');
    ok($clone2,"Expecting a clone , got ".($clone2 or 'UNDEF'));

    if ($clone2) {
        my @volumes_clone2= $clone2->list_volumes();
        is(scalar @volumes_clone2, 1);
    }

93
94
95
    $clone->remove( user_admin );
    $clone2->remove( user_admin );
    $domain->remove_base( user_admin );
96
97

    my $clone3;
98
    eval  { $clone3 = $domain->clone(user => user_admin , name => new_domain_name()) };
99
100
101
102
103
104
105
106
107
108
109
    is($@,'');
    ok($clone3,"Expecting a clone , got ".($clone3 or 'UNDEF'));

    if ($clone3) {
        my @volumes_clone3= $clone3->list_volumes();
        is(scalar @volumes_clone3, 2);
    }


}

110
end();
111
112
113

done_testing();