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

wip: download before create tests

parent 89c76917
......@@ -4282,6 +4282,9 @@ sub _cmd_download {
my $vm;
$vm = Ravada::VM->open($request->args('id_vm')) if $request->defined_arg('id_vm');
$vm = Ravada::VM->open(type => $request->args('vm'))
if $request->defined_arg('vm');
$vm = $self->search_vm('KVM') if !$vm;
my $delay = $request->defined_arg('delay');
......@@ -4295,7 +4298,7 @@ sub _cmd_download {
return;
}
my $device_cdrom = $vm->_iso_name($iso, $request, $verbose);
Ravada::Request->refresh_storage();
Ravada::Request->refresh_storage(id_vm => $vm->id);
}
sub _cmd_add_hardware {
......
......@@ -82,7 +82,7 @@ our %VALID_ARG = (
,dettach => { uid => 1, id_domain => 1 }
,set_driver => {uid => 1, id_domain => 1, id_option => 1}
,hybernate=> {uid => 1, id_domain => 1}
,download => {uid => 2, id_iso => 1, id_vm => 2, verbose => 2, delay => 2, test => 2}
,download => {uid => 2, id_iso => 1, id_vm => 2, vm => 2, verbose => 2, delay => 2, test => 2}
,refresh_storage => { id_vm => 2 }
,list_storage_pools => { id_vm => 1 , uid => 1 }
,check_storage => { uid => 1 }
......@@ -756,14 +756,14 @@ sub _validate_create_domain($self) {
$self->_validate_clone($id_base, $id_owner) if $id_base;
$self->_check_downloading();
return if $owner->is_admin
unless ( $owner->is_admin
|| $owner->can_create_machine()
|| ($id_base && $owner->can_clone);
|| ($id_base && $owner->can_clone)) {
return $self->_status_error("done","Error: access denied to user ".$owner->name);
return $self->_status_error("done","Error: access denied to user ".$owner->name);
}
$self->_check_downloading();
}
sub _check_downloading($self) {
......@@ -772,19 +772,21 @@ sub _check_downloading($self) {
return if !$id_iso && !$iso_file;
my $sth = $$CONNECTOR->dbh->prepare("SELECT id,downloading,device "
my $sth = $$CONNECTOR->dbh->prepare(
"SELECT id,downloading,device,has_cd "
." FROM iso_images "
." WHERE (id=? or device=?) "
);
$sth->execute($id_iso,$iso_file);
my ($id_iso2,$downloading, $device) = $sth->fetchrow;
my ($id_iso2,$downloading, $device, $has_cd) = $sth->fetchrow;
return if !$downloading && $device;
my $req_download = _search_request('download', id_iso => $id_iso2);
if (!$device && !$req_download) {
if ($has_cd && !$device && !$req_download) {
$req_download = Ravada::Request->download(
id_iso => $id_iso2
,uid => Ravada::Utils::user_daemon->id
,vm => $self->defined_arg('vm')
);
}
if (! $req_download) {
......
......@@ -426,6 +426,33 @@ sub _is_ip_nat($self, $ip) {
return 1;
}
sub _search_iso($self, $id, $device = undef) {
my $sth = $$CONNECTOR->dbh->prepare("SELECT * FROM iso_images "
." WHERE id=?"
);
$sth->execute($id);
my $row = $sth->fetchrow_hashref;
$row->{device} = $device if defined $device;
return $row;
}
sub _iso_name($self, $iso, $request=undef, $verbose=0) {
my $name = ($iso->{device} or $iso->{rename_file} or $iso->{file_re});
confess Dumper($iso) if !$name;
$name =~ s/(.*)\.\*(.*)/$1$2/;
$name =~ s/(.*)\.\+(.*)/$1.$2/;
confess $name if $name =~ m{[*+\\]};
$name = $self->dir_img."/".$name unless $name =~ m{^/};
my $sth = $$CONNECTOR->dbh->prepare(
"UPDATE iso_images "
." SET device=? WHERE id=?"
);
$sth->execute($name, $iso->{id});
return $name;
}
#########################################################################3
1;
......@@ -2535,7 +2535,7 @@ sub req_new_domain {
,swap => $swap
,data => $data
);
$args{iso_file} => $c->param('iso_file') if defined $c->param('iso_file');
$args{iso_file} = $c->param('iso_file') if defined $c->param('iso_file');
$args{options}->{uefi} = 1 if $bios && $bios eq 'UEFI';
$args{options}->{machine} = $machine if $machine;
$args{memory} = int($c->param('memory')*1024*1024) if $c->param('memory');
......
......@@ -162,7 +162,7 @@ sub test_req_create_base {
ok($req->status eq 'requested'
,"Status of request is ".$req->status." it should be requested");
$ravada->_process_requests_dont_fork();
wait_request();
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......
......@@ -160,6 +160,8 @@ for my $vm_name ( vm_names() ) {
);
ok($req, "Request $name not created");
$RVD_FRONT->wait_request($req);
$RVD_FRONT->wait_request($req);
$RVD_FRONT->wait_request($req);
ok($req->status eq 'done',"Request for create $vm domain ".$req->status);
......
......@@ -1157,6 +1157,11 @@ sub wait_request {
$run_at = 'now' if !$run_at;
$run_at = " $run_at";
}
if ($req->command eq 'refresh_machine_ports'
&& $req->error =~ /has ports .*up/) {
$req->status('done');
next;
}
if ($debug && (time%5 == 0)) {
diag("Waiting for request ".$req->id." ".$req->command." ".$req->status
.$run_at." bg=$background"
......@@ -1180,6 +1185,7 @@ sub wait_request {
like($error,qr{^($|.*port \d+ already used|rsync done)}) or confess $req->command;
} elsif($req->command eq 'refresh_machine_ports') {
like($error,qr{^($|.*is not up|.*has ports down|nc: |Connection)});
$req->status('done');
} elsif($req->command eq 'open_exposed_ports') {
like($error,qr{^($|.*No ip in domain|.*duplicated port)});
} elsif($req->command eq 'compact') {
......
......@@ -228,6 +228,7 @@ sub test_login_non_admin($t, $base, $clone){
my ($req) = grep { $_->status ne 'done' } $user->list_requests();
last if !$req;
wait_request(debug => 1, check_error => 1, background => 1, timeout => 120);
delete_request('open_exposed_ports');
}
my ($req) = reverse $user->list_requests();
is($req->error, '');
......
......@@ -93,10 +93,7 @@ sub test_req_create_domain_iso {
ok($req->status eq 'requested'
,"Status of request is ".$req->status." it should be requested");
my $rvd_back = rvd_back();
# $rvd_back->process_requests(1);
$rvd_back->process_requests();
wait_request(background => 1);
wait_request(background => 0);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......@@ -159,8 +156,7 @@ sub test_req_create_domain {
,"Status of request is ".$req->status." it should be requested");
my $rvd_back = rvd_back();
$rvd_back->process_requests();
wait_request(background => 1);
wait_request(background => 0);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......
......@@ -109,9 +109,7 @@ sub test_req_create_domain{
}
ok($req,"Expecting request to create_domain");
rvd_back()->process_requests();
wait_request(background => 1);
wait_request(background => 0);
ok($req->status('done'),"Expecting status='done' , got ".$req->status);
ok(!$req->error,"Expecting error '' , got '".($req->error or '')."'");
......@@ -145,6 +143,7 @@ sub test_req_create_fail {
} else {
rvd_back->_process_all_requests_dont_fork();
}
delete_request('refresh_storage');
wait_request( background => $fork, check_error => 0 );
ok($req->status('done'),"Expecting status='done' , got ".$req->status);
......@@ -222,6 +221,7 @@ sub test_args {
}
{
my $domain = test_req_create_domain($vm_name, $memory, $disk, "Request");
return if !$domain;
test_memory($vm_name, $domain, $memory, "Request") if $domain;
my $domain_backend = rvd_back->search_domain($domain->name);
......
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