lib/Tapper/Installer/Precondition/Exec.pm

filter: Statementstmt 86.2% 69 / 80 Branchbran 50.0% 13 / 26 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 74.8% 95 / 127 CC 17 SCAR 29.9
CC
17
Cov
75%
install
27.7
BEGIN
1.0
BEGIN
1.0
CRAP 19.9
« lib/Tapper/Installer/Precondition/Package.pm ↑ Summary lib/Tapper/Installer/Precondition/Copyfile.pm »
1 package Tapper::Installer::Precondition::Exec;
2 10 our $AUTHORITY = 'cpan:TAPPER';
3 10 $Tapper::Installer::Precondition::Exec::VERSION = '5.0.3';
4 10 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use IO::Handle; # needed to set pipe nonblocking
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 extends 'Tapper::Installer::Precondition';
13  
14  
15  
16  
17 sub set_env_variables
18 2 ▶{
Subroutine set_env_variables: called CC=1 SCAR=0.0
Pod documented
19 2 my ($self) = @_;
20  
21 2 $ENV{TAPPER_TESTRUN} = $self->cfg->{test_run};
22 2 $ENV{TAPPER_SERVER} = $self->cfg->{mcp_host};
23 2 $ENV{TAPPER_REPORT_SERVER} = $self->cfg->{report_server};
24 2 $ENV{TAPPER_REPORT_API_PORT} = $self->cfg->{report_api_port};
25 2 $ENV{TAPPER_REPORT_PORT} = $self->cfg->{report_port};
26 2 $ENV{TAPPER_HOSTNAME} = $self->cfg->{hostname};
27 2 return;
28 }
29  
30  
31 sub install
32 4 ▶{
Subroutine install: called CC=17 SCAR=33.2
Pod documented
33 4 my ($self, $exec) = @_;
34  
35 4 my $command = $exec->{command};
36 4 my @options;
37 4 ▶ @options = @{$exec->{options}} if $exec->{options};
Branch: 1 branch
BranchTrueFalseTotal
if $exec->{"options"} 2 2 4
38  
39 4 ▶ if ($exec->{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exec->{"filename"}) 0 4 4
40 0 $command = $exec->{filename};
41 0 my $cmd_full = $self->cfg->{paths}{base_dir}.$command;
42 0 ▶ if (not -x $cmd_full) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $cmd_full) 0 0 0
43 0 $self->log_and_exec ("chmod", "ugo+x", $cmd_full);
44 0 ▶ return("tried to execute $cmd_full which is not an execuable and can not set exec flag") if not -x $cmd_full;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $cmd_full 0 0 0
45 }
46 }
47  
48 4 $self->log->debug("executing $command with options ",join (" ",@options));
49  
50  
51 4 pipe (my $read, my $write);
52 4 ▶ return ("Can't open pipe:$!") if not (defined $read and defined $write);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read and defined $write 0 4 4
Condition33%1/3
defined $read and defined $write
!ll&&!rl&&r
004
MC/DC0%0/2
defined $read and defined $write
defined $read defined $write
Truth table33%1/3
A and B
A= defined $readB= defined $write
ABresult
0X0
100
111
53  
54 # we need to fork for chroot
55 4 my $pid = fork();
56 4 ▶ return "fork failed: $!" if not defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 4 4
57  
58 # hello child
59 4 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) { } 2 2 4
60 2 $self->set_env_variables;
61  
62 2 close $read;
63 # chroot to execute script inside the future root file system
64 2 my ($error, $output) = $self->log_and_exec("mount -o bind /dev/ ".$self->cfg->{paths}{base_dir}."/dev");
65 2 ($error, $output) = $self->log_and_exec("mount -t sysfs sys ".$self->cfg->{paths}{base_dir}."/sys");
66 2 ($error, $output) = $self->log_and_exec("mount -t proc proc ".$self->cfg->{paths}{base_dir}."/proc");
67 2 ▶ my $arch = $exec->{arch} // "";
Condition50%1/2
$exec->{"arch"} // ""
l!l
02
MC/DC0%0/1
$exec->{"arch"} // ""
$exec->{"arch"}
Truth table50%1/2
A
A= $exec->{"arch"}
Aresult
11
00
68 2 ▶ if ($arch eq 'linux32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arch eq "linux32") 0 2 2
69 0 Linux::Personality::personality(Linux::Personality::PER_LINUX32());
70 }
71 2 chroot $self->cfg->{paths}{base_dir};
72 2 chdir ("/");
73 2 ▶ %ENV = (%ENV, %{$exec->{environment} || {} });
Condition50%1/2
$exec->{'environment'} || {}
l!l
02
MC/DC0%0/1
$exec->{'environment'} || {}
$exec->{'environment'}
Truth table50%1/2
A
A= $exec->{'environment'}
Aresult
11
00
74 2 ($error, $output)=$self->log_and_exec($command,@options);
75 2 ▶ print( $write $output, "\n") if $output;
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 2 2
76 2 close $write;
77 2 exit $error;
78 } else {
79 2 close $write;
80 2 my $select = IO::Select->new( $read );
81 2 my ($error, $output);
82 MSG_FROM_CHILD:
83 2 ▶ while (my @ready = $select->can_read()){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@ready) = $select->can_read) 2 0 2
84 2 my $tmpout = <$read>; # only read can be in @ready, since no other FH is in $select
85 2 ▶ last MSG_FROM_CHILD if not $tmpout;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpout 2 0 2
86 0 $output.=$tmpout;
87 }
88 2 ▶ if ($output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output) 0 2 2
89 0 my $outfile = $command;
90 0 $outfile =~ s/[^A-Za-z_-]/_/g;
91 0 $self->file_save($output,$outfile);
92 }
93 2 ($error, $output)=$self->log_and_exec("umount ".$self->cfg->{paths}{base_dir}."/dev");
94 2 ($error, $output)=$self->log_and_exec("umount ".$self->cfg->{paths}{base_dir}."/sys");
95 2 ($error, $output)=$self->log_and_exec("umount ".$self->cfg->{paths}{base_dir}."/proc");
96 2 waitpid($pid,0);
97 2 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 2 2
98 0 return("executing $command failed");
99 }
100 2 return(0);
101 }
102 }
103  
104  
105  
106 10 1;
107  
108 __END__
« lib/Tapper/Installer/Precondition/Package.pm ↑ Summary lib/Tapper/Installer/Precondition/Copyfile.pm »