Skip to content

Commit

Permalink
[UPC#441] Copy volumes checking target
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Nov 23, 2017
1 parent 01fffc4 commit 1eb635a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,15 @@ sub _copy_clone($self, %args) {
,id_owner => $user->id
,_vm => $self->_vm
);
my @volumes = $self->list_volumes;
my @copy_volumes = $copy->list_volumes;
for my $n (0 .. $#volumes) {
copy($volumes[$n],$copy_volumes[$n]) or die "$! $volumes[$n] $copy_volumes[$n]"
my @volumes = $self->list_volumes_target;
my @copy_volumes = $copy->list_volumes_target;

my %volumes = map { $_->[1] => $_->[0] } @volumes;
my %copy_volumes = map { $_->[1] => $_->[0] } @copy_volumes;
for my $target (keys %volumes) {
warn "$target:\n $volumes{$target}\n $copy_volumes{$target}\n";
copy($volumes{$target}, $copy_volumes{$target})
or die "$! $volumes{$target}, $copy_volumes{$target}"
}
return $copy;
}
Expand Down
24 changes: 20 additions & 4 deletions t/vm/c10_copy.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ my $FILE_CONFIG = 't/etc/ravada.conf';

##########################################################################3

sub add_volumes {
my ($base, $volumes) = @_;
$base->add_volume_swap(name => "vol_swap", size => 512 * 1024);
for my $n ( 1 .. $volumes ) {
$base->add_volume(name => "vol_$n", size => 512 * 1024);
}
}

sub test_copy_clone {
my $vm_name = shift;
my $volumes = shift;

my $base = create_domain($vm_name);

add_volumes($base, $volumes) if $volumes;

my $name_clone = new_domain_name();

my $clone = $base->clone(
Expand All @@ -32,7 +43,7 @@ sub test_copy_clone {
is($clone->is_base,0);
for ( $clone->list_volumes ) {
open my $out,'>',$_ or die $!;
print $out "hola\n";
print $out "hola $_\n";
close $out;
}

Expand All @@ -51,9 +62,11 @@ sub test_copy_clone {
my @copy_volumes = $copy->list_volumes();
my @clone_volumes = $clone->list_volumes();

for ( 0 .. $#copy_volumes ) {
isnt($copy_volumes[$_], $clone_volumes[$_]);
is(-s $copy_volumes[$_], -s $clone_volumes[$_],"[$vm_name] size of $copy_volumes[$_]");
for my $n ( 0 .. $#copy_volumes ) {
isnt($copy_volumes[$n], $clone_volumes[$n]);
my @stat_copy = stat($copy_volumes[$n]);
my @stat_clone = stat($clone_volumes[$n]);
is($stat_copy[7],$stat_clone[7],"[$vm_name] size of $copy_volumes[$n] ".($stat_copy[7])) or exit;

}
}
Expand All @@ -77,6 +90,9 @@ for my $vm_name ('Void', 'KVM') {
skip($msg,10) if !$vm;

test_copy_clone($vm_name);
test_copy_clone($vm_name,1);
test_copy_clone($vm_name,2);
test_copy_clone($vm_name,10);
}

}
Expand Down

0 comments on commit 1eb635a

Please sign in to comment.