Commit fa06c580 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

fixed search and remove of Void domains

parent 3145ecf2
......@@ -203,10 +203,25 @@ Removes a domain
sub remove_domain {
my $self = shift;
my $name = shift or confess "Missing domain name";
my %arg = @_;
croak "Argument name required "
if !$arg{name};
croak "Argument id_user required "
if !$arg{id_user};
lock_hash(%arg);
my $domain = $self->search_domain($arg{name}, 1)
or confess "ERROR: I can't find domain $arg{name}";
# TODO allow if user is admin
# my $user = ...
confess "ERROR: Access denied. User ".$arg{id_user}." is not owner of domain $arg{name}"
if $domain->id_owner != $arg{id_user};
# || $user->is_admin();
my $domain = $self->search_domain($name, 1)
or confess "ERROR: I can't find domain $name";
$domain->remove();
}
......@@ -231,6 +246,14 @@ sub search_domain {
warn $@ if $@ && $DEBUG;
return $domain if $id || $import;
}
my $vm = $self->search_vm('Void');
warn "No Void VM" if !$vm;
return if !$vm;
my $domain = $vm->search_domain($name, $import);
return $domain if $domain;
return;
}
......@@ -704,7 +727,7 @@ sub search_vm {
my $class = 'Ravada::VM::'.uc($type);
if ($type eq 'Void') {
if ($type =~ /Void/i) {
return Ravada::VM::Void->new();
}
......
......@@ -75,6 +75,7 @@ sub _data {
$self->{_data} = $self->_select_domain_db( name => $self->name);
confess "No DB info for domain ".$self->name if !$self->{_data};
confess "No field $field in domains" if !exists$self->{_data}->{$field};
return $self->{_data}->{$field};
}
......@@ -188,4 +189,9 @@ sub id_owner {
return $self->_data('id_owner',@_);
}
sub vm {
my $self = shift;
return $self->_data('vm');
}
1;
......@@ -30,7 +30,10 @@ sub display {
sub is_active {}
sub pause {}
sub remove {}
sub remove {
my $self = shift;
$self->_remove_domain_db();
}
sub shutdown {}
sub start {}
......
......@@ -46,6 +46,16 @@ sub list_domains {
}
sub search_domain {
my $self = shift;
my $name = shift;
my $domain = Ravada::Domain::Void->new( domain => $name);
my $id;
eval { $id = $domain->id };
return if !defined $id;
return $domain;
}
sub search_domain_by_id {
......
......@@ -95,11 +95,25 @@ sub test_manage_domain {
sub test_remove_domain {
my $domain = shift;
diag("Removing domain ".$domain->name);
my $domain0 = rvd_back()->search_domain($domain->name);
ok($domain0, "Domain ".$domain->name." should be there in ".ref $domain);
eval { $domain->remove };
ok(!$@ , "Error removing domain ".$domain->name." ".ref($domain).": $@") or exit;
my $domain2 = rvd_back()->search_domain($domain->name);
ok(!$domain2, "Domain ".$domain->name." should be removed in ".ref $domain);
}
sub test_search_domain {
my $domain = shift;
my $domain0 = rvd_back()->search_domain($domain->name);
ok($domain0, "Domain ".$domain->name." should be there in ".ref $domain);
};
#######################################################
remove_old_domains();
......@@ -126,6 +140,7 @@ for my $vm_name (qw( Void KVM )) {
test_vm_connect($vm_name);
test_search_vm($vm_name);
my $domain = test_create_domain($vm_name);
test_search_domain($domain);
test_manage_domain($domain);
test_remove_domain($domain);
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment