Unverified Commit 76512fb0 authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Test no download (#1693)

test:  create virtual machine when no ISO is download automatically
parent 1b15f31f
......@@ -61,4 +61,4 @@ jobs:
- name: Test mock VM
run: prove -lr t/vm/60_new_args.t t/30_request.t
- name: Test create from ISO
run: prove -lr t/request/25_create_from_iso.t
run: prove -lr t/request/25_create_from_iso.t t/vm/d10_not_download.t
......@@ -770,17 +770,27 @@ sub _check_downloading($self) {
my $id_iso = $self->defined_arg('id_iso');
my $iso_file = $self->defined_arg('iso_file');
$iso_file = '' if $iso_file && $iso_file eq '<NONE>';
return if !$id_iso && !$iso_file;
my $sth = $$CONNECTOR->dbh->prepare(
"SELECT id,downloading,device,has_cd "
"SELECT id,downloading,device,has_cd,name,url "
." FROM iso_images "
." WHERE (id=? or device=?) "
);
$sth->execute($id_iso,$iso_file);
my ($id_iso2,$downloading, $device, $has_cd) = $sth->fetchrow;
my ($id_iso2,$downloading, $device, $has_cd, $iso_name, $iso_url)
= $sth->fetchrow;
return if !$downloading && $device;
my $req_download = _search_request('download', id_iso => $id_iso2);
return $self->_status_error("done"
,"Error: ISO file required for $iso_name")
if $has_cd && !$device && !$iso_file && !$iso_url && !$device;
if ($has_cd && !$device && !$iso_file && !$req_download) {
$req_download = Ravada::Request->download(
id_iso => $id_iso2
......
......@@ -9,6 +9,8 @@ use Test::More;
use lib 't/lib';
use Test::Ravada;
use feature qw(signatures);
no warnings "experimental::signatures";
use_ok('Ravada');
my %ARG_CREATE_DOM = (
......@@ -35,12 +37,13 @@ sub test_dont_download {
);
$sth->execute;
my $name = new_domain_name();
my $id_iso = search_id_iso('test'.$vm->type);
eval {
$vm->create_domain(
name => $name
,vm => $vm
,disk => 1024 * 1024
,id_iso => search_id_iso('test')
,id_iso => $id_iso
,id_owner => user_admin->id
);
};
......@@ -52,8 +55,44 @@ sub test_dont_download {
$domain->remove(user_admin) if $domain;
unlink $device;
$sth = connector->dbh->prepare(
"DELETE FROM iso_images WHERE id=?"
);
$sth->execute($id_iso);
}
sub test_windows($vm) {
my $isos = rvd_front->list_iso_images();
my $dev = "/var/tmp/a.iso";
for my $iso (@$isos) {
next unless $iso->{name} =~ /windows/i || !$iso->{url};
is($iso->{has_cd},1) unless $iso->{name} =~ /^Empty/;
is($iso->{url}, undef);
my $name = new_domain_name();
my @args =(
id_owner => user_admin->id
,name => $name
,id_iso => $iso->{id}
,vm => $vm->type
);
my $req = Ravada::Request->create_domain(@args);
ok($req->status,'done');
like($req->error,qr/ISO.*required/) unless $iso->{name} =~ /Empty/;
wait_request(debug => 0);
$name = new_domain_name();
push @args, ( iso_file => $dev) if $iso->{has_cd};
my $req2 = Ravada::Request->create_domain(@args,name => $name );
ok($req2->status,'requested');
wait_request( debug => 0);
ok($req2->status,'done');
is($req2->error, '');
my $domain = rvd_back->search_domain($name);
ok($domain, "Expected domain $name created") or exit;
}
}
#########################################################
clean();
......@@ -72,6 +111,7 @@ for my $vm_name ( vm_names() ) {
skip($msg,10) if !$vm;
test_windows($vm);
test_dont_download($vm);
}
......
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