Imported Upstream version 3.2.0
[debian/amanda] / installcheck / Amanda_Disklist.pl
1 # Copyright (c) 2008, 2010 Zmanda, Inc.  All Rights Reserved.
2 #
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.
6 #
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
10 # for more details.
11 #
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
15 #
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 13;
20 use strict;
21 use warnings;
22
23 use lib "@amperldir@";
24 use Amanda::Config qw( :init :getconf );
25 use Amanda::Disklist;
26 use Installcheck::Config;
27
28 my $testconf;
29
30 $testconf = Installcheck::Config->new();
31 $testconf->add_dumptype("mytype", [
32     "compress" => "server",
33     "starttime" => "1830",
34     "amandad_path" => "\"/path/to/amandad\"",
35 ]);
36 $testconf->add_interface("eth1", []);
37 $testconf->add_dle("otherbox /home mytype");
38 $testconf->add_dle("otherbox /disk1 mytype");
39 $testconf->add_dle("otherbox /disk2 mytype");
40 $testconf->add_dle(<<EOF);
41 myhost /mydisk {
42     auth "bsd"
43 } -1 eth1
44 EOF
45 $testconf->write();
46
47 if (config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF") != $CFGERR_OK) {
48     config_print_errors();
49     die("config errors");
50 }
51
52 is(Amanda::Disklist::read_disklist(), $CFGERR_OK,
53     "read_disklist returns CFGERR_OK")
54     or die("Error loading disklist");
55
56 my ($x, $d, @list);
57
58 $x = Amanda::Disklist::get_host("otherbox");
59 ok($x, "get_host returns a host");
60 is($x->{'auth'}, 'BSD', "..host has correct auth");
61 is_deeply([ sort @{$x->{'disks'}} ],
62           [ sort "/disk1", "/disk2", "/home" ],
63           "..and three disks");
64 is(interface_name($x->{'interface'}->{'config'}), "default", "..and correct interface");
65
66 $d = $x->get_disk("/home");
67 is($d->{'name'}, "/home", "host->get_disk() works");
68
69 @list = $x->all_disks();
70 is_deeply([ sort map { $_->{'name'} } @list ],
71           [ sort "/disk1", "/disk2", "/home" ],
72           "host->all_disks returns all disk objects");
73
74 @list = Amanda::Disklist::all_hosts();
75 is_deeply([ sort( map { $_->{'hostname'} } @list ) ],
76         [ sort qw(myhost otherbox) ],
77         "all_hosts returns correct hosts");
78
79 $x = Amanda::Disklist::get_disk("myhost", "/mydisk");
80 ok($x, "get_disk returns a disk");
81 is($x->{'name'}, "/mydisk", "..and it's the right one");
82
83 @list = Amanda::Disklist::all_disks();
84 is(scalar @list, 4, "all_lists returns 4 disks");
85
86 $x = Amanda::Disklist::get_interface("eth1");
87 is(interface_name($x->{'config'}), "eth1", "get_interface returns an interface");
88
89 @list = Amanda::Disklist::all_interfaces();
90 is(scalar @list, 2, "all_interfaces returns two interfaces");