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

Test: missing volume (#1624)

* refactor(test): work around missing volumes

It can be either a missing ISO file or a missing volume

* refactor(backend): properly check for missing volumes first
parent d728f873
......@@ -894,6 +894,10 @@ sub _check_free_space_prepare_base($self) {
my $pool_base = $self->_vm->default_storage_pool_name;
$pool_base = $self->_vm->base_storage_pool() if $self->_vm->base_storage_pool();
for my $volume ($self->list_volumes(device => 'disk')) {;
next if !$volume;
die "Error: volume $volume is missing.\n" if !$self->_vm->file_exists($volume);
}
for my $volume ($self->list_volumes_info(device => 'disk')) {;
next if !$volume->file;
die "Error: volume ".$volume->file." is missing.\n" if !$self->_vm->file_exists($volume->file);
......
......@@ -614,13 +614,24 @@ sub disk_device {
return list_volumes(@_);
}
sub list_volumes($self, @args) {
my @vol = $self->list_volumes_info(@args);
my @vol2;
for (@vol) {
push @vol2,($_->{file});
sub list_volumes($self, $attribute=undef, $value=undef) {
my $data = $self->_load();
return () if !exists $data->{hardware}->{device};
my @vol;
my $n_order = 0;
for my $dev (@{$data->{hardware}->{device}}) {
next if exists $dev->{type}
&& $dev->{type} eq 'base';
if (exists $dev->{file} ) {
confess "Error loading $dev->{file} ".$@ if $@;
next if defined $attribute
&& (!exists $dev->{$attribute} || $dev->{$attribute} ne $value);
}
push @vol,($dev->{file});
}
return @vol2;
return @vol;
}
sub list_volumes_info($self, $attribute=undef, $value=undef) {
......
......@@ -256,9 +256,9 @@ sub test_add_cdrom($domain) {
my $iso = $domain->_vm->_search_iso(search_id_iso('Alpine'));
$data->{file} = $iso->{device};
} else {
$data->{file} = $file_iso;
$data->{boot} = 2;
}
$data->{file} = $file_iso if !$data->{file};
my $found = 0;
test_add_hardware_request($domain->_vm, $domain,'disk', $data);
......
......@@ -1818,8 +1818,9 @@ sub test_prepare_base_disk_missing($vm) {
my @volumes = $domain->list_volumes();
my ($one, $two) = @volumes;
unlink $two;
my ($two) = grep(!/iso$/i, reverse @volumes);
unlink $two or die "$! $two";
is($vm->file_exists($two),undef);
eval {
$domain->prepare_base(user_admin);
......@@ -1832,8 +1833,12 @@ sub test_prepare_base_disk_missing($vm) {
print $out "Error\n";
close $two;
eval {
$domain->prepare_base(user_admin);
};
like($@,qr/Unknown capacity/,"Expecting unknown capacity for $two") if $@;
unlink $two;
$domain->remove(user_admin);
}
......
Markdown is supported
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