Imported Upstream version 3.3.3
[debian/amanda] / installcheck / Amanda_Disklist.pl
1 # Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use Test::More tests => 13;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use Amanda::Config qw( :init :getconf );
26 use Amanda::Disklist;
27 use Installcheck::Config;
28
29 my $testconf;
30
31 $testconf = Installcheck::Config->new();
32 $testconf->add_dumptype("mytype", [
33     "compress" => "server",
34     "starttime" => "1830",
35     "amandad_path" => "\"/path/to/amandad\"",
36 ]);
37 $testconf->add_interface("eth1", []);
38 $testconf->add_dle("otherbox /home mytype");
39 $testconf->add_dle("otherbox /disk1 mytype");
40 $testconf->add_dle("otherbox /disk2 mytype");
41 $testconf->add_dle(<<EOF);
42 myhost /mydisk {
43     auth "bsd"
44 } -1 eth1
45 EOF
46 $testconf->write();
47
48 if (config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF") != $CFGERR_OK) {
49     config_print_errors();
50     die("config errors");
51 }
52
53 is(Amanda::Disklist::read_disklist(), $CFGERR_OK,
54     "read_disklist returns CFGERR_OK")
55     or die("Error loading disklist");
56
57 my ($x, $d, @list);
58
59 $x = Amanda::Disklist::get_host("otherbox");
60 ok($x, "get_host returns a host");
61 is($x->{'auth'}, 'BSDTCP', "..host has correct auth");
62 is_deeply([ sort @{$x->{'disks'}} ],
63           [ sort "/disk1", "/disk2", "/home" ],
64           "..and three disks");
65 is(interface_name($x->{'interface'}->{'config'}), "default", "..and correct interface");
66
67 $d = $x->get_disk("/home");
68 is($d->{'name'}, "/home", "host->get_disk() works");
69
70 @list = $x->all_disks();
71 is_deeply([ sort map { $_->{'name'} } @list ],
72           [ sort "/disk1", "/disk2", "/home" ],
73           "host->all_disks returns all disk objects");
74
75 @list = Amanda::Disklist::all_hosts();
76 is_deeply([ sort( map { $_->{'hostname'} } @list ) ],
77         [ sort qw(myhost otherbox) ],
78         "all_hosts returns correct hosts");
79
80 $x = Amanda::Disklist::get_disk("myhost", "/mydisk");
81 ok($x, "get_disk returns a disk");
82 is($x->{'name'}, "/mydisk", "..and it's the right one");
83
84 @list = Amanda::Disklist::all_disks();
85 is(scalar @list, 4, "all_lists returns 4 disks");
86
87 $x = Amanda::Disklist::get_interface("eth1");
88 is(interface_name($x->{'config'}), "eth1", "get_interface returns an interface");
89
90 @list = Amanda::Disklist::all_interfaces();
91 is(scalar @list, 2, "all_interfaces returns two interfaces");