27d1df229a606758b3b6cde38317e0025ec6a415
[debian/amanda] / installcheck / amservice.pl
1 # Copyright (c) 2005-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 Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 3;
20
21 use lib "@amperldir@";
22 use Installcheck::Run qw( run run_get );
23 use Amanda::Paths;
24 use Amanda::Constants;
25
26 my $input_filename = "$AMANDA_TMPDIR/amservice_input.txt";
27 my $testconf = Installcheck::Run::setup();
28 my $input;
29
30 sub write_input_file {
31     my ($contents) = @_;
32     open my $fh, ">", $input_filename
33         or die("Could not write to $input_filename");
34     print $fh $contents;
35     close $fh;
36 }
37
38 sub all_lines_ok {
39     my ($output) = @_;
40     my $ok = 1;
41
42     return 0 if not $output;
43
44     for (split /\n/, $output) {
45         next if /^OPTIONS /;
46         next if /^OK /;
47         diag "Got unexpected line: $_";
48         $ok = 0;
49     }
50
51     return $ok;
52 }
53
54 # a simple run of amservice to begin with
55 like(run_get('amservice', '-f', '/dev/null', 'localhost', 'local', 'noop'),
56     qr/^OPTIONS features=/,
57     "amservice runs noop successfully");
58
59 $input = <<EOF;
60 <dle>
61   <program>GNUTAR</program>
62   <disk>$AMANDA_TMPDIR</disk>
63 </dle>
64 EOF
65
66 SKIP: {
67     skip "GNUTAR not installed", 1 unless $Amanda::Constants::GNUTAR;
68     write_input_file($input);
69     ok(all_lines_ok(
70         run_get('amservice', '-f', $input_filename, 'localhost', 'local', 'selfcheck')),
71         "GNUTAR program selfchecks successfully");
72 }
73
74 # (can't test DUMP, since we don't have a device)
75
76 $input = <<EOF;
77 <dle>
78   <program>APPLICATION</program>
79   <backup-program>
80     <plugin>amgtar</plugin>
81   </backup-program>
82   <disk>$AMANDA_TMPDIR</disk>
83 </dle>
84 EOF
85
86 SKIP: {
87     skip "GNUTAR not installed", 1 unless $Amanda::Constants::GNUTAR;
88     write_input_file($input);
89     ok(all_lines_ok(
90         run_get('amservice', '-f', $input_filename, 'localhost', 'local', 'selfcheck')),
91         "amgtar application selfchecks successfully");
92 }
93
94 $input = <<EOF;
95 <dle>
96   <program>APPLICATION</program>
97   <backup-program>
98     <plugin>amstar</plugin>
99   </backup-program>
100   <disk>$AMANDA_TMPDIR</disk>
101 </dle>
102 EOF
103
104 Installcheck::Run::cleanup();
105 unlink($input_filename);