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