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