File: 00_filer_command.t

package info (click to toggle)
libnetapp-perl 500.002-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 5,695; makefile: 2
file content (124 lines) | stat: -rw-r--r-- 3,928 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env perl -w

use strict;
use warnings;

use lib 'blib/lib';
use lib 't/lib';
use NetApp::Test;

BEGIN {
    if ( not @NetApp::Test::filer_args ) {
        print "1..0 # Skip: No test filers defined\n";
        exit 0;
    }
}

use Test::More qw( no_plan );
use Test::Exception;
use Data::Dumper;

use NetApp::Filer;

my @filer_args		= @NetApp::Test::filer_args;

my ($ssh_filer)		= grep { $_->{protocol} eq 'ssh' } @filer_args;
my $ssh_command		= $ssh_filer->{ssh_command};
my $ssh_identity	= $ssh_filer->{ssh_identity};
my $hostname		= $ssh_filer->{hostname};
my $ssh_string_want	= join(' ',@$ssh_command,
                               "-i $ssh_identity -l root $hostname");

my ($telnet_filer)	= grep { $_->{protocol} eq 'telnet' } @filer_args;

throws_ok {
    my $filer		= NetApp::Filer->new({});
} qr{Mandatory parameter 'hostname' missing in call to NetApp::Filer::BUILD.*},
    qq{NetApp::Filer->new requires hostname};

throws_ok {
    my $filer		= NetApp::Filer->new({
        hostname	=> 'some_random_hostname',
        ssh_identity	=> '/no/such/file',
    });
} qr{No such ssh_identity file: /no/such/file},
    qq{NetApp::Filer->new requires valid ssh_identity file};

my $filer		= NetApp::Filer->new( $ssh_filer );
isa_ok( $filer, 'NetApp::Filer' );

ok( ref $filer->_get_ssh_command eq "ARRAY",
    'return type of _get_ssh_command');

my $ssh_string_have	= join(' ',@{ $filer->_get_ssh_command });
ok( $ssh_string_have eq $ssh_string_want,
    "return value of _get_ssh_command: $ssh_string_have" );

ok( $filer->_run_command( command => [qw(version)] ),
    'calling _run_command');
ok( $filer->_get_command_status,	'true status');

my @stderr	= $filer->_get_command_stderr;
my @stdout	= $filer->_get_command_stdout;

ok( scalar @stderr == 0,		'no stderr');
ok( $filer->_get_command_error == 0,	'no error');
ok( scalar @stdout == 1,		'one line in stdout');

my $status	= $filer->_run_command(
    command	=> [qw(nosuch command)],
    nonfatal	=> 1,
);

ok( $status,	'calling run_command again');
# Hmm...  The status is still true
# ok( $filer->_get_command_status == 0,	'failed status' );
ok( scalar $filer->_get_command_stdout == 0, 'no stdout');
ok( scalar $filer->_get_command_stderr == 1, 'one line in stderr');
ok( ( $filer->_get_command_stderr )[0] eq
        "nosuch not found.  Type '?' for a list of commands",
    'nosuch command error message');

#
# This is failing with a bizarre error:
#   Failed test 'Fatal _run_command throws exception by default'
#   at t/00_filer_command.t line 76.
# expecting: Regexp ((?-xism:Error running 'nosuch command' on))
# found: panic: attempt to copy freed scalar a1c7d20 to 9fd7238 at /efs/dist/perl5/core/5.10.0-ml01/.exec/x86-32.linux.2.4/lib/perl5/Carp/Heavy.pm line 104.
#
# There appear to be major problems with perl5.8 and Test::Exception
# on Solaris 8, too.
#
# throws_ok {
#     $filer->_run_command( command => [qw(nosuch command)] );
# } qr{Error running 'nosuch command' on},
#     qq{Fatal _run_command throws exception by default};

eval {
    $filer->_run_command( command => [qw(nosuch command)] );
};
ok( $@ =~ qr{Error running 'nosuch command' via ssh on},
    qq{Fatal _run_command throws exception by default} );
    
# Telnet tests

if ( not ref $telnet_filer ) {
    print "# Skipping tests of telnet access.  Not configured\n";
    exit 0;
}

$filer			= NetApp::Filer->new( $telnet_filer );
isa_ok( $filer,		'NetApp::Filer' );

ok( $filer->_run_command( command => [qw( version )] ),
    'calling _run_command' );
ok( $filer->_get_command_status,
    'true status' );
@stderr		= $filer->_get_command_stderr;
@stdout		= $filer->_get_command_stdout;
ok( scalar @stderr == 0,	'no stderr');
ok( scalar @stdout == 1,	'one line in stdout' );

# NOTE: The error checking tests, based on calling "nosuch command"
# can NOT be made to work with Net::Telnet, because there is no
# generic error handling available via telnet, only ssh.