Skip to content

Commit

Permalink
[UPC#441] copy a clone raw
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Nov 20, 2017
1 parent fbae151 commit 01fffc4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
23 changes: 23 additions & 0 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Ravada::Domain - Domains ( Virtual Machines ) library for Ravada

use Carp qw(carp confess croak cluck);
use Data::Dumper;
use File::Copy;
use Hash::Util qw(lock_hash);
use Image::Magick;
use JSON::XS;
Expand Down Expand Up @@ -992,6 +993,8 @@ sub clone {
my $name = $args{name} or confess "ERROR: Missing domain cloned name";
confess "ERROR: Missing request user" if !$args{user};

return $self->_copy_clone(@_) if $self->id_base();

my $uid = $args{user}->id;

$self->prepare_base($args{user}) if !$self->is_base();
Expand All @@ -1008,6 +1011,26 @@ sub clone {
return $clone;
}

sub _copy_clone($self, %args) {
my $name = delete $args{name} or confess "ERROR: Missing name";
my $user = delete $args{user} or confess "ERROR: Missing user";

my $base = Ravada::Domain->open($self->id_base);

my $copy = $self->_vm->create_domain(
name => $name
,id_base => $base->id
,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]"
}
return $copy;
}

sub _post_pause {
my $self = shift;
my $user = shift;
Expand Down
42 changes: 40 additions & 2 deletions t/vm/c10_copy.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,45 @@ my $FILE_CONFIG = 't/etc/ravada.conf';

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

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

my $base = create_domain($vm_name);

my $name_clone = new_domain_name();

my $clone = $base->clone(
name => $name_clone
,user => user_admin
);

is($clone->is_base,0);
for ( $clone->list_volumes ) {
open my $out,'>',$_ or die $!;
print $out "hola\n";
close $out;
}

my $name_copy = new_domain_name();
my $copy = $clone->clone(
name => $name_copy
,user => user_admin
);
is($clone->is_base,0);
is($copy->is_base,0);

is($copy->id_base, $base->id);

is(scalar($copy->list_volumes),scalar($clone->list_volumes));

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[$_]");

}
}

##########################################################################3
Expand All @@ -38,7 +76,7 @@ for my $vm_name ('Void', 'KVM') {

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

test_copy($vm_name);
test_copy_clone($vm_name);
}

}
Expand Down

0 comments on commit 01fffc4

Please sign in to comment.