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 => 3;
22 use lib "@amperldir@";
24 use Installcheck::Config;
25 use Installcheck::Run qw(run run_get run_err $diskname);
26 use Installcheck::Dumpcache;
28 use File::Path qw(rmtree mkpath);
39 if (!$Installcheck::Run::have_expect) {
41 skip("Expect.pm not available",
42 Test::More->builder->expected_tests);
47 # amrecover can successfully set the host if its hostname is localhost
48 my $hostname = hostname;
49 my $set_host_succeed = 0;
50 $set_host_succeed=1 if ( ($hostname eq "localhost")
51 or ($hostname =~ /localhost\./));
53 my $debug = !exists $ENV{'HARNESS_ACTIVE'};
54 diag("logging amrecover conversations to stdout because Test::Harness not in use")
58 my $testdir = "$Installcheck::TMP/amfetchdump-installcheck/files";
64 for my $filename (<$testdir/*>) {
79 my ($exp, $continued);
80 my @commands = @{$params{'commands'}};
83 my @h_opt = ('-h', 'localhost') unless $set_host_succeed;
84 $exp = Installcheck::Run::run_expect('amrecover', 'TESTCONF',
85 @h_opt, '-s', 'localhost', '-t', 'localhost', '-o', 'auth=local');
86 $exp->log_stdout($debug);
90 [ qr{220.*ready\.}, mkcont "server-ready" ],
91 [ qr{200 Config set to TESTCONF\.}, mkcont "config-set" ],
92 [ qr{Use the sethost command}, mkcont "use-sethost" ],
93 [ qr{syntax error}, mkcont "syntax-err" ],
94 [ qr{Invalid command:}, mkcont "invalid-cmd" ],
95 [ qr{200 Dump host set}, mkcont "host-set" ],
96 [ qr{200 Disk set to}, mkcont "disk-set" ],
97 [ qr{Added file /1kilobyte}, mkcont "added-file" ],
98 [ qr{The following tapes are needed:}, mkcont "tapes-needed" ],
99 [ qr{Load tape \S+ now}, mkcont "load-tape" ],
100 [ qr{Restoring files into directory}, mkcont "restoring-into" ],
101 [ qr{All existing files.*can be deleted}, mkcont "can-delete" ],
102 [ qr{\./1kilobyte}, mkcont "restored-file" ],
103 [ qr{200 Good bye}, mkcont "bye" ],
105 [ qr{amrecover> }, sub {
106 my $cmd = shift @commands or die "out of commands!";
107 push @results, "> $cmd";
108 $exp->send("$cmd\n");
111 [ qr{Continue \[\?/Y/n/s/d\]\?}, sub {
112 die "multiple Continue requests" if $continued;
115 push @results, "> continue-Y";
119 [ qr{Continue \[\?/Y/n\]\?}, sub { # the "all files" question
120 push @results, "> deletall-Y";
128 ## plain vanilla amrecover run
130 Installcheck::Dumpcache::load("basic");
141 is_deeply([ @results ], [
142 'server-ready', 'config-set',
144 '> sethost localhost',
146 "> setdisk $diskname",
151 'tapes-needed', 'load-tape',
153 'restoring-into', 'can-delete',
159 "simple restore follows the correct steps")
160 or diag Dumper([@results]);
162 ok((-f "1kilobyte" and ! -z "1kilobyte"),
163 "..restored file appears in current directory");
169 "sethost localhost ", # <-- note extra space
174 is_deeply([ @results ], [
175 'server-ready', 'config-set',
177 '> sethost localhost ',
179 '> sethost localhost',
184 "check trailling space")
185 or die Dumper([@results]);
191 Installcheck::Run::cleanup();