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