| 1 | package TAP::Parser::Iterator::Worker::SSH; | ||
| 2 | use strict; | ||
| 3 | use File::Spec; | ||
| 4 | |||
| 5 | use TAP::Parser::Iterator::Worker (); | ||
| 6 | use TAP::Parser::SourceHandler::Worker::SSH (); | ||
| 7 | use vars qw($VERSION @ISA); | ||
| 8 | @ISA = 'TAP::Parser::Iterator::Worker'; | ||
| 9 | |||
| 10 | =head1 DESCRIPTION | ||
| 11 | |||
| 12 | This is the SSH iterator worker. | ||
| 13 | The ssh to the specified hosts must be able | ||
| 14 | to be ssh to by the user without authenticate | ||
| 15 | by password. | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | # new() implementation supplied by TAP::Object | ||
| 20 | |||
| 21 | sub _initialize { | ||
| 22 | my ( $self, $args ) = @_; | ||
| 23 | $self->SUPER::_initialize($args); | ||
| 24 | |||
| 25 | =cut | ||
| 26 | my $out = $self->{out}; | ||
| 27 | my $pid = <$out>; | ||
| 28 | if ( $pid ) { | ||
| 29 | $self->{ssh_pid} = $pid; | ||
| 30 | } | ||
| 31 | else { | ||
| 32 | print STDERR "failed to start an SSH job.\n"; | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | =cut | ||
| 36 | |||
| 37 | return $self; | ||
| 38 | } | ||
| 39 | |||
| 40 | =head1 NAME | ||
| 41 | |||
| 42 | TAP::Parser::Iterator::Worker::SSH - Iterator for SSH worker TAP sources | ||
| 43 | |||
| 44 | =head1 VERSION | ||
| 45 | |||
| 46 | Version 0.03 | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | $VERSION = '0.03'; | ||
| 51 | |||
| 52 | =head3 C<initialize_worker_command> | ||
| 53 | |||
| 54 | Initialize the command to be used to initialize worker. | ||
| 55 | |||
| 56 | For your specific command, you can subclass this to put your command in this method. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | sub initialize_worker_command { | ||
| 61 | my $self = shift; | ||
| 62 | my $commands = $self->SUPER::initialize_worker_command; | ||
| 63 | my $hostname = TAP::Parser::SourceHandler::Worker::SSH->get_next_host(); | ||
| 64 | my $cwd = File::Spec->rel2abs('.'); | ||
| 65 | |||
| 66 | my $escaped_command = "cd $cwd;" . $commands->[0]; | ||
| 67 | $escaped_command =~ s/'/'"'"'/g; | ||
| 68 | $commands->[0] = "ssh $hostname '" . $escaped_command . "'"; | ||
| 69 | $self->{host} = $hostname; | ||
| 70 | return $commands; | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ |