1 # Copyright (c) 2008-2012 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'}->{'bytes'} = "$_->{dump}->{bytes}" + 0;
149 $_->{'dump'}->{'kb'} = "$_->{dump}->{kb}" + 0;
150 $_->{'dump'}->{'orig_kb'} = "$_->{dump}->{orig_kb}" + 0;
151 if (!defined $_->{filenum}) {
154 $_->{'filenum'} = "$_->{filenum}" + 0;
156 $_->{'kb'} = "$_->{kb}" + 0;
157 $_->{'orig_kb'} = "$_->{orig_kb}" + 0;
158 $_->{'partnum'} = "$_->{partnum}" + 0;
161 if (exists $a->{'holding_file'} and exists $b->{'holding_file'}) {
162 return $a->{'holding_file'} cmp $b->{'holding_file'};
163 } elsif (not exists $a->{'holding_file'} and not exists $b->{'holding_file'}) {
164 return ($a->{'label'} cmp $b->{'label'})
165 || ($a->{'filenum'} <=> $b->{'filenum'});
167 return (exists $a->{'holding_file'})? 1 : -1;
175 return "$dump->{hostname} $dump->{diskname} " .
176 "$dump->{dump_timestamp} $dump->{level}";
179 # filter out recursive links from dump->parts->dump, without changing
180 # the original objects.
185 for my $d (@$dumps) {
186 $d = do { my %t = %$d; \%t; }; # copy hash
188 return undef unless defined $_;
189 my $p = do { my %t = %$_; \%t }; # copy part
190 $p->{'dump'} = undef;
193 $d->{'parts'} = [ @dparts ];
201 my ($got, $exp, $msg, %params) = @_;
203 # give a warning if we accidentally select zero dumps
205 diag("warning: zero dumps expected: $msg")
206 unless $params{'zero_dumps_expected'};
209 # filter recursive references to avoid confusing old is_deeply instances
210 if (!is_deeply(filter_dumps($got), filter_dumps($exp), $msg)) {
213 diag(" " . dumpstr($_));
215 diag("expected dumps:");
217 diag(" " . dumpstr($_));
224 # get dumps filtered by a regexp on the key
227 my @selected_keys = grep { $_ =~ $expr } keys %dumps;
228 return map { $dumps{$_} } @selected_keys;
231 # get dumps filtered by an expression on the dumpfile itself
232 sub dumps_matching(&) {
234 return grep { &$block } values %dumps;
237 # put @_ in a canonical order
240 # convert bigints to strings and on to integers so is_deeply doesn't get confused
241 $_->{'level'} = "$_->{level}" + 0;
242 $_->{'bytes'} = "$_->{bytes}" + 0;
243 $_->{'kb'} = "$_->{kb}" + 0;
244 $_->{'orig_kb'} = "$_->{orig_kb}" + 0;
245 $_->{'nparts'} = "$_->{nparts}" + 0;
248 $a->{'write_timestamp'} cmp $b->{'write_timestamp'}
249 or $a->{'hostname'} cmp $b->{'hostname'}
250 or $a->{'diskname'} cmp $b->{'diskname'}
251 or $a->{'level'} <=> $b->{'level'}
257 # Test the timestamps
259 is_deeply([ Amanda::DB::Catalog::get_write_timestamps(), ],
260 [ '20080111000000', '20080222222222', '20080313133333',
261 '20080414144444', '20080515155555', '20080616166666',
263 "get_write_timestamps returns all logfile datestamps in proper order, with zero-padding");
265 is(Amanda::DB::Catalog::get_latest_write_timestamp(), '20100722000000',
266 "get_latest_write_timestamp correctly returns the latest write timestamp");
268 is(Amanda::DB::Catalog::get_latest_write_timestamp(type => 'amdump'), '20100722000000',
269 "get_latest_write_timestamp correctly returns the latest write timestamp of type amdump");
271 is(Amanda::DB::Catalog::get_latest_write_timestamp(type => 'amflush'), '20080111000000',
272 "get_latest_write_timestamp correctly returns the latest write timestamp of type amflush");
274 is(Amanda::DB::Catalog::get_latest_write_timestamp(types => [qw(amvault amflush)]),
276 "get_latest_write_timestamp correctly returns the latest write timestamp of a set of ts's");
278 is(Amanda::DB::Catalog::get_run_type('20080222222222'), "amvault",
279 "get_run_type detects amvault");
281 is(Amanda::DB::Catalog::get_run_type('20080111'), "amflush",
282 "get_run_type detects amflush (short ts)");
284 is(Amanda::DB::Catalog::get_run_type('20080111000000'), "amflush",
285 "get_run_type detects amflush (long ts)");
288 # test get_parts and sort_parts
290 got_parts([ sortparts Amanda::DB::Catalog::get_parts() ],
291 [ sortparts parts_named qr/.*/ ],
292 "get_parts returns all parts when given no parameters");
293 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111000000') ],
294 [ sortparts parts_named qr/somebox_lib_20080111/ ],
295 "get_parts parameter write_timestamp");
296 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111') ],
297 [ sortparts parts_named qr/somebox_lib_20080111/ ],
298 "get_parts accepts a short write_timestamp and zero-pads it");
299 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamps => ['20080111000000','20080222222222']) ],
300 [ sortparts parts_named qr/(20080111|20080222222222_p\d*)$/ ],
301 "get_parts parameter write_timestamps");
302 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080111', holding => 1) ],
304 "get_parts parameter write_timestamp + holding => 1 returns nothing",
305 zero_parts_expected => 1);
307 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp => '20080111000000') ],
308 [ sortparts parts_named qr/somebox_lib_20080111/ ],
309 "get_parts parameter dump_timestamp");
310 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp => '20080111') ],
311 [ sortparts parts_named qr/somebox_lib_20080111/ ],
312 "get_parts accepts a short dump_timestamp and zero-pads it");
313 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamps => ['20080111000000','20080222222222']) ],
314 [ sortparts parts_named qr/(20080111|20080222222222_p\d*)$/ ],
315 "get_parts parameter dump_timestamps");
316 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dump_timestamp_match => '200801-2') ],
317 [ sortparts parts_named qr/20080[12]/ ],
318 "get_parts parameter dump_timestamp_match");
320 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => 'otherbox') ],
321 [ sortparts parts_named qr/^otherbox_/ ],
322 "get_parts parameter hostname");
323 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => ['otherbox','somebox']) ],
324 [ sortparts parts_named qr/^(otherbox_|somebox_)/ ],
325 "get_parts parameter hostnames");
326 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname_match => '*box') ],
327 [ sortparts parts_named qr/box/ ],
328 "get_parts parameter hostname_match");
330 got_parts([ sortparts Amanda::DB::Catalog::get_parts(diskname => '/lib') ],
331 [ sortparts parts_named qr/_lib_/ ],
332 "get_parts parameter diskname");
333 got_parts([ sortparts Amanda::DB::Catalog::get_parts(disknames => ['/lib','/usr/bin']) ],
334 [ sortparts parts_named qr/(_lib_|_usr_bin_)/ ],
335 "get_parts parameter disknames");
336 got_parts([ sortparts Amanda::DB::Catalog::get_parts(diskname_match => '/usr') ],
337 [ sortparts parts_named qr/_usr_/ ],
338 "get_parts parameter diskname_match");
340 got_parts([ sortparts Amanda::DB::Catalog::get_parts(label => 'Conf-001') ],
341 [ sortparts parts_matching { defined $_->{'label'} and $_->{'label'} eq 'Conf-001' } ],
342 "get_parts parameter label");
343 got_parts([ sortparts Amanda::DB::Catalog::get_parts(labels => ['Conf-002','Conf-003']) ],
344 [ sortparts parts_matching { defined $_->{'label'} and ($_->{'label'} eq 'Conf-002' or $_->{'label'} eq 'Conf-003') } ],
345 "get_parts parameter labels");
347 got_parts([ sortparts Amanda::DB::Catalog::get_parts(level => 0) ],
348 [ sortparts parts_matching { $_->{'dump'}->{'level'} == 0 } ],
349 "get_parts parameter level");
350 got_parts([ sortparts Amanda::DB::Catalog::get_parts(levels => [ 1 ]) ],
351 [ sortparts parts_matching { $_->{'dump'}->{'level'} == 1 } ],
352 "get_parts parameter levels");
354 got_parts([ sortparts Amanda::DB::Catalog::get_parts(status => "OK") ],
355 [ sortparts parts_matching { $_->{'status'} eq "OK" } ],
356 "get_parts parameter status = OK");
358 got_parts([ sortparts Amanda::DB::Catalog::get_parts(status => "PARTIAL") ],
359 [ sortparts parts_matching { $_->{'status'} eq "PARTIAL" } ],
360 "get_parts parameter status = PARTIAL");
362 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox") ],
363 [ sortparts parts_named qr/^oldbox_/ ],
364 "get_parts finds a holding-disk dump");
366 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox", holding => 0) ],
368 "get_parts ignores a holding-disk dump if holding is false",
369 zero_parts_expected => 1);
370 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => "oldbox", holding => 1) ],
371 [ sortparts parts_named qr/^oldbox_/ ],
372 "get_parts supplies a holding-disk dump if holding is true");
373 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ]) ],
374 [ sortparts (parts_named qr/^oldbox_.*_holding/, parts_named qr/^somebox_/) ],
375 "get_parts returns both holding and on-media dumps");
376 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ],
378 [ sortparts parts_named qr/^oldbox_.*_holding/ ],
379 "get_parts ignores an on-media dump if holding is true");
381 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostnames => [ "oldbox", "somebox" ],
383 [ sortparts parts_named qr/^somebox_/ ],
384 "get_parts ignores an holding dump if holding is false");
386 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
387 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
388 [ sortparts parts_named qr/_lib_/ ],
389 "get_parts parameter dumpspecs with one dumpspec");
391 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib", "somebox"], 0);
392 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
393 [ sortparts parts_matching { $_->{'dump'}->{'diskname'} eq '/lib'
394 or $_->{'dump'}->{'hostname'} eq 'somebox' } ],
395 "get_parts parameter dumpspecs with two dumpspecs");
397 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
398 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ]) ],
399 [ sortparts parts_matching { $_->{'dump'}->{'hostname'} eq 'otherbox'
400 or $_->{'dump'}->{'hostname'} eq 'somebox' } ],
401 "get_parts parameter dumpspecs with two non-overlapping dumpspecs");
403 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
404 got_parts([ sortparts Amanda::DB::Catalog::get_parts(dumpspecs => [ @dumpspecs ], holding => 1), ],
405 [ sortparts parts_matching { $_->{'dump'}->{'hostname'} eq 'otherbox'
406 and exists $_->{'holding_file'} } ],
407 "get_parts parameter dumpspecs with two non-overlapping dumpspecs, but holding files only");
409 ## more complex, multi-parameter queries
411 got_parts([ sortparts Amanda::DB::Catalog::get_parts(hostname => 'somebox',
412 diskname_match => '/lib') ],
413 [ sortparts parts_named qr/^somebox_lib_/ ],
414 "get_parts parameters hostname and diskname_match");
416 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080313133333',
417 dump_timestamp => '20080311131133') ],
418 [ sortparts parts_matching { $_->{'dump'}->{'dump_timestamp'} eq '20080311131133'
419 and $_->{'dump'}->{'write_timestamp'} eq '20080313133333' } ],
420 "get_parts parameters write_timestamp and dump_timestamp");
422 got_parts([ sortparts Amanda::DB::Catalog::get_parts(write_timestamp => '20080414144444',
424 [ ], # there were no OK dumps on that date
425 "get_parts parameters write_timestamp status",
426 zero_parts_expected => 1);
430 got_parts([ Amanda::DB::Catalog::sort_parts(['write_timestamp'],
431 @parts{'somebox_lib_20080222222222_p1','somebox_lib_20080111'}) ],
432 [ @parts{'somebox_lib_20080111','somebox_lib_20080222222222_p1'} ],
433 "sort by write_timestamps");
434 got_parts([ Amanda::DB::Catalog::sort_parts(['-write_timestamp'],
435 @parts{'somebox_lib_20080111','somebox_lib_20080222222222_p1'}) ],
436 [ @parts{'somebox_lib_20080222222222_p1','somebox_lib_20080111'} ],
437 "sort by write_timestamps, reverse");
439 got_parts([ Amanda::DB::Catalog::sort_parts(['hostname', '-diskname', 'write_timestamp'],
441 'somebox_lib_20080222222222_p1',
442 'somebox_usr_bin_20080313133333',
443 'somebox_lib_20080313133333_p4',
444 'otherbox_lib_20080313133333',
445 'somebox_lib_20080111',
448 'otherbox_lib_20080313133333',
449 'somebox_usr_bin_20080313133333',
450 'somebox_lib_20080111',
451 'somebox_lib_20080222222222_p1',
452 'somebox_lib_20080313133333_p4',
456 got_parts([ Amanda::DB::Catalog::sort_parts(['filenum'],
458 'somebox_lib_20080313133333_p9',
459 'somebox_lib_20080313133333_p10',
460 'somebox_lib_20080313133333_p1',
463 'somebox_lib_20080313133333_p1',
464 'somebox_lib_20080313133333_p9',
465 'somebox_lib_20080313133333_p10',
467 "filenum is sorted numerically, not lexically");
469 got_parts([ Amanda::DB::Catalog::sort_parts(['-partnum'],
471 'somebox_lib_20080313133333_p9',
472 'somebox_lib_20080313133333_p10',
473 'somebox_lib_20080313133333_p1',
476 'somebox_lib_20080313133333_p10',
477 'somebox_lib_20080313133333_p9',
478 'somebox_lib_20080313133333_p1',
480 "partnum is sorted numerically (and in reverse!), not lexically");
482 got_parts([ Amanda::DB::Catalog::sort_parts(['nparts'],
484 'somebox_lib_20080313133333_p9', # nparts=10
485 'somebox_lib_20080222222222_p2', # nparts=2
488 'somebox_lib_20080222222222_p2', # nparts=2
489 'somebox_lib_20080313133333_p9', # nparts=10
491 "nparts is sorted numerically, not lexically");
493 got_parts([ Amanda::DB::Catalog::sort_parts(['label'],
495 'somebox_lib_20080313133333_p9', # Conf-003
496 'somebox_lib_20080222222222_p2', # Conf-002
499 'somebox_lib_20080222222222_p2', # Conf-002
500 'somebox_lib_20080313133333_p9', # Conf-003
502 "labels sort correctly");
504 ### test dump selecting
506 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps() ],
507 [ sortdumps dumps_named qr/.*/ ],
508 "get_dumps returns all dumps when given no parameters");
510 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111000000') ],
511 [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
512 "get_dumps parameter write_timestamp");
514 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111') ],
515 [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
516 "get_dumps accepts a short write_timestamp and zero-pads it");
518 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamps => ['20080111000000','20080222222222']) ],
519 [ sortdumps dumps_named qr/(20080111|20080222222222)$/ ],
520 "get_dumps parameter write_timestamps");
522 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'otherbox') ],
523 [ sortdumps dumps_named qr/^otherbox/ ],
524 "get_dumps parameter hostname");
526 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'oldbox') ],
527 [ sortdumps dumps_named qr/^oldbox_.*_holding/ ],
528 "get_dumps parameter hostname, holding");
530 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostnames => ['notthere', 'otherbox']) ],
531 [ sortdumps dumps_named qr/^otherbox/ ],
532 "get_dumps parameter hostnames");
534 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname_match => 'other*') ],
535 [ sortdumps dumps_named qr/^otherbox/ ],
536 "get_dumps parameter hostname_match");
538 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname => '/lib') ],
539 [ sortdumps dumps_named qr/^[^_]*_lib_/ ],
540 "get_dumps parameter diskname");
542 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(disknames => ['/lib', '/usr/bin']) ],
543 [ sortdumps dumps_named qr/^[^_]*_(usr_bin|lib)_/ ],
544 "get_dumps parameter disknames");
546 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname_match => 'bin') ],
547 [ sortdumps dumps_named qr/.*_bin_/ ],
548 "get_dumps parameter diskname_match");
550 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp => '20080414144444') ],
551 [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444' } ],
552 "get_dumps parameter dump_timestamp");
554 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(
555 dump_timestamps => ['20080414144444', '20080311131133']) ],
556 [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444'
557 or $_->{'dump_timestamp'} eq '20080311131133' } ],
558 "get_dumps parameter dump_timestamps");
560 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp_match => '200804-7') ],
561 [ sortdumps dumps_matching { $_->{'dump_timestamp'} =~ /^20080[4567]/ } ],
562 "get_dumps parameter dump_timestamp_match");
564 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(level => 0) ],
565 [ sortdumps dumps_matching { $_->{'level'} == 0 } ],
566 "get_dumps parameter level");
568 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(levels => [ 1 ]) ],
569 [ sortdumps dumps_matching { $_->{'level'} == 1 } ],
570 "get_dumps parameter levels");
572 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "OK") ],
573 [ sortdumps dumps_matching { $_->{'status'} eq "OK" } ],
574 "get_dumps parameter status = OK");
576 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "PARTIAL") ],
577 [ sortdumps dumps_matching { $_->{'status'} eq "PARTIAL" } ],
578 "get_dumps parameter status = PARTIAL");
580 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "FAIL") ],
581 [ sortdumps dumps_matching { $_->{'status'} eq "FAIL" } ],
582 "get_dumps parameter status = FAIL");
584 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
585 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
586 [ sortdumps dumps_named qr/_lib_/ ],
587 "get_dumps parameter dumpspecs with one dumpspec");
589 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
590 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ], holding => 1) ],
591 [ sortdumps dumps_named qr/_lib_.*_holding/ ],
592 "get_dumps parameter dumpspecs with one dumpspec");
594 @dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib", "somebox"], 0);
595 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
596 [ sortdumps dumps_matching { $_->{'diskname'} eq '/lib'
597 or $_->{'hostname'} eq 'somebox' } ],
598 "get_dumps parameter dumpspecs with two dumpspecs");
600 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
601 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
602 [ sortdumps dumps_matching { $_->{'hostname'} eq 'otherbox'
603 or $_->{'hostname'} eq 'somebox' } ],
604 "get_dumps parameter dumpspecs with two non-overlapping dumpspecs");
606 @dumpspecs = Amanda::Cmdline::parse_dumpspecs(["does-not-exist"], 0);
607 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
609 "get_dumps parameter dumpspecs with a dumpspec that matches nothing",
610 zero_dumps_expected => 1);
612 @dumpspecs = Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, undef, '20080222222222');
613 got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
614 [ sortdumps dumps_matching { $_->{'write_timestamp'} eq '20080222222222' }],
615 "get_dumps parameter dumpspecs with write_timestamp");
619 got_dumps([ Amanda::DB::Catalog::sort_dumps(['write_timestamp'],
620 @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'}) ],
621 [ @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'} ],
622 "sort dumps by write_timestamps");
623 got_dumps([ Amanda::DB::Catalog::sort_dumps(['-write_timestamp'],
624 @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'}) ],
625 [ @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'} ],
626 "sort dumps by write_timestamps, reverse");
628 got_dumps([ Amanda::DB::Catalog::sort_dumps(['hostname', '-diskname', 'write_timestamp'],
630 'somebox_lib_20080222222222',
631 'somebox_usr_bin_20080313133333',
632 'somebox_lib_20080313133333',
633 'otherbox_lib_20080313133333',
634 'somebox_lib_20080111',
637 'otherbox_lib_20080313133333',
638 'somebox_usr_bin_20080313133333',
639 'somebox_lib_20080111',
640 'somebox_lib_20080222222222',
641 'somebox_lib_20080313133333',
643 "multi-key dump sort");
645 got_dumps([ Amanda::DB::Catalog::sort_dumps(['nparts'],
647 'somebox_lib_20080313133333', # nparts=10
648 'somebox_lib_20080222222222', # nparts=2
651 'somebox_lib_20080222222222', # nparts=2
652 'somebox_lib_20080313133333', # nparts=10
654 "dumps' nparts is sorted numerically, not lexically");
656 got_dumps([ Amanda::DB::Catalog::sort_dumps(['-level'],
658 'somebox_lib_20080313133333', # level=0
659 'somebox_usr_bin_20080313133333', # level=1
662 'somebox_usr_bin_20080313133333', # level=1
663 'somebox_lib_20080313133333', # level=0
665 "sort dumps by level, reversed");
667 got_dumps([ Amanda::DB::Catalog::sort_dumps(['dump_timestamp'],
669 'somebox_lib_20080313133333', # dts=20080313133333
670 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
673 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
674 'somebox_lib_20080313133333', # dts=20080313133333
676 "sort dumps by write_timestamp");
679 # install the multi-taper catalog
680 $cat = Installcheck::Catalogs::load("multi-taper");
682 %dumps = $cat->get_dumps();
683 %parts = $cat->get_parts();
685 Amanda::DB::Catalog::_clear_cache();
687 got_parts([ sortparts Amanda::DB::Catalog::get_parts() ],
688 [ sortparts parts_named qr/.*/ ],
689 "get_parts returns all parts when given no parameters");