1 # Copyright (c) 2008, 2010 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 85;
25 use lib "@amperldir@";
27 use Installcheck::Run;
28 use Installcheck::Catalogs;
29 use Amanda::Config qw( :init :getconf config_dir_relative );
30 use Amanda::DB::Catalog;
32 use Amanda::Xfer qw( :constants );
34 # send xfer logging somewhere
35 Amanda::Debug::dbopen("installcheck");
36 Installcheck::log_test_output();
38 # set up and load a simple config
39 my $testconf = Installcheck::Run->setup();
41 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF') == $CFGERR_OK
42 or die("Could not load test config");
44 # test functions against an empty set of logfiles
46 is_deeply([ Amanda::DB::Catalog::get_write_timestamps() ], [],
47 "No write_timestamps in an empty catalog");
49 is_deeply(Amanda::DB::Catalog::get_latest_write_timestamp(), undef,
50 "No latest write_timestamp in an empty catalog");
52 is_deeply(Amanda::DB::Catalog::get_latest_write_timestamp(type => 'amvault'), undef,
53 "No latest write_timestamp in an empty catalog, even of a specific type");
55 is_deeply([ Amanda::DB::Catalog::get_parts() ], [],
56 "No parts in an empty catalog");
58 # and add some logfiles to query, and a corresponding tapelist, while also gathering
59 # a list of parts and dumps for comparison with the results from Amanda::DB::Catalog.
60 # also add some files to holding disk
63 # install the bigdb catalog
64 my $cat = Installcheck::Catalogs::load("bigdb");
66 my %dumps = $cat->get_dumps();
67 my %parts = $cat->get_parts();
69 Amanda::DB::Catalog::_clear_cache();
73 if (exists $part->{'holding_file'}) {
74 return "$part->{holding_file}: " .
75 "$part->{dump}->{hostname} $part->{dump}->{diskname} " .
76 "w$part->{dump}->{write_timestamp} d$part->{dump}->{dump_timestamp}";
78 return "$part->{label}:$part->{filenum}: " .
79 "$part->{dump}->{hostname} $part->{dump}->{diskname} $part->{dump}->{orig_kb} " .
80 "w$part->{dump}->{write_timestamp} d$part->{dump}->{dump_timestamp}";
84 # filter out recursive links from part->dump->parts, without changing
85 # the original objects. Note that this removes the object-identity of
92 $p = do { my %t = %$p; \%t; }; # copy hash
93 $p->{'dump'} = do { my %t = %{$p->{'dump'}}; \%t; };
94 $p->{'dump'}->{'parts'} = undef;
102 my ($got, $exp, $msg, %params) = @_;
104 # give a warning if we accidentally select zero parts
106 diag("warning: zero parts expected: $msg")
107 unless $params{'zero_parts_expected'};
110 # filter recursive references to avoid confusing old is_deeply instances
111 if (!is_deeply(filter_parts($got), filter_parts($exp), $msg)) {
115 diag(" [$i] " . partstr($_));
119 diag("expected parts:");
122 diag(" [$i] " . partstr($_));
130 # get parts filtered by a regexp on the key
133 my @selected_keys = grep { $_ =~ $expr } keys %parts;
134 return map { $parts{$_} } @selected_keys;
137 # get parts filtered by an expression on the dumpfile itself
138 sub parts_matching(&) {
140 return grep { &$block } values %parts;
143 # put @_ in a canonical order
146 # convert bigints to strings and on to integers so is_deeply doesn't get confused
147 $_->{'dump'}->{'level'} = "$_->{dump}->{level}" + 0;
148 $_->{'dump'}->{'kb'} = "$_->{dump}->{kb}" + 0;
149 $_->{'dump'}->{'orig_kb'} = "$_->{dump}->{orig_kb}" + 0;
150 if (!defined $_->{filenum}) {
153 $_->{'filenum'} = "$_->{filenum}" + 0;
155 $_->{'kb'} = "$_->{kb}" + 0;
156 $_->{'orig_kb'} = "$_->{orig_kb}" + 0;
157 $_->{'partnum'} = "$_->{partnum}" + 0;
160 if (exists $a->{'holding_file'} and exists $b->{'holding_file'}) {
161 return $a->{'holding_file'} cmp $b->{'holding_file'};
162 } elsif (not exists $a->{'holding_file'} and not exists $b->{'holding_file'}) {
163 return ($a->{'label'} cmp $b->{'label'})
164 || ($a->{'filenum'} <=> $b->{'filenum'});
166 return (exists $a->{'holding_file'})? 1 : -1;
174 return "$dump->{hostname} $dump->{diskname} " .
175 "$dump->{dump_timestamp} $dump->{level}";
178 # filter out recursive links from dump->parts->dump, without changing
179 # the original objects.
184 for my $d (@$dumps) {
185 $d = do { my %t = %$d; \%t; }; # copy hash
187 return undef unless defined $_;
188 my $p = do { my %t = %$_; \%t }; # copy part
189 $p->{'dump'} = undef;
192 $d->{'parts'} = [ @dparts ];
200 my ($got, $exp, $msg, %params) = @_;
202 # give a warning if we accidentally select zero dumps
204 diag("warning: zero dumps expected: $msg")
205 unless $params{'zero_dumps_expected'};
208 # filter recursive references to avoid confusing old is_deeply instances
209 if (!is_deeply(filter_dumps($got), filter_dumps($exp), $msg)) {
212 diag(" " . dumpstr($_));
214 diag("expected dumps:");
216 diag(" " . dumpstr($_));
223 # get dumps filtered by a regexp on the key
226 my @selected_keys = grep { $_ =~ $expr } keys %dumps;
227 return map { $dumps{$_} } @selected_keys;
230 # get dumps filtered by an expression on the dumpfile itself
231 sub dumps_matching(&) {
233 return grep { &$block } values %dumps;
236 # put @_ in a canonical order
239 # convert bigints to strings and on to integers so is_deeply doesn't get confused
240 $_->{'level'} = "$_->{level}" + 0;
241 $_->{'kb'} = "$_->{kb}" + 0;
242 $_->{'orig_kb'} = "$_->{orig_kb}" + 0;
243 $_->{'nparts'} = "$_->{nparts}" + 0;
246 $a->{'write_timestamp'} cmp $b->{'write_timestamp'}
247 or $a->{'hostname'} cmp $b->{'hostname'}
248 or $a->{'diskname'} cmp $b->{'diskname'}
249 or $a->{'level'} <=> $b->{'level'}
255 # Test the timestamps
257 is_deeply([ Amanda::DB::Catalog::get_write_timestamps(), ],
258 [ '20080111000000', '20080222222222', '20080313133333',
259 '20080414144444', '20080515155555', '20080616166666',
261 "get_write_timestamps returns all logfile datestamps in proper order, with zero-padding");
263 is(Amanda::DB::Catalog::get_latest_write_timestamp(), '20100722000000',
264 "get_latest_write_timestamp correctly returns the latest write timestamp");
266 is(Amanda::DB::Catalog::get_latest_write_timestamp(type => 'amdump'), '20100722000000',
267 "get_latest_write_timestamp correctly returns the latest write timestamp of type amdump");
269 is(Amanda::DB::Catalog::get_latest_write_timestamp(type => 'amflush'), '20080111000000',
270 "get_latest_write_timestamp correctly returns the latest write timestamp of type amflush");
272 is(Amanda::DB::Catalog::get_latest_write_timestamp(types => [qw(amvault amflush)]),
274 "get_latest_write_timestamp correctly returns the latest write timestamp of a set of ts's");
276 is(Amanda::DB::Catalog::get_run_type('20080222222222'), "amvault",
277 "get_run_type detects amvault");
279 is(Amanda::DB::Catalog::get_run_type('20080111'), "amflush",
280 "get_run_type detects amflush (short ts)");
282 is(Amanda::DB::Catalog::get_run_type('20080111000000'), "amflush",
283 "get_run_type detects amflush (long ts)");
286 # test get_parts and sort_parts
288 got_parts([ sortparts Amanda::DB::Catalog::get_parts() ],
289 [ sortparts parts_named qr/.*/ ],
290 "get_parts returns all parts when given no parameters");
291 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111000000') ],
292 [ sortparts parts_named qr/somebox_lib_20080111/ ],
293 "get_parts parameter write_timestamp");
294 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111') ],
295 [ sortparts parts_named qr/somebox_lib_20080111/ ],
296 "get_parts accepts a short write_timestamp and zero-pads it");
297 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamps => ['20080111000000','20080222222222']) ],
298 [ sortparts parts_named qr/(20080111|20080222222222_p\d*)$/ ],
299 "get_parts parameter write_timestamps");
300 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111', holding => 1) ],
302 "get_parts parameter write_timestamp + holding => 1 returns nothing",
303 zero_parts_expected => 1);
305 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp => '20080111000000') ],
306 [ sortparts parts_named qr/somebox_lib_20080111/ ],
307 "get_parts parameter dump_timestamp");
308 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp => '20080111') ],
309 [ sortparts parts_named qr/somebox_lib_20080111/ ],
310 "get_parts accepts a short dump_timestamp and zero-pads it");
311 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamps => ['20080111000000','20080222222222']) ],
312 [ sortparts parts_named qr/(20080111|20080222222222_p\d*)$/ ],
313 "get_parts parameter dump_timestamps");
314 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp_match => '200801-2') ],
315 [ sortparts parts_named qr/20080[12]/ ],
316 "get_parts parameter dump_timestamp_match");
318 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => 'otherbox') ],
319 [ sortparts parts_named qr/^otherbox_/ ],
320 "get_parts parameter hostname");
321 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => ['otherbox','somebox']) ],
322 [ sortparts parts_named qr/^(otherbox_|somebox_)/ ],
323 "get_parts parameter hostnames");
324 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname_match => '*box') ],
325 [ sortparts parts_named qr/box/ ],
326 "get_parts parameter hostname_match");
328 got_parts([ sortparts Amanda::DB::Catalog::get_parts(diskname => '/lib') ],
329 [ sortparts parts_named qr/_lib_/ ],
330 "get_parts parameter diskname");
331 got_parts([ sortparts Amanda::DB::Catalog::get_parts(disknames => ['/lib','/usr/bin']) ],
332 [ sortparts parts_named qr/(_lib_|_usr_bin_)/ ],
333 "get_parts parameter disknames");
334 got_parts([ sortparts Amanda::DB::Catalog::get_parts(diskname_match => '/usr') ],
335 [ sortparts parts_named qr/_usr_/ ],
336 "get_parts parameter diskname_match");
338 got_parts([ sortparts Amanda::DB::Catalog::get_parts(label => 'Conf-001') ],
339 [ sortparts parts_matching { defined $_->{'label'} and $_->{'label'} eq 'Conf-001' } ],
340 "get_parts parameter label");
341 got_parts([ sortparts Amanda::DB::Catalog::get_parts(labels => ['Conf-002','Conf-003']) ],
342 [ sortparts parts_matching { defined $_->{'label'} and ($_->{'label'} eq 'Conf-002' or $_->{'label'} eq 'Conf-003') } ],
343 "get_parts parameter labels");
345 got_parts([ sortparts Amanda::DB::Catalog::get_parts(level => 0) ],
346 [ sortparts parts_matching { $_->{'dump'}->{'level'} == 0 } ],
347 "get_parts parameter level");
348 got_parts([ sortparts Amanda::DB::Catalog::get_parts(levels => [ 1 ]) ],
349 [ sortparts parts_matching { $_->{'dump'}->{'level'} == 1 } ],
350 "get_parts parameter levels");
352 got_parts([ sortparts Amanda::DB::Catalog::get_parts(status => "OK") ],
353 [ sortparts parts_matching { $_->{'status'} eq "OK" } ],
354 "get_parts parameter status = OK");
356 got_parts([ sortparts Amanda::DB::Catalog::get_parts(status => "PARTIAL") ],
357 [ sortparts parts_matching { $_->{'status'} eq "PARTIAL" } ],
358 "get_parts parameter status = PARTIAL");
360 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox") ],
361 [ sortparts parts_named qr/^oldbox_/ ],
362 "get_parts finds a holding-disk dump");
364 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox", holding => 0) ],
366 "get_parts ignores a holding-disk dump if holding is false",
367 zero_parts_expected => 1);
368 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox", holding => 1) ],
369 [ sortparts parts_named qr/^oldbox_/ ],
370 "get_parts supplies a holding-disk dump if holding is true");
371 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ]) ],
372 [ sortparts (parts_named qr/^oldbox_.*_holding/, parts_named qr/^somebox_/) ],
373 "get_parts returns both holding and on-media dumps");
374 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ],
376 [ sortparts parts_named qr/^oldbox_.*_holding/ ],
377 "get_parts ignores an on-media dump if holding is true");
379 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ],
381 [ sortparts parts_named qr/^somebox_/ ],
382 "get_parts ignores an holding dump if holding is false");
384 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
385 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
386 [ sortparts parts_named qr/_lib_/ ],
387 "get_parts parameter dumpspecs with one dumpspec");
389 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib", "somebox"], 0);
390 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
391 [ sortparts parts_matching { $_->{'dump'}->{'diskname'} eq '/lib'
392 or $_->{'dump'}->{'hostname'} eq 'somebox' } ],
393 "get_parts parameter dumpspecs with two dumpspecs");
395 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
396 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
397 [ sortparts parts_matching { $_->{'dump'}->{'hostname'} eq 'otherbox'
398 or $_->{'dump'}->{'hostname'} eq 'somebox' } ],
399 "get_parts parameter dumpspecs with two non-overlapping dumpspecs");
401 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
402 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ], holding => 1), ],
403 [ sortparts parts_matching { $_->{'dump'}->{'hostname'} eq 'otherbox'
404 and exists $_->{'holding_file'} } ],
405 "get_parts parameter dumpspecs with two non-overlapping dumpspecs, but holding files only");
407 ## more complex, multi-parameter queries
409 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => 'somebox',
410 diskname_match => '/lib') ],
411 [ sortparts parts_named qr/^somebox_lib_/ ],
412 "get_parts parameters hostname and diskname_match");
414 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080313133333',
415 dump_timestamp => '20080311131133') ],
416 [ sortparts parts_matching { $_->{'dump'}->{'dump_timestamp'} eq '20080311131133'
417 and $_->{'dump'}->{'write_timestamp'} eq '20080313133333' } ],
418 "get_parts parameters write_timestamp and dump_timestamp");
420 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080414144444',
422 [ ], # there were no OK dumps on that date
423 "get_parts parameters write_timestamp status",
424 zero_parts_expected => 1);
428 got_parts([ Amanda::DB::Catalog::sort_parts(['write_timestamp'],
429 @parts{'somebox_lib_20080222222222_p1','somebox_lib_20080111'}) ],
430 [ @parts{'somebox_lib_20080111','somebox_lib_20080222222222_p1'} ],
431 "sort by write_timestamps");
432 got_parts([ Amanda::DB::Catalog::sort_parts(['-write_timestamp'],
433 @parts{'somebox_lib_20080111','somebox_lib_20080222222222_p1'}) ],
434 [ @parts{'somebox_lib_20080222222222_p1','somebox_lib_20080111'} ],
435 "sort by write_timestamps, reverse");
437 got_parts([ Amanda::DB::Catalog::sort_parts(['hostname', '-diskname', 'write_timestamp'],
439 'somebox_lib_20080222222222_p1',
440 'somebox_usr_bin_20080313133333',
441 'somebox_lib_20080313133333_p4',
442 'otherbox_lib_20080313133333',
443 'somebox_lib_20080111',
446 'otherbox_lib_20080313133333',
447 'somebox_usr_bin_20080313133333',
448 'somebox_lib_20080111',
449 'somebox_lib_20080222222222_p1',
450 'somebox_lib_20080313133333_p4',
454 got_parts([ Amanda::DB::Catalog::sort_parts(['filenum'],
456 'somebox_lib_20080313133333_p9',
457 'somebox_lib_20080313133333_p10',
458 'somebox_lib_20080313133333_p1',
461 'somebox_lib_20080313133333_p1',
462 'somebox_lib_20080313133333_p9',
463 'somebox_lib_20080313133333_p10',
465 "filenum is sorted numerically, not lexically");
467 got_parts([ Amanda::DB::Catalog::sort_parts(['-partnum'],
469 'somebox_lib_20080313133333_p9',
470 'somebox_lib_20080313133333_p10',
471 'somebox_lib_20080313133333_p1',
474 'somebox_lib_20080313133333_p10',
475 'somebox_lib_20080313133333_p9',
476 'somebox_lib_20080313133333_p1',
478 "partnum is sorted numerically (and in reverse!), not lexically");
480 got_parts([ Amanda::DB::Catalog::sort_parts(['nparts'],
482 'somebox_lib_20080313133333_p9', # nparts=10
483 'somebox_lib_20080222222222_p2', # nparts=2
486 'somebox_lib_20080222222222_p2', # nparts=2
487 'somebox_lib_20080313133333_p9', # nparts=10
489 "nparts is sorted numerically, not lexically");
491 got_parts([ Amanda::DB::Catalog::sort_parts(['label'],
493 'somebox_lib_20080313133333_p9', # Conf-003
494 'somebox_lib_20080222222222_p2', # Conf-002
497 'somebox_lib_20080222222222_p2', # Conf-002
498 'somebox_lib_20080313133333_p9', # Conf-003
500 "labels sort correctly");
502 ### test dump selecting
504 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps() ],
505 [ sortdumps dumps_named qr/.*/ ],
506 "get_dumps returns all dumps when given no parameters");
508 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111000000') ],
509 [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
510 "get_dumps parameter write_timestamp");
512 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111') ],
513 [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
514 "get_dumps accepts a short write_timestamp and zero-pads it");
516 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamps => ['20080111000000','20080222222222']) ],
517 [ sortdumps dumps_named qr/(20080111|20080222222222)$/ ],
518 "get_dumps parameter write_timestamps");
520 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'otherbox') ],
521 [ sortdumps dumps_named qr/^otherbox/ ],
522 "get_dumps parameter hostname");
524 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'oldbox') ],
525 [ sortdumps dumps_named qr/^oldbox_.*_holding/ ],
526 "get_dumps parameter hostname, holding");
528 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostnames => ['notthere', 'otherbox']) ],
529 [ sortdumps dumps_named qr/^otherbox/ ],
530 "get_dumps parameter hostnames");
532 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname_match => 'other*') ],
533 [ sortdumps dumps_named qr/^otherbox/ ],
534 "get_dumps parameter hostname_match");
536 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname => '/lib') ],
537 [ sortdumps dumps_named qr/^[^_]*_lib_/ ],
538 "get_dumps parameter diskname");
540 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(disknames => ['/lib', '/usr/bin']) ],
541 [ sortdumps dumps_named qr/^[^_]*_(usr_bin|lib)_/ ],
542 "get_dumps parameter disknames");
544 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname_match => 'bin') ],
545 [ sortdumps dumps_named qr/.*_bin_/ ],
546 "get_dumps parameter diskname_match");
548 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp => '20080414144444') ],
549 [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444' } ],
550 "get_dumps parameter dump_timestamp");
552 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(
553 dump_timestamps => ['20080414144444', '20080311131133']) ],
554 [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444'
555 or $_->{'dump_timestamp'} eq '20080311131133' } ],
556 "get_dumps parameter dump_timestamps");
558 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp_match => '200804-7') ],
559 [ sortdumps dumps_matching { $_->{'dump_timestamp'} =~ /^20080[4567]/ } ],
560 "get_dumps parameter dump_timestamp_match");
562 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(level => 0) ],
563 [ sortdumps dumps_matching { $_->{'level'} == 0 } ],
564 "get_dumps parameter level");
566 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(levels => [ 1 ]) ],
567 [ sortdumps dumps_matching { $_->{'level'} == 1 } ],
568 "get_dumps parameter levels");
570 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "OK") ],
571 [ sortdumps dumps_matching { $_->{'status'} eq "OK" } ],
572 "get_dumps parameter status = OK");
574 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "PARTIAL") ],
575 [ sortdumps dumps_matching { $_->{'status'} eq "PARTIAL" } ],
576 "get_dumps parameter status = PARTIAL");
578 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "FAIL") ],
579 [ sortdumps dumps_matching { $_->{'status'} eq "FAIL" } ],
580 "get_dumps parameter status = FAIL");
582 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
583 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
584 [ sortdumps dumps_named qr/_lib_/ ],
585 "get_dumps parameter dumpspecs with one dumpspec");
587 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
588 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ], holding => 1) ],
589 [ sortdumps dumps_named qr/_lib_.*_holding/ ],
590 "get_dumps parameter dumpspecs with one dumpspec");
592 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib", "somebox"], 0);
593 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
594 [ sortdumps dumps_matching { $_->{'diskname'} eq '/lib'
595 or $_->{'hostname'} eq 'somebox' } ],
596 "get_dumps parameter dumpspecs with two dumpspecs");
598 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
599 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
600 [ sortdumps dumps_matching { $_->{'hostname'} eq 'otherbox'
601 or $_->{'hostname'} eq 'somebox' } ],
602 "get_dumps parameter dumpspecs with two non-overlapping dumpspecs");
604 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["does-not-exist"], 0);
605 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
607 "get_dumps parameter dumpspecs with a dumpspec that matches nothing",
608 zero_dumps_expected => 1);
610 @dumpspecs = Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, undef, '20080222222222');
611 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
612 [ sortdumps dumps_matching { $_->{'write_timestamp'} eq '20080222222222' }],
613 "get_dumps parameter dumpspecs with write_timestamp");
617 got_dumps([ Amanda::DB::Catalog::sort_dumps(['write_timestamp'],
618 @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'}) ],
619 [ @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'} ],
620 "sort dumps by write_timestamps");
621 got_dumps([ Amanda::DB::Catalog::sort_dumps(['-write_timestamp'],
622 @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'}) ],
623 [ @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'} ],
624 "sort dumps by write_timestamps, reverse");
626 got_dumps([ Amanda::DB::Catalog::sort_dumps(['hostname', '-diskname', 'write_timestamp'],
628 'somebox_lib_20080222222222',
629 'somebox_usr_bin_20080313133333',
630 'somebox_lib_20080313133333',
631 'otherbox_lib_20080313133333',
632 'somebox_lib_20080111',
635 'otherbox_lib_20080313133333',
636 'somebox_usr_bin_20080313133333',
637 'somebox_lib_20080111',
638 'somebox_lib_20080222222222',
639 'somebox_lib_20080313133333',
641 "multi-key dump sort");
643 got_dumps([ Amanda::DB::Catalog::sort_dumps(['nparts'],
645 'somebox_lib_20080313133333', # nparts=10
646 'somebox_lib_20080222222222', # nparts=2
649 'somebox_lib_20080222222222', # nparts=2
650 'somebox_lib_20080313133333', # nparts=10
652 "dumps' nparts is sorted numerically, not lexically");
654 got_dumps([ Amanda::DB::Catalog::sort_dumps(['-level'],
656 'somebox_lib_20080313133333', # level=0
657 'somebox_usr_bin_20080313133333', # level=1
660 'somebox_usr_bin_20080313133333', # level=1
661 'somebox_lib_20080313133333', # level=0
663 "sort dumps by level, reversed");
665 got_dumps([ Amanda::DB::Catalog::sort_dumps(['dump_timestamp'],
667 'somebox_lib_20080313133333', # dts=20080313133333
668 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
671 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
672 'somebox_lib_20080313133333', # dts=20080313133333
674 "sort dumps by write_timestamp");
677 # install the multi-taper catalog
678 $cat = Installcheck::Catalogs::load("multi-taper");
680 %dumps = $cat->get_dumps();
681 %parts = $cat->get_parts();
683 Amanda::DB::Catalog::_clear_cache();
685 got_parts([ sortparts Amanda::DB::Catalog::get_parts() ],
686 [ sortparts parts_named qr/.*/ ],
687 "get_parts returns all parts when given no parameters");