lib/Rex/Pkg/SunOS.pm

filter: Statementstmt 25.6% 19 / 74 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 4 totaltotal 20.8% 25 / 120 CC 16 SCAR 35.6
CC
16
Cov
18%
get_installed
72.0
update
42.0
remove
12.0
CRAP 35.3
« lib/Rex/Virtualization/VBox/import.pm ↑ Summary lib/Rex/Interface/Exec/SSH.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Pkg::SunOS;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Pkg::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base qw(Rex::Pkg::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $that = shift;
19 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
20 0 my $self = $proto->SUPER::new(@_);
21  
22 0 bless( $self, $proto );
23  
24 0 $self->{commands} = {};
25  
26 0 return $self;
27 }
28  
29 0 ▶sub update {
Subroutine update: not called CC=6 SCAR=37.4
Pod undocumented
30 0 my ( $self, $pkg, $option ) = @_;
31  
32 0 ▶ my $version = $option->{'version'} || '';
Condition0%0/2
$option->{'version'} || ''
l!l
00
MC/DC0%0/1
$option->{'version'} || ''
$option->{'version'}
Truth table0%0/2
A
A= $option->{'version'}
Aresult
11
00
33  
34 0 Rex::Logger::debug("Version option not supported.");
35 0 Rex::Logger::debug("Installing $pkg / $version");
36  
37 0 my $cmd = "pkgadd ";
38  
39 0 ▶ if ( !exists $option->{"source"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $option->{"source"}) 0 0 0
40 0 die("You have to specify the source.");
41 }
42  
43 0 ▶ $cmd .= " -a " . $option->{"adminfile"} if ( $option->{"adminfile"} );
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"adminfile"} 0 0 0
44 0 ▶ $cmd .= " -r " . $option->{"responsefile"} if ( $option->{"responsefile"} );
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"responsefile"} 0 0 0
45  
46 0 $cmd .= " -d " . $option->{"source"};
47 0 $cmd .= " -n " . $pkg;
48  
49 0 my $f = i_run( $cmd, fail_ok => 1 );
50  
51 0 ▶ unless ( $? == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? == 0) 0 0 0
52 0 Rex::Logger::info( "Error installing $pkg.", "warn" );
53 0 Rex::Logger::debug($f);
54 0 die("Error installing $pkg");
55 }
56  
57 0 Rex::Logger::debug("$pkg successfully installed.");
58  
59 0 return 1;
60 }
61  
62 0 ▶sub remove {
Subroutine remove: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my ( $self, $pkg, $option ) = @_;
64  
65 0 Rex::Logger::debug("Removing $pkg");
66  
67 0 my $cmd = "pkgrm -n ";
68 0 ▶ $cmd .= " -a " . $option->{"adminfile"} if ( $option->{"adminfile"} );
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"adminfile"} 0 0 0
69  
70 0 my $f = i_run( $cmd . " $pkg", fail_ok => 1 );
71  
72 0 ▶ unless ( $? == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? == 0) 0 0 0
73 0 Rex::Logger::info( "Error removing $pkg.", "warn" );
74 0 Rex::Logger::debug($f);
75 0 die("Error removing $pkg");
76 }
77  
78 0 Rex::Logger::debug("$pkg successfully removed.");
79  
80 0 return 1;
81 }
82  
83 0 ▶sub get_installed {
Subroutine get_installed: not called CC=8 SCAR=42.8
Pod undocumented
84 0 my ($self) = @_;
85  
86 0 my @lines = i_run "pkginfo -l";
87  
88 0 my ( @pkg, %current );
89  
90 0 for my $line (@lines) {
91 0 ▶ if ( $line =~ m/^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^$/u) 0 0 0
92 0 push( @pkg, {%current} );
93 0 next;
94 }
95  
96 0 ▶ if ( $line =~ m/PKGINST:\s+([^\s]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /PKGINST:\s+([^\s]+)/u) 0 0 0
97 0 $current{"name"} = $1;
98 0 next;
99 }
100  
101 0 ▶ if ( $line =~ m/VERSION:\s+([^\s]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /VERSION:\s+([^\s]+)/u) 0 0 0
102 0 my ( $version, $rev ) = split( /,/, $1 );
103 0 $current{"version"} = $version;
104 0 ▶ $rev =~ s/^REV=// if ($rev);
Branch: 1 branch
BranchTrueFalseTotal
if $rev 0 0 0
105 0 $current{"revision"} = $rev;
106 0 next;
107 }
108  
109 0 ▶ if ( $line =~ m/STATUS:\s+(.*?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /STATUS:\s+(.*?)$/u) 0 0 0
110 0 ▶ $current{"status"} = ( $1 eq "completely installed" ? "installed" : $1 );
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'completely installed' ? : 0 0 0
111 0 next;
112 }
113  
114 }
115  
116 0 return @pkg;
117 }
118  
119 1 1;
« lib/Rex/Virtualization/VBox/import.pm ↑ Summary lib/Rex/Interface/Exec/SSH.pm »