| 1 | package Net::SSH::Any::Test::Backend::_Base; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Net::SSH::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Net::SSH::Any::Constants qw(SSHA_BACKEND_ERROR SSHA_REMOTE_CMD_ERROR); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | our @CARP_NOT = qw(Net::SSH::Any::Test); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | sub _validate_backend_opts { 1 } | ||||||||||||||||||||||||||
|
Subroutine
_validate_backend_opts: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _stop { 1 } | ||||||||||||||||||||||||||
|
Subroutine
_stop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | my $dev_null = File::Spec->devnull; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub _dev_null { $dev_null } | ||||||||||||||||||||||||||
|
Subroutine
_dev_null: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub _new_ssh_client { | ||||||||||||||||||||||||||
|
Subroutine
_new_ssh_client: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($tssh, $uri) = @_; | |||||||||||||||||||||||||||
| 20 | 0 | $tssh->_log("Trying to connect to server at ".$uri->uri); | |||||||||||||||||||||||||||
| 21 | my $ssh = Net::SSH::Any->new($uri, | ||||||||||||||||||||||||||||
| 22 | batch_mode => 1, | ||||||||||||||||||||||||||||
| 23 | timeout => $tssh->{timeout}, | ||||||||||||||||||||||||||||
| 24 | backends => $tssh->{any_backends}, | ||||||||||||||||||||||||||||
| 25 | 0 | strict_host_key_checking => 0, | |||||||||||||||||||||||||||
| 26 | known_hosts_path => $tssh->_dev_null); | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($ssh->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $tssh->_log("Unable to establish SSH connection", $ssh->error, uri => $uri->as_string); | |||||||||||||||||||||||||||
| 29 | 0 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | $ssh | ||||||||||||||||||||||||||||
| 32 | 0 | } | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _check_and_set_uri { | ||||||||||||||||||||||||||
|
Subroutine
_check_and_set_uri: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($tssh, $uri) = @_; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | $uri //= $tssh->uri // return; | ||||||||||||||||||||||||||
|
Condition0%0/4
$uri //= $tssh->uri // (return)
$tssh->uri // (return)
MC/DC0%0/1
$uri //= $tssh->uri // (return)
$uri
Truth table0%0/2
A
A= $uri
| |||||||||||||||||||||||||||||
| 37 | 0 | $tssh->_log("Checking URI ".$uri->uri); | |||||||||||||||||||||||||||
| 38 | 0 | my $ssh; | |||||||||||||||||||||||||||
| 39 | 0 | for my $cmd (@{$tssh->{test_commands}}) { | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | $ssh //= $tssh->_new_ssh_client($uri) // return; | ||||||||||||||||||||||||||
|
Condition0%0/4
$ssh //= $tssh->_new_ssh_client($uri) // (return)
$tssh->_new_ssh_client($uri) // (return)
MC/DC0%0/1
$ssh //= $tssh->_new_ssh_client($uri) // (return)
$ssh
Truth table0%0/2
A
A= $ssh
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($out, $err) = $ssh->capture2($cmd); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (my $error = $ssh->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $tssh->_log("Running command '$cmd' failed, rc: $?, error: $error"); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | undef $ssh unless $error == SSHA_REMOTE_CMD_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (length $out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $out =~ s/\n?$/\n/; $out =~ s/^/out: /mg; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (length $err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $err =~ s/\n?$/\n/; $err =~ s/^/err: /mg; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | $tssh->_log("Running command '$cmd', rc: $?\n$out$err"); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $tssh->{good_uri} = $uri; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | return 1; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _cmd_to_name { | ||||||||||||||||||||||||||
|
Subroutine
_cmd_to_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($tssh, $cmd) = @_; | |||||||||||||||||||||||||||
| 64 | 0 | $cmd =~ s{.*[/\\]}{}; | |||||||||||||||||||||||||||
| 65 | 0 | $cmd =~ s{\.exe$}{}; | |||||||||||||||||||||||||||
| 66 | 0 | $cmd; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _run_cmd { | ||||||||||||||||||||||||||
|
Subroutine
_run_cmd: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($tssh, $opts, $cmd, @args) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $name = $opts->{out_name} // $tssh->_cmd_to_name($cmd); | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{"out_name"} // $tssh->_cmd_to_name($cmd)
MC/DC0%0/2
$opts->{"out_name"} // $tssh->_cmd_to_name($cmd)
$opts->{"out_name"}
$tssh->_cmd_to_name($cmd)
Truth table0%0/3
A // B
A= $opts->{"out_name"}B= $tssh->_cmd_to_name($cmd)
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $out_fn = $opts->{stdout_file} // $tssh->_log_fn($name); | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{"stdout_file"} // $tssh->_log_fn($name)
MC/DC0%0/2
$opts->{"stdout_file"} // $tssh->_log_fn($name)
$opts->{"stdout_file"}
$tssh->_log_fn($name)
Truth table0%0/3
A // B
A= $opts->{"stdout_file"}B= $tssh->_log_fn($name)
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $resolved_cmd = ($opts->{find} // 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
($opts->{"find"} // 1 ? $tssh->_be_find_cmd($cmd) : $cmd) // (return)
$opts->{"find"} // 1
MC/DC0%0/1
($opts->{"find"} // 1 ? $tssh->_be_find_cmd($cmd) : $cmd) // (return)
$opts->{"find"}
Truth table0%0/2
A
A= $opts->{"find"}
| |||||||||||||||||||||||||||||
| 74 | ? $tssh->_be_find_cmd($cmd) | ||||||||||||||||||||||||||||
| 75 | : $cmd) // return; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $tssh->_log("Running cmd: $resolved_cmd @args"); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (open my ($out_fh), '>>', $out_fn and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
open my $out_fh, ">>", $out_fn and open my $in_fh, "<", $tssh->_dev_null
MC/DC0%0/2
open my $out_fh, ">>", $out_fn and open my $in_fh, "<", $tssh->_dev_null
open my $out_fh, ">>", $out_fn
open my $in_fh, "<", $tssh->_dev_null
Truth table0%0/3
A and B
A= open my $out_fh, ">>", $out_fnB= open my $in_fh, "<", $tssh->_dev_null
| |||||||||||||||||||||||||||||
| 80 | open my ($in_fh), '<', $tssh->_dev_null) { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (my $proc = $tssh->_os_open4([$in_fh, $out_fh], [], undef, 1, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | $resolved_cmd => @args)) { | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $opts->{async} and return $proc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $tssh->_log("Waiting for process $proc->{pid} to finish"); | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $tssh->_os_wait_proc($proc, $opts->{timeout}, $opts->{force_kill}) and return 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | $tssh->_set_error(SSHA_BACKEND_ERROR, "Can't execute command $cmd: $!"); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | () | ||||||||||||||||||||||||||||
| 90 | 0 | } | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # _be_find_cmd first checks if the user has given us the exact command | ||||||||||||||||||||||||||||
| 93 | # location as a backend argument: | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | ▶ | sub _be_find_cmd { | ||||||||||||||||||||||||||
|
Subroutine
_be_find_cmd: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 96 | 3 | my $tssh = shift; | |||||||||||||||||||||||||||
| 97 | 3 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # if we have the opts argument, name is at $_[1], otherwise it is | ||||||||||||||||||||||||||||
| 100 | # at $_[0]: | ||||||||||||||||||||||||||||
| 101 | 3 | ▶ | my $safe_name = (ref $_[0] ? $_[1] : $_[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 3 | $safe_name =~ s/\W/_/g; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | $opts->{"local_${safe_name}_cmd"} //= | ||||||||||||||||||||||||||
|
Condition66%2/3
$$opts{"local_${safe_name}_cmd"} //= $tssh->_find_cmd(@_)
MC/DC50%1/2
$$opts{"local_${safe_name}_cmd"} //= $tssh->_find_cmd(@_)
$$opts{"local_${safe_name}_cmd"}
$tssh->_find_cmd(@_)
Truth table66%2/3
A //= B
A= $$opts{"local_${safe_name}_cmd"}B= $tssh->_find_cmd(@_)
| |||||||||||||||||||||||||||||
| 105 | $tssh->_find_cmd(@_); | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _is_localhost { 0 } | ||||||||||||||||||||||||||
|
Subroutine
_is_localhost: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 3 | 1; | |||||||||||||||||||||||||||