Commit 9489ccf5 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

prepare_base requires user for authorization

parent 24faedf5
......@@ -589,10 +589,8 @@ sub _do_cmd_create{
warn "$$ creating domain" if $DEBUG;
my $domain;
$domain = $self->create_domain(%{$request->args},request => $request);
warn $@ if $@;
$request->status('done');
$request->error($@);
}
......@@ -710,7 +708,6 @@ sub _cmd_start {
$domain->start();
$request->status('done');
$request->error($@ or '');
}
......@@ -719,14 +716,16 @@ sub _cmd_prepare_base {
my $request = shift;
$request->status('working');
my $name = $request->args('name');
eval {
my $domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->prepare_base();
};
$request->status('done');
$request->error($@);
my $name = $request->args('name') or confess "Missing argument name";
my $uid = $request->args('uid') or confess "Missing argument uid";
my $user = Ravada::Auth::SQL->search_by_id( $uid);
my $domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->prepare_base($user);
}
......@@ -738,14 +737,12 @@ sub _cmd_shutdown {
$request->status('working');
my $name = $request->args('name');
my $timeout = ($request->args('timeout') or 60);
my $domain;
eval {
$domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->shutdown(timeout => $timeout);
};
$request->status('done');
$request->error($@);
$domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->shutdown(timeout => $timeout);
}
......
......@@ -34,6 +34,11 @@ our %VALID_ARG = (
name => 1
,uid => 1
}
,prepare_base => {
name => 1
,uid => 1
}
);
our $CONNECTOR;
......@@ -207,15 +212,20 @@ sub prepare_base {
my $proto = shift;
my $class=ref($proto) || $proto;
my $name = shift;
$name = $name->name if ref($name) =~ /Domain/;
my %args = @_;
confess "Missing domain name" if !$args{name};
confess "Missing uid" if !$args{uid};
my %args = ( name => $name ) or confess "Missing domain name";
for (keys %args) {
confess "Invalid argument $_" if !$VALID_ARG{'remove_domain'}->{$_};
}
$args{name} = $args{name}->name if ref($args{name}) =~ /Domain/;
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'prepare_base'
, args => encode_json({ name => $name }));
, args => encode_json( \%args ));
}
......
......@@ -133,7 +133,7 @@ sub test_req_create_base {
my $domain = $ravada->search_domain($name);
ok($domain,"I can't find domain $name") && do {
$domain->prepare_base();
$domain->prepare_base($USER);
ok($domain && $domain->is_base,"Domain $name should be base");
};
return $domain;
......@@ -184,10 +184,10 @@ ok($ravada,"I can't launch a new Ravada");# or exit;
my ($vm_kvm, $vm_lxc);
eval { $vm_kvm = $ravada->search_vm('kvm') if $ravada;
@ARG_CREATE_DOM = ( id_iso => 1, vm => 'kvm', id_owner => 1 ) if $vm_kvm;
@ARG_CREATE_DOM = ( id_iso => 1, vm => 'kvm', id_owner => $USER->id ) if $vm_kvm;
};
eval { $vm_lxc = $ravada->search_vm('lxc') if $ravada;
@ARG_CREATE_DOM = ( id_template => 1, vm => 'LXC', id_owner => 1 ) if $vm_lxc;
@ARG_CREATE_DOM = ( id_template => 1, vm => 'LXC', id_owner => $USER->id ) if $vm_lxc;
};
SKIP: {
......
......@@ -104,7 +104,7 @@ sub test_new_domain {
sub test_prepare_base {
my $domain = shift;
$domain->prepare_base();
$domain->prepare_base($USER);
my $sth = $test->dbh->prepare("SELECT is_base FROM domains WHERE name=? ");
$sth->execute($domain->name);
......@@ -148,15 +148,16 @@ sub test_domain{
ok($is_base eq '0',"Mangled is base '$is_base', it should be 0 "
.Dumper($list_domains_data));
ok(!$domain->is_active ,"domain should be inactive") if defined $active && $active==0;
ok($domain->is_active ,"domain should be active") if defined $active && $active==1;
# test prepare base
test_prepare_base($domain);
ok($domain->is_base,"Domain should be base"
.Dumper($domain->_select_domain_db())
);
ok(!$domain->is_active,"domain should be inactive") if defined $active && $active==0;
ok($domain->is_active,"domain should active") if defined $active && $active==1;
ok(test_domain_in_virsh($domain->name,$domain->name)," not in virsh list all");
my $domain2;
eval { $domain2 = $vm->vm->get_domain_by_name($domain->name)};
......
......@@ -68,7 +68,7 @@ sub test_new_domain_from_iso {
eval { $domain = $RAVADA->create_domain(name => $name
, id_iso => 1
,vm => $BACKEND
,id_owner => 1
,id_owner => $USER->id
)
};
ok(!$@,"Domain $name not created: $@");
......@@ -100,7 +100,7 @@ sub test_prepare_base {
ok(!grep(/^$name$/,map { $_->name } @list),"$name shouldn't be a base ".Dumper(\@list));
$domain->prepare_base();
$domain->prepare_base($USER);
my $sth = $test->dbh->prepare("SELECT * FROM domains WHERE name=? ");
$sth->execute($domain->name);
......@@ -126,7 +126,7 @@ sub test_new_domain_from_base {
my $domain = $RAVADA->create_domain(
name => $name
,id_base => $base->id
,id_owner => 1
,id_owner => $USER->id
,vm => $BACKEND
);
ok($domain,"Domain not created");
......
......@@ -26,11 +26,15 @@ sub test_req_prepare_base {
my $domain0 = $RAVADA->search_domain($name);
ok(!$domain0->is_base,"Domain $name should not be base");
my $req = Ravada::Request->prepare_base($name);
my $req = Ravada::Request->prepare_base(name => $name, uid => $USER->id);
$RAVADA->_process_requests_dont_fork();
ok($req->status('done'),"Request should be done, it is".$req->status);
ok(!$req->error(),"Request error ".$req->error);
my $domain = $RAVADA->search_domain($name);
ok($domain->is_base,"Domain $name should be base");
ok($domain->file_base_img,"Domain $name has no file_base_img");
}
......
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