Remote/Net.pm

filter: Statementstmt 71.5% 73 / 102 Branchbran 43.7% 14 / 32 Conditioncond 35.2% 6 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 76.9% 10 / 13 Podpod 100% 6 / 6 totaltotal 60.5% 109 / 180 CC 26 SCAR 23.5
CC
26
Cov
62%
mcp_send
21.5
tap_report_away
12.0
nfs_mount
12.0
CRAP 10.5
↑ Summary Remote/Config.pm »
1 package Tapper::Remote::Net;
2 2 our $AUTHORITY = 'cpan:TAPPER';
3 2 $Tapper::Remote::Net::VERSION = '5.0.0';
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 requires qw(cfg log);
10  
11 2 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 sub mcp_inform
17 1 ▶{
Subroutine mcp_inform: called CC=3 SCAR=11.8
Pod documented
18  
19 1 my ($self, $msg) = @_;
20  
21 1 ▶ $msg = {state => $msg} if not ref($msg) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $msg eq "HASH" 1 0 1
22  
23 # set PRC number
24 1 ▶ if ($self->cfg->{guest_number}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{'guest_number'}) { } 0 1 1
25 0 $msg->{prc_number} = $self->{cfg}->{guest_number};
26 } else {
27 # guest numbers start with 1, 0 is host or no virtualisation
28 1 $msg->{prc_number} = 0;
29 }
30 1 return $self->mcp_send($msg);
31 };
32  
33  
34  
35 sub mcp_send
36 1 ▶{
Subroutine mcp_send: called CC=12 SCAR=30.7
Pod documented
37 1 my ($self, $message) = @_;
38 1 ▶ my $server = $self->cfg->{mcp_host} || $self->cfg->{mcp_server} or return "MCP host unknown";
Branch: 1 branch
BranchTrueFalseTotal
my $server = $self->cfg->{"mcp_host"} || $self->cfg->{"mcp_server"} or return "MCP host unknown" 1 0 1
Condition33%1/3
$self->cfg->{'mcp_host'} || $self->cfg->{'mcp_server'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->cfg->{'mcp_host'} || $self->cfg->{'mcp_server'}
$self->cfg->{'mcp_host'} $self->cfg->{'mcp_server'}
Truth table33%1/3
A || B
A= $self->cfg->{'mcp_host'}B= $self->cfg->{'mcp_server'}
ABresult
1X1
011
000
39 1 ▶ my $port = $self->cfg->{mcp_port} || $self->cfg->{port} or return "MCP port unknown";
Branch: 1 branch
BranchTrueFalseTotal
my $port = $self->cfg->{"mcp_port"} || $self->cfg->{"port"} or return "MCP port unknown" 1 0 1
Condition33%1/3
$self->cfg->{'mcp_port'} || $self->cfg->{'port'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->cfg->{'mcp_port'} || $self->cfg->{'port'}
$self->cfg->{'mcp_port'} $self->cfg->{'port'}
Truth table33%1/3
A || B
A= $self->cfg->{'mcp_port'}B= $self->cfg->{'port'}
ABresult
1X1
011
000
40 1 ▶ $message->{testrun_id} ||= $self->cfg->{testrun_id} || $self->cfg->{test_run};
Condition33%2/6
$message->{"testrun_id"} ||= $self->cfg->{"testrun_id"} || $self->cfg->{"test_run"}
l!l&&r!l&&!r
010
$self->cfg->{'testrun_id'} || $self->cfg->{'test_run'}
l!l&&r!l&&!r
100
MC/DC0%0/3
$message->{"testrun_id"} ||= $self->cfg->{"testrun_id"} || $self->cfg->{"test_run"}
$message->{"testrun_id"} $self->cfg->{'testrun_id'} $self->cfg->{'test_run'}
Truth table0%0/4
A ||= B || C
A= $message->{"testrun_id"}B= $self->cfg->{'testrun_id'}C= $self->cfg->{'test_run'}
ABCresult
1XX1
01X1
0011
0000
41 1 my %headers;
42  
43 1 my $url = "GET /state/";
44  
45 # state always needs to be first URL part because server uses it as filter
46 1 ▶ $url .= $message->{state} || 'unknown';
Condition50%1/2
$message->{'state'} || 'unknown'
l!l
10
MC/DC0%0/1
$message->{'state'} || 'unknown'
$message->{'state'}
Truth table50%1/2
A
A= $message->{'state'}
Aresult
11
00
47 1 delete $message->{state};
48  
49 1 foreach my $key (keys %$message) {
50 2 ▶ if ($message->{$key} =~ m|/| ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->{$key} =~ m[/]) { } 0 2 2
51 0 $headers{$key} = $message->{$key};
52 } else {
53 2 $url .= "/$key/";
54 2 $url .= uri_escape($message->{$key});
55 }
56 }
57 1 $url .= " HTTP/1.0\r\n";
58 1 foreach my $header (keys %headers) {
59 0 $url .= "X-Tapper-$header: ";
60 0 $url .= $headers{$header};
61 0 $url .= "\r\n";
62 }
63  
64 1 $self->log->info("Sending $url to $server");
65 1 ▶ if (my $sock = IO::Socket::INET->new(PeerAddr => $server,
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = 'IO::Socket::INET'->new('PeerAddr', $server, 'PeerPort', $port, 'Proto', 'tcp')) { } 1 0 1
66 PeerPort => $port,
67 Proto => 'tcp')){
68 1 $sock->print("$url\r\n");
69 1 close $sock;
70 } else {
71 0 $self->log->error("Can't connect to MCP on $server:$port: $@");
72 0 return("Can't connect to MCP: $!");
73 }
74 1 return(0);
75 }
76  
77  
78  
79 sub tap_report_away
80 0 ▶{
Subroutine tap_report_away: not called CC=3 SCAR=24.8
Pod documented
81 0 my ($self, $tap) = @_;
82 0 my $reportid;
83 0 ▶ if (my $sock = IO::Socket::INET->new(PeerAddr => $self->cfg->{report_server},
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = 'IO::Socket::INET'->new('PeerAddr', $self->cfg->{'report_server'}, 'PeerPort', $self->cfg->{'report_port'}, 'Proto', 'tcp')) { } 0 0 0
84 PeerPort => $self->cfg->{report_port},
85 Proto => 'tcp')) {
86 0 eval{
87 0 my $timeout = 100;
88 0 ▶ local $SIG{ALRM}=sub{die("timeout for sending tap report ($timeout seconds) reached.");};
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 alarm($timeout);
90 0 ($reportid) = <$sock> =~m/(\d+)$/g;
91 0 $sock->print($tap);
92 };
93 0 alarm(0);
94 0 ▶ $self->log->error($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
95 0 close $sock;
96 } else {
97 0 return(1,"Can not connect to report server: $!");
98 }
99 0 return (0,$reportid);
100  
101 }
102  
103  
104  
105 sub tap_report_create
106 1 ▶{
Subroutine tap_report_create: called CC=5 SCAR=16.1
Pod documented
107 1 my ($self, $report) = @_;
108 1 my $message;
109 1 my @tests = @{$report->{tests}};
110  
111 1 $message .= "1..".int (@tests);
112 1 $message .= "\n";
113 1 foreach my $header (keys %{$report->{headers}}) {
114 2 $message .= "# $header: ";
115 2 $message .= $report->{headers}->{$header};
116 2 $message .= "\n";
117 }
118  
119 # @tests starts with 0, reports start with 1
120 1 ▶ for (my $i=1; $i<=@tests; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= @tests) 2 1 3
121 2 ▶ $message .= "not " if $tests[$i-1]->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $tests[$i - 1]{"error"} 1 1 2
122 2 $message .="ok $i - ";
123 2 ▶ $message .= $tests[$i-1]->{test} if $tests[$i-1]->{test};
Branch: 1 branch
BranchTrueFalseTotal
if $tests[$i - 1]{"test"} 2 0 2
124 2 $message .="\n";
125 }
126 1 return ($message);
127 }
128  
129  
130 sub nfs_mount
131 0 ▶{
Subroutine nfs_mount: not called CC=3 SCAR=24.8
Pod documented
132 0 my ($self) = @_;
133 0 my ($error, $retval);
134 0 $error = $self->makedir($self->cfg->{paths}{prc_nfs_mountdir});
135 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
136  
137 ($error, $retval) = $self->log_and_exec("mount",
138 $self->cfg->{prc_nfs_server}.":".$self->cfg->{paths}{prc_nfs_mountdir},
139 0 $self->cfg->{paths}{prc_nfs_mountdir});
140 0 ▶ return "Can't mount ".$self->cfg->{paths}{prc_nfs_mountdir}.":$retval" if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
141 0 return 0;
142 }
143  
144  
145 sub log_to_file
146 1 ▶{
Subroutine log_to_file: called CC=5 SCAR=17.0
Pod documented
147  
148 1 my ($self, $state) = @_;
149 1 my $output = $self->cfg->{paths}{output_dir};
150 1 ▶ $output .= "/".($self->cfg->{testrun_id} || $self->cfg->{test_run});
Condition33%1/3
$self->cfg->{'testrun_id'} || $self->cfg->{'test_run'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->cfg->{'testrun_id'} || $self->cfg->{'test_run'}
$self->cfg->{'testrun_id'} $self->cfg->{'test_run'}
Truth table33%1/3
A || B
A= $self->cfg->{'testrun_id'}B= $self->cfg->{'test_run'}
ABresult
1X1
011
000
151 1 $output .= "/$state";
152  
153 1 my $error = $self->makedir ($output);
154 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
155  
156 1 $output .= "/Tapper";
157 1 ▶ open (STDOUT, ">>", "$output.stdout") or $self->logdie("Can't open output file $output.stdout: $!");
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">>", "$output.stdout" or $self->logdie("Can't open output file $output.stdout: $!") 1 0 1
158 1 ▶ open (STDERR, ">>", "$output.stderr") or $self->logdie("Can't open output file $output.stderr: $!");
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">>", "$output.stderr" or $self->logdie("Can't open output file $output.stderr: $!") 1 0 1
159 1 return 0;
160 }
161  
162 2 1;
163  
164 __END__
↑ Summary Remote/Config.pm »