Skip to content

Commit 3650ec4

Browse files
committed
Treat an unset destination mbuffer as 'off' in checkBackupSet
When a backup set configures no mbuffer at all (neither the legacy 'mbuffer' property nor a per-destination 'dst_X_mbuffer'), dst_X_mbuffer is left undef. The check 'ne off' then evaluated undef ne 'off' as true, entering mbuffer validation: it emitted uninitialized-value warnings and died with a bogus "mbuffer size '' invalid". Default an undef value to 'off' so such configurations are accepted. Add a test exercising checkBackupSet with all mbuffer properties removed.
1 parent 234d055 commit 3650ec4

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

lib/ZnapZend/Config.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ my $checkBackupSets = sub {
257257
}
258258

259259
# mbuffer property set? check if executable is available on remote host
260-
if ($backupSet->{$dst . '_mbuffer'} ne 'off') {
260+
# (an undef value means no mbuffer was configured at all => treat as 'off')
261+
if (($backupSet->{$dst . '_mbuffer'} // 'off') ne 'off') {
261262
my ($mbuffer, $mbufferPort) = split /:/, $backupSet->{$dst . '_mbuffer'}, 2;
262263
my ($remote, $dataset) = $splitHostDataSet->($backupSet->{$dst});
263264
my $file = ($remote ? "$remote:" : '') . $mbuffer;

t/znapzend-lib-config-mbuffer.t

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env perl
2+
3+
# Test ZnapZend::Config::checkBackupSet() with a backup set that configures
4+
# no mbuffer at all (neither the legacy 'mbuffer' property nor a per-destination
5+
# 'dst_X_mbuffer'). Such a set leaves dst_X_mbuffer undefined; checkBackupSet
6+
# must treat that as "mbuffer off" and not fall into mbuffer validation (which
7+
# would emit uninitialized-value warnings and die with a bogus
8+
# "mbuffer size '' invalid").
9+
10+
use strict;
11+
use warnings;
12+
13+
use FindBin;
14+
$ENV{PATH} = $FindBin::RealBin . ':' . $ENV{PATH};
15+
my $buildDir;
16+
17+
BEGIN {
18+
$buildDir = shift @ARGV // $FindBin::RealBin . '/../';
19+
}
20+
21+
use lib "$FindBin::RealBin/../lib";
22+
use lib "$buildDir/thirdparty/lib/perl5";
23+
24+
use Test::More;
25+
use Test::Exception;
26+
use Mojo::Log;
27+
28+
use_ok 'ZnapZend::Config';
29+
30+
my $zLog = Mojo::Log->new(level => 'fatal');
31+
my $cfg = ZnapZend::Config->new(zLog => $zLog, debug => 0);
32+
isa_ok($cfg, 'ZnapZend::Config');
33+
34+
my $bs = $cfg->getBackupSet(0, 0, 'tank/source')->[0];
35+
ok($bs && $bs->{src} eq 'tank/source', 'got backup set for tank/source');
36+
37+
# Simulate a configuration that does not use mbuffer anywhere:
38+
# drop the legacy 'mbuffer'/'mbuffer_size' and every per-destination
39+
# mbuffer property, leaving dst_X_mbuffer to default to undef.
40+
delete $bs->{$_} for grep { /mbuffer/ } keys %$bs;
41+
42+
lives_ok { $cfg->checkBackupSet($bs) }
43+
'checkBackupSet tolerates a backup set without any mbuffer configuration';
44+
45+
done_testing;
46+
47+
1;

test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ perl -I./thirdparty/lib/perl5 \
1515
-MDevel::Cover=+ignore,thirdparty ./t/autoscrub.t
1616
perl -I./thirdparty/lib/perl5 \
1717
-MDevel::Cover=+ignore,thirdparty ./t/znapzend-lib-splitter.t
18+
perl -I./thirdparty/lib/perl5 \
19+
-MDevel::Cover=+ignore,thirdparty ./t/znapzend-lib-config-mbuffer.t

0 commit comments

Comments
 (0)