A backup job in pool mode keeps referencing its pool after the pool got deleted. Resolving the guests of such a job dies with "pool '<name>' does not exist", and since get_included_vmids() did not catch this, the whole /cluster/backup-info/not-backed-up call failed. The GUI then hides the "Show guests without backup job" button, so users lose exactly the overview that would tell them some guests are no longer backed up. Catch the error per job, warn about it and continue with the remaining jobs. The broken job does not back up anything, so its guests correctly show up as not covered by any backup job. Add a test for get_included_vmids() covering this case. Signed-off-by: Michal Fox <me@dualfroz.com>
72 lines
1.9 KiB
Perl
72 lines
1.9 KiB
Perl
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use lib '..';
|
|
|
|
use Test::More;
|
|
use Test::MockModule;
|
|
|
|
use PVE::API2::Cluster::BackupInfo;
|
|
|
|
my $vmlist = {
|
|
ids => {
|
|
100 => { type => 'qemu', node => 'node1' },
|
|
101 => { type => 'qemu', node => 'node1' },
|
|
102 => { type => 'lxc', node => 'node1' },
|
|
},
|
|
};
|
|
|
|
my $pools = {
|
|
testpool => [100],
|
|
};
|
|
|
|
my $jobs_cfg = {
|
|
ids => {
|
|
'backup-pool' => { type => 'vzdump', pool => 'testpool' },
|
|
'backup-vmid' => { type => 'vzdump', vmid => '101' },
|
|
},
|
|
};
|
|
|
|
my $cluster_module = Test::MockModule->new('PVE::Cluster');
|
|
$cluster_module->mock(get_vmlist => sub { return $vmlist });
|
|
|
|
my $api2tools_module = Test::MockModule->new('PVE::API2Tools');
|
|
$api2tools_module->mock(
|
|
get_resource_pool_guest_members => sub {
|
|
my ($pool) = @_;
|
|
die "pool '$pool' does not exist\n" if !$pools->{$pool};
|
|
return $pools->{$pool};
|
|
},
|
|
);
|
|
|
|
my $backup_info_module = Test::MockModule->new('PVE::API2::Cluster::BackupInfo');
|
|
$backup_info_module->mock(
|
|
cfs_read_file => sub {
|
|
my ($filename) = @_;
|
|
return { jobs => [] } if $filename eq 'vzdump.cron';
|
|
return $jobs_cfg if $filename eq 'jobs.cfg';
|
|
die "unexpected file '$filename'\n";
|
|
},
|
|
);
|
|
|
|
is_deeply(
|
|
PVE::API2::Cluster::BackupInfo::get_included_vmids(),
|
|
{ 100 => 1, 101 => 1 },
|
|
'guests of all backup jobs are included',
|
|
);
|
|
|
|
$jobs_cfg->{ids}->{'backup-deleted-pool'} = { type => 'vzdump', pool => 'deletedpool' };
|
|
|
|
my @warnings;
|
|
my $included = eval {
|
|
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
|
PVE::API2::Cluster::BackupInfo::get_included_vmids();
|
|
};
|
|
is($@, '', 'job referencing a deleted pool does not make the lookup fail');
|
|
is_deeply($included, { 100 => 1, 101 => 1 }, 'guests of the other jobs are still included');
|
|
like($warnings[0] // '', qr/pool 'deletedpool' does not exist/, 'broken job is warned about');
|
|
|
|
done_testing();
|