1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
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.
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
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
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 13;
24 use lib "@amperldir@";
25 use Amanda::Config qw( :init :getconf );
27 use Installcheck::Config;
31 $testconf = Installcheck::Config->new();
32 $testconf->add_dumptype("mytype", [
33 "compress" => "server",
34 "starttime" => "1830",
35 "amandad_path" => "\"/path/to/amandad\"",
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);
48 if (config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF") != $CFGERR_OK) {
49 config_print_errors();
53 is(Amanda::Disklist::read_disklist(), $CFGERR_OK,
54 "read_disklist returns CFGERR_OK")
55 or die("Error loading disklist");
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" ],
65 is(interface_name($x->{'interface'}->{'config'}), "default", "..and correct interface");
67 $d = $x->get_disk("/home");
68 is($d->{'name'}, "/home", "host->get_disk() works");
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");
75 @list = Amanda::Disklist::all_hosts();
76 is_deeply([ sort( map { $_->{'hostname'} } @list ) ],
77 [ sort qw(myhost otherbox) ],
78 "all_hosts returns correct hosts");
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");
84 @list = Amanda::Disklist::all_disks();
85 is(scalar @list, 4, "all_lists returns 4 disks");
87 $x = Amanda::Disklist::get_interface("eth1");
88 is(interface_name($x->{'config'}), "eth1", "get_interface returns an interface");
90 @list = Amanda::Disklist::all_interfaces();
91 is(scalar @list, 2, "all_interfaces returns two interfaces");