Commit 21e32adf authored by Kevin Tew's avatar Kevin Tew
Browse files

testsuite/testswap cmdsuccess_stdin

parent 9e0ac444
...@@ -23,13 +23,13 @@ sub instance { ...@@ -23,13 +23,13 @@ sub instance {
} }
sub wrapped_ssh { sub wrapped_ssh {
my ($invocant, $user, $cmd, $checker, $diemessage) = @_; my ($invocant, $user, $cmd, $checker, $diemessage, $stdin) = @_;
my $ssh; my $ssh;
if (ref $invocant) { $ssh = $invocant } if (ref $invocant) { $ssh = $invocant }
else { else {
$ssh = Tools::TBSSH->new('host' => $invocant, 'user' => $user); $ssh = Tools::TBSSH->new('host' => $invocant, 'user' => $user);
} }
my @results = $ssh->cmd($cmd); my @results = $ssh->cmd($cmd, $stdin);
if ($TBConfig::DEBUG_XML_CLIENT) { if ($TBConfig::DEBUG_XML_CLIENT) {
$ssh->saydebug($cmd); $ssh->saydebug($cmd);
sayd @results; sayd @results;
...@@ -64,6 +64,11 @@ sub cmdsuccess { ...@@ -64,6 +64,11 @@ sub cmdsuccess {
return wrapped_ssh($host, $TBConfig::EMULAB_USER, $cmd, sub { $_[2] == 0; }, $diemessage); return wrapped_ssh($host, $TBConfig::EMULAB_USER, $cmd, sub { $_[2] == 0; }, $diemessage);
} }
sub cmdsuccess_stdin {
my ($host, $cmd, $stdin, $diemessage) = @_;
return wrapped_ssh($host, $TBConfig::EMULAB_USER, $cmd, sub { $_[2] == 0; }, $diemessage, $stdin);
}
sub cmdoutput { sub cmdoutput {
my ($host, $cmd, $diemessage) = @_; my ($host, $cmd, $diemessage) = @_;
my @results = wrapped_ssh($host, $TBConfig::EMULAB_USER, $cmd, sub { $_[2] == 0; }, $diemessage ); my @results = wrapped_ssh($host, $TBConfig::EMULAB_USER, $cmd, sub { $_[2] == 0; }, $diemessage );
......
...@@ -10,13 +10,13 @@ has 'host' => ( isa => 'Str', is => 'rw'); ...@@ -10,13 +10,13 @@ has 'host' => ( isa => 'Str', is => 'rw');
has 'user' => ( isa => 'Str', is => 'rw'); has 'user' => ( isa => 'Str', is => 'rw');
sub cmd { sub cmd {
my ($ssh, $cmd) = @_; my ($ssh, $cmd, $stdin) = @_;
my $out; my $out;
my $err; my $err;
my $host = $ssh->host; my $host = $ssh->host;
my $user = $ssh->user; my $user = $ssh->user;
my $sshcmd = "ssh -x -o BatchMode=yes -o StrictHostKeyChecking=no $user\@$host $cmd"; my $sshcmd = "ssh -x -o BatchMode=yes -o StrictHostKeyChecking=no $user\@$host $cmd";
run3($sshcmd, undef, \$out, \$err); run3($sshcmd, \$stdin, \$out, \$err);
my $rc = $? >> 8; my $rc = $? >> 8;
($out, $err, $rc); ($out, $err, $rc);
} }
......
...@@ -4,7 +4,7 @@ use TBConfig; ...@@ -4,7 +4,7 @@ use TBConfig;
use Tools; use Tools;
use Tools::TBSSH; use Tools::TBSSH;
use Data::Dumper; use Data::Dumper;
use Test::More tests => 6; use Test::More tests => 7;
ok(0 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'ssh ops hostname'); ok(0 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'ssh ops hostname');
ok(1 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "false", sub { $_[2] } )]->[0], 'ssh ops false return code'); ok(1 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "false", sub { $_[2] } )]->[0], 'ssh ops false return code');
...@@ -17,3 +17,5 @@ ok(0 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "hostname", sub { $ ...@@ -17,3 +17,5 @@ ok(0 == [Tools::TBSSH::cmdcheckoutput($TBConfig::OPS_SERVER, "hostname", sub { $
#test #test
ok(0 == [$ssh->cmdsuccess("hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'cmdsuccess(..) test'); ok(0 == [$ssh->cmdsuccess("hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'cmdsuccess(..) test');
ok(0 == [$ssh->cmdsuccessdump("hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'cmdsuccessdump(..) test'); ok(0 == [$ssh->cmdsuccessdump("hostname", sub { $_[0] =~ /ops.emulab.net/; } )]->[0], 'cmdsuccessdump(..) test');
ok(0 == [$ssh->cmdsuccess_stdin("python -", 'print "Hello"' )]->[0], 'python stdin Hello test');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment