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