| 1 | package Clustericious::Admin::RemoteHandler; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 39 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 39 | ▶ | use AE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 39 | ▶ | use AnyEvent::Open3::Simple 0.76; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 39 | our $VERSION = '1.11'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 30 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 30 | my($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # args: prefix, clad, user, host, payload | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | prefix => $args{prefix}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | clad => $args{clad}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | cv => AE::cv, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | summary => $args{clad}->summary, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 30 | }, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 30 | my $clad = $args{clad}; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # TODO: handle the same host multiple times | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 30 | ▶ | if($clad->log_dir) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $fn = $clad->log_dir->file($args{prefix} . ".log"); | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | open(my $fh, '>', "$fn") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | || die "unable to write to $fn $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | $self->{logfile} = $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | $self->{logfilename} = $fn; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 30 | my $done = $self->{cv}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | my $ipc = AnyEvent::Open3::Simple->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 30 | ▶ | on_start => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 30 | my($proc, $program, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 30 | ▶ | $self->print_line(star => "% $program @args") if $clad->verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 35 | ▶ | on_stdout => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 35 | my($proc, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 35 | $self->print_line(out => $line); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | on_stderr => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | my($proc, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | $self->print_line(err => $line); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 30 | ▶ | on_exit => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 30 | my($proc, $exit, $signal) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 30 | ▶ | $self->print_line(exit => $exit) if ($self->summary && !$signal) || $exit; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->summary and not $signal or $exit
$self->summary and not $signal
MC/DC66%2/3
$self->summary and not $signal or $exit
$self->summary
not $signal
$exit
Truth table60%3/5
A and not(B) or C
A= $self->summaryB= not $signalC= $exit
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 30 | ▶ | $self->print_line(sig => $signal) if $signal; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 30 | ▶ | $clad->ret(2) if $exit || $signal; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$exit or $signal
MC/DC50%1/2
$exit or $signal
$exit
$signal
Truth table66%2/3
A or B
A= $exitB= $signal
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 30 | $self->cleanup; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my($error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->print_line(fail => $error); | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $clad->ret(2); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->cleanup; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 30 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $ipc->run( | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $clad->ssh_command, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $clad->ssh_options, | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $clad->ssh_extra, | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ($args{user} ? ('-l' => $args{user}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $args{host}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $clad->server_command, | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | \$args{payload}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 30 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 30 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 69 | ▶ | sub clad { shift->{clad} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clad: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 41 | ▶ | sub prefix { shift->{prefix} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 77 | ▶ | sub summary { shift->{summary} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 80 | ▶ | sub logfile { shift->{logfile} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logfile: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub logfilename { shift->{logfilename} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logfilename: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub cleanup | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 30 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanup: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 30 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 30 | ▶ | $self->logfile->close if $self->logfile; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 30 | $self->{cv}->send; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | sub color | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
color: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $self->{color} //= $self->clad->next_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"color"} //= $self->clad->next_color
MC/DC0%0/2
$self->{"color"} //= $self->clad->next_color
$self->{"color"}
$self->clad->next_color
Truth table0%0/3
A //= B
A= $self->{"color"}B= $self->clad->next_color
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | sub is_color | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 88 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_color: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 88 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 88 | ▶ | $self->{is_color} //= $self->clad->color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"is_color"} //= $self->clad->color
MC/DC0%0/2
$self->{"is_color"} //= $self->clad->color
$self->{"is_color"}
$self->clad->color
Truth table66%2/3
A //= B
A= $self->{"is_color"}B= $self->clad->color
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | sub print_line | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 47 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_line: called CC=18 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 47 | my($self, $code, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 47 | my $fh = $self->logfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 47 | ▶ | printf $fh "[%-4s] %s\n", $code, $line | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | if $fh; | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 47 | my $last_line = $code =~ /^(exit|sig|fail)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 47 | ▶ | return if $self->summary && ! $last_line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->summary and not $last_line
MC/DC100%2/2
$self->summary and not $last_line
$self->summary
not $last_line
Truth table100%3/3
A and not(B)
A= $self->summaryB= not $last_line
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 41 | ▶ | if($last_line && $line ne '0') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$last_line and $line ne 0
MC/DC100%2/2
$last_line and $line ne 0
$last_line
$line ne 0
Truth table100%3/3
A and B
A= $last_lineB= $line ne 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | print Term::ANSIColor::color($self->clad->fail_color) if $self->is_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 37 | ▶ | print Term::ANSIColor::color($self->color) if $self->is_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 41 | printf "[%@{[ $self->clad->host_length ]}s %-4s] ", $self->prefix, $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 41 | ▶ | if(! $last_line) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 35 | ▶ | if($code eq 'err') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | print Term::ANSIColor::color($self->clad->err_color) if $self->is_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 29 | ▶ | print Term::ANSIColor::color('reset') if $self->is_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 41 | print $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 41 | ▶ | if($last_line || $code eq 'err') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$last_line or $code eq "err"
MC/DC100%2/2
$last_line or $code eq "err"
$last_line
$code eq "err"
Truth table100%3/3
A or B
A= $last_lineB= $code eq "err"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | ▶ | print Term::ANSIColor::color('reset') if $self->is_color; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 41 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 41 | ▶ | if($fh && $last_line && $line ne '0') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$fh and $last_line and $line ne 0
$fh and $last_line
MC/DC0%0/3
$fh and $last_line and $line ne 0
$fh
$last_line
$line ne 0
Truth table50%2/4
A and B and C
A= $fhB= $last_lineC= $line ne 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | print ' ' x ($self->clad->host_length +8), "see @{[ $self->logfilename ]}\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 30 | ▶ | sub cv { shift->{cv} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cv: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 39 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||