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

refactor(test): check downloads with headers

parent f1ce07b1
......@@ -4243,9 +4243,10 @@ sub _cmd_download {
my $delay = $request->defined_arg('delay');
sleep $delay if $delay;
my $verbose = $request->defined_arg('verbose');
my $test = $request->defined_arg('test');
my $iso = $vm->_search_iso($id_iso);
if ($iso->{device} && -e $iso->{device}) {
if (!$test && $iso->{device} && -e $iso->{device}) {
$request->status('done',"$iso->{device} already downloaded");
return;
}
......
......@@ -1152,15 +1152,17 @@ sub _iso_name($self, $iso, $req, $verbose=1) {
if $VERIFY_ISO && $iso->{url} && !$iso->{md5} && !$iso->{sha256};
my $downloaded = 0;
if (! -e $device || ! -s $device) {
my $test = 0;
$test = 1 if $req && $req->defined_arg('test');
if ($test || ! -e $device || ! -s $device) {
$req->status("downloading $iso_name file"
,"Downloading ISO file for $iso_name "
." from $iso->{url}. It may take several minutes"
) if $req;
_fill_url($iso);
my $test = 0;
$test = 1 if $req && $req->defined_arg('test');
my $url = $self->_download_file_external($iso->{url}, $device, $verbose, $test);
$req->output($url) if $req;
$self->_refresh_storage_pools();
die "Download failed, file $device missing.\n"
if !$test && ! -e $device;
......@@ -1269,9 +1271,10 @@ sub _download_file_external_headers($self,$url) {
run3(\@cmd,\$in,\$out,\$err);
my ($status) = $err =~ /^\s*(HTTP.*\d+.*)/m;
return $url if $status =~ /(200|301|302) ([\w\s]+)$/;
return $url if $status =~ /(200|301|302|307) ([\w\s]+)$/;
# 200: OK
# 302: redirect
# 307: temporary redirect
die "Error: $url not found $status";
}
......
......@@ -2343,6 +2343,7 @@ sub unload_nbd() {
}
sub _unload_nbd() {
return if $<;
my @cmd = ($QEMU_NBD,"-d", $DEV_NBD);
my ($in, $out, $err);
run3(\@cmd,\$in,\$out,\$err);
......
......@@ -17,12 +17,12 @@ $Ravada::DEBUG=0;
sub test_download($vm, $id_iso, $test=0) {
my $iso = $vm->_search_iso($id_iso);
unlink($iso->{device}) or die "$! $iso->{device}"
if $iso->{device} && -e $iso->{device};
# unlink($iso->{device}) or die "$! $iso->{device}"
# if $iso->{device} && -e $iso->{device};
my $req1 = Ravada::Request->download(
id_iso => $id_iso
, id_vm => $vm->id
, delay => 4
# , delay => 4
, test => $test
);
is($req1->status, 'requested');
......@@ -30,6 +30,7 @@ sub test_download($vm, $id_iso, $test=0) {
rvd_back->_process_all_requests_dont_fork();
is($req1->status, 'done');
is($req1->error,'',$iso->{name});
like($req1->output,qr/^http.*/);
}
......@@ -52,11 +53,6 @@ sub search_id_isos {
##################################################################
SKIP: {
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
skip($msg,30);
}
init();
......@@ -64,7 +60,7 @@ for my $vm_name ('KVM') {
my $rvd_back = rvd_back();
my $vm = $rvd_back->search_vm($vm_name);
my $msg = "SKIPPED: No virtual managers found";
if ($vm && $vm_name =~ /kvm/i && $>) {
if (0 && $vm && $vm_name =~ /kvm/i && $>) {
$msg = "SKIPPED: Test must run as root";
$vm = undef;
}
......
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