Commit 5e421388 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

fix(backend): refresh ISOs misplaced file

It only happened if the ISO cache was removed
parent 44bea8c5
......@@ -363,6 +363,7 @@ sub _refresh_isos($self) {
my ($file);
($file) = $row->{url} =~ m{.*/(.*)} if $row->{url};
$file = $row->{rename_file} if $row->{rename_file};
my $file_re = $row->{file_re};
next if $row->{device};
......@@ -1190,19 +1191,17 @@ sub _download_file_external($self, $url, $device, $verbose=1) {
die $err;
}
sub _search_iso {
my $self = shift;
my $id_iso = shift or croak "Missing id_iso";
my $file_iso = shift;
sub _search_iso($self, $id_iso, $file_iso=undef) {
my $sth = $$CONNECTOR->dbh->prepare("SELECT * FROM iso_images WHERE id = ?");
$sth->execute($id_iso);
my $row = $sth->fetchrow_hashref;
die "Missing iso_image id=$id_iso" if !keys %$row;
return $row if $file_iso;
return $row if $file_iso && -e $file_iso;
return $row if $row->{device} && -e $row->{device};
if ( $row->{device} && -e $row->{device} ) {
($row->{filename}) = $row->{device} =~ m{.*/(.*)};
}
$self->_fetch_filename($row);# if $row->{file_re};
if ($VERIFY_ISO) {
$self->_fetch_md5($row) if !$row->{md5} && $row->{md5_url};
......@@ -1210,7 +1209,7 @@ sub _search_iso {
}
if ( !$row->{device} && $row->{filename}) {
if (my $volume = $self->search_volume($row->{filename})) {
if (my $volume = $self->search_volume_re(qr("^".$row->{filename}))) {
$row->{device} = $volume->get_path;
my $sth = $$CONNECTOR->dbh->prepare(
"UPDATE iso_images SET device=? WHERE id=?"
......@@ -1218,6 +1217,8 @@ sub _search_iso {
$sth->execute($volume->get_path, $row->{id});
}
}
confess Dumper($row) if $row->{rename_file} && $row->{device}
&& $row->{rename_file} =~ /^xubuntu/ && $row->{device} =~ m{/ubuntu};
return $row;
}
......
......@@ -55,6 +55,8 @@ sub test_download {
is($iso2->{rename_file}, $iso2->{filename}) if $iso2->{rename_file};
like($iso2->{device},qr'.',"Expecting something in device field ");
return $iso2;
}
sub test_download_fail {
......@@ -82,7 +84,7 @@ sub search_id_isos {
my $vm = shift;
my $sth=connector->dbh->prepare(
"SELECT * FROM iso_images"
# ." where name like 'Xubuntu Bionic%'"
# ." where name like 'Xubuntu %'"
." ORDER BY name,arch"
);
$sth->execute;
......@@ -119,6 +121,21 @@ sub add_locales {
rvd_back->_process_requests_dont_fork();
}
sub test_refresh_isos {
my ($vm,$iso) = @_;
# Now we remove the ISO file and try to refresh
unlink $iso->{device};
my $sth = connector->dbh->prepare(
"UPDATE iso_images set device=NULL WHERE id=?"
);
$sth->execute($iso->{id});
$vm->_refresh_isos();
my $iso2 = $vm->_search_iso($iso->{id});
like($iso2->{device},qr{.*/$iso->{rename_file}}) or exit;
}
##################################################################
......@@ -149,7 +166,9 @@ for my $vm_name ('KVM') {
$sth->execute($id_iso);
$sth->finish;
test_download($vm, $id_iso);
my $iso = test_download($vm, $id_iso);
test_refresh_isos($vm, $iso) if $iso->{rename_file};
}
}
}
......
......@@ -149,6 +149,8 @@ sub test_create_domain {
for my $dom2 ( $vm->list_domains ) {
is(ref($dom2),ref($domain)) if $vm_name ne 'Void';
}
my ($cdrom) = grep { /iso/ } $domain->list_volumes;
like($cdrom, qr/\.iso$/, "Expecting a CDROM ".Dumper([$domain->list_volumes]));
return $domain;
}
......@@ -459,9 +461,6 @@ sub test_create_domain_nocd {
return if $@ && $@ =~ /Can't locate object method/;
is($@,'');
ok(!$iso->{device},"Expecting no device. Got: "
.($iso->{device} or '<UNDEF>')) or return;
my $domain;
eval { $domain = rvd_back->search_vm($vm_name)->create_domain(
name => $name
......@@ -473,10 +472,8 @@ sub test_create_domain_nocd {
is($@,'');
ok($domain,"Expecting a domain");
my $iso2 = select_iso($id_iso);
is($iso->{id}, $iso2->{id}) or return;
ok(!$iso2->{device},"Expecting no device. Got: "
.($iso2->{device} or '<UNDEF>'));
my ($cdrom) = grep { /iso/ } $domain->list_volumes;
is($cdrom, undef, "Expecting a CDROM ".Dumper([$domain->list_volumes]));
}
sub select_iso {
......
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