Skip to content

Commit

Permalink
Merge branch 'feat/bundle' of github.com:UPC/ravada into feat/bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Feb 8, 2024
2 parents 929eee1 + 6f5218b commit dabbc8b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,7 @@ sub _req_method {
,pause => \&_cmd_pause
,create => \&_cmd_create
,remove => \&_cmd_remove
,remove_domain => \&_cmd_remove
,remove_clones => \&_cmd_remove_clones
,restore_domain => \&_cmd_restore_domain
,resume => \&_cmd_resume
Expand Down
15 changes: 9 additions & 6 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,9 @@ sub _search_already_started($self, $fast = 0) {
$sth->execute($self->_vm->type);
my %started;
while (my ($id) = $sth->fetchrow) {
my $vm = Ravada::VM->open($id);
next if !$vm->enabled;
my $vm;
eval { $vm = Ravada::VM->open($id) };
next if !$vm || !$vm->enabled;

my $vm_active;
eval {
Expand All @@ -539,7 +540,7 @@ sub _search_already_started($self, $fast = 0) {
my $error = $@;
if ($error) {
warn $error;
$vm->enabled(0) if !$vm->is_local;
$vm->enabled(0) if !$vm->is_local && !$vm->ping;
next;
}
next if !$vm_active;
Expand Down Expand Up @@ -2406,13 +2407,15 @@ sub _remove_domain_cascade($self,$user, $cascade = 1) {
next if $instance->{id_vm} == $self->_vm->id;
my $vm;
eval { $vm = Ravada::VM->open($instance->{id_vm}) };
die $@ if $@ && $@ !~ /I can't find VM/i;
next if !$vm || !$vm->is_active;
die $@ if $@ && $@ !~ /I can't find VM ||libvirt error code: 38,/i;
my $domain;
$@ = '';
eval { $domain = $vm->search_domain($domain_name) } if $vm;
warn $@ if $@;
$domain->remove($user, $cascade) if $domain;
eval {
$domain->remove($user, $cascade) if $domain;
};
warn $@ if $@;
$sth_delete->execute($instance->{id});
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Ravada/Domain/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@ sub list_volumes_info($self, $attribute=undef, $value=undef) {
} else {
$dev->{driver}->{type} = 'void';
}
$dev->{storage_pool} = $self->_vm->_find_storage_pool($dev->{file});
$dev->{storage_pool} = $self->_vm->_find_storage_pool($dev->{file})
if $dev->{file};

my $vol = Ravada::Volume->new(
file => $dev->{file}
,info => $dev
Expand Down
2 changes: 1 addition & 1 deletion script/rvd_front
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ get '/machine/view/(:id).(:type)' => sub {
return view_machine($c) if $USER->is_admin
|| $USER->can_view_all;

if ( $domain->id_owner == $USER->id ) {
if ( $domain->id_owner == $USER->id || $USER->can_start_machine($domain) ) {
if ( $domain->id_base) {
my $base = Ravada::Front::Domain->open($domain->id_base);
if ($base->is_public || $base->show_clones()) {
Expand Down
2 changes: 1 addition & 1 deletion t/lib/Test/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ sub mojo_clean($wait=1) {

sub mojo_check_login( $t, $user=$MOJO_USER , $pass=$MOJO_PASSWORD ) {
$t->ua->get("/user.json");
return if $t->tx->res->code =~ /^(101|200|302)$/;
return if $t->tx && $t->tx->res->code =~ /^(101|200|302)$/;
mojo_login($t, $user,$pass);
}

Expand Down
6 changes: 6 additions & 0 deletions t/mojo/10_login.t
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ sub test_login_non_admin($t, $base, $clone){

mojo_check_login($t, $name, $pass);
$base->is_public(0);
$base->show_clones(1);

$t->get_ok("/machine/clone/".$base->id.".html")
->status_is(200);
Expand Down Expand Up @@ -365,10 +366,15 @@ sub test_login_non_admin_req($t, $base, $clone){

mojo_check_login($t, $name, $pass);
$base->is_public(0);
$base->show_clones(1);

$t->get_ok("/machine/clone/".$base->id.".html")
->status_is(200);
die "Error cloning ".$base->id if $t->tx->res->code() != 200;

$base->show_clones(0);
$t->get_ok("/machine/clone/".$base->id.".html")
->status_is(403);
}


Expand Down
39 changes: 32 additions & 7 deletions t/mojo/30_settings.t
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,46 @@ sub clean_clones() {
}
}

sub _create_storage_pool($id_vm , $vm_name) {
$t->get_ok("/list_storage_pools/$vm_name");
my $sp = decode_json($t->tx->res->body);
my $name = new_pool_name();
my ($found) = grep { $_->{name} eq $name } @$sp;
return $name if $found;

my $dir0 = "/var/tmp/$$/";

mkdir $dir0 if !-e $dir0;

my $dir = $dir0."/".new_pool_name();

mkdir $dir or die "$! $dir" if !-e $dir;


my $req = Ravada::Request->create_storage_pool(
uid => user_admin->id
,id_vm => $id_vm
,name => $name
,directory => $dir
);
wait_request( );
is($req->error,'');

return $name;
}

sub test_storage_pools($vm_name) {

my $id_vm = _id_vm($vm_name);
my $sp_name = _create_storage_pool($id_vm, $vm_name);

$t->get_ok("/list_storage_pools/$vm_name");

is($t->tx->res->code(),200) or die $t->tx->res->body;

my $sp = decode_json($t->tx->res->body);
ok(scalar(@$sp));

my $id_vm = _id_vm($vm_name);

$t->get_ok("/list_storage_pools/$id_vm");

is($t->tx->res->code(),200) or die $t->tx->res->body;
Expand All @@ -532,11 +562,6 @@ sub test_storage_pools($vm_name) {

my ($sp_inactive) = grep { $_->{name} ne 'default' } @$sp_id;

if ( !$sp_inactive ) {
# warn "Warning: no sp in addition to 'default' in ".Dumper($sp_id);
$sp_inactive = $sp_id->[0];
}

my $name_inactive= $sp_inactive->{name};
die "Error, no name in ".Dumper($sp_inactive) if !$name_inactive;

Expand Down

0 comments on commit dabbc8b

Please sign in to comment.