lib/Rex/Pkg/Redhat.pm

filter: Statementstmt 69.2% 72 / 104 Branchbran 40.9% 9 / 22 Conditioncond 33.3% 3 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 6 totaltotal 59.0% 95 / 161 CC 23 SCAR 25.9
CC
23
Cov
62%
add_repository
42.0
diff_package_list
13.0
get_installed
12.0
CRAP 13.4
« lib/Rex/Test/Base.pm ↑ Summary lib/Rex/Pkg/SunOS/pkg.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Pkg::Redhat;
6  
7 2 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.16.1'; # VERSION
11  
12 2 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Rex::Pkg::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use base qw(Rex::Pkg::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod undocumented
19 1 my $that = shift;
20 1 ▶ my $proto = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
21 1 my $self = $proto->SUPER::new(@_);
22  
23 1 bless( $self, $proto );
24  
25 1 ▶ if ( Rex::has_feature_version('1.5') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Rex::has_feature_version('1.5')) { } 0 1 1
26 $self->{commands} = {
27 0 install => $self->_yum('-y install %s'),
28 install_version => $self->_yum('-y install %s-%s'),
29 update_system => $self->_yum("-y -C upgrade"),
30 dist_update_system => $self->_yum("-y -C upgrade"),
31 remove => $self->_yum('-y erase %s'),
32 update_package_db => $self->_yum("clean all") . " ; "
33 . $self->_yum("makecache"),
34 };
35 }
36 else {
37 $self->{commands} = {
38 1 install => $self->_yum('-y install %s'),
39 install_version => $self->_yum('-y install %s-%s'),
40 update_system => $self->_yum("-y upgrade"),
41 dist_update_system => $self->_yum("-y upgrade"),
42 remove => $self->_yum('-y erase %s'),
43 update_package_db => $self->_yum("clean all") . " ; "
44 . $self->_yum("makecache"),
45 };
46 }
47  
48 1 return $self;
49 }
50  
51 0 ▶sub bulk_install {
Subroutine bulk_install: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my ( $self, $packages_aref, $option ) = @_;
53  
54 0 delete $option->{version}; # makes no sense to specify the same version for several packages
55  
56 0 $self->update( "@{$packages_aref}", $option );
57  
58 0 return 1;
59 }
60  
61 0 ▶sub get_installed {
Subroutine get_installed: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my ($self) = @_;
63  
64 0 my @lines = i_run
65 'rpm -qa --nosignature --nodigest --qf "%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n"';
66  
67 0 my @pkg;
68  
69 0 for my $line (@lines) {
70 0 ▶ if ( $line =~ m/^([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s(.*)$/u) 0 0 0
71 0 push(
72 @pkg,
73 {
74 name => $1,
75 epoch => $2,
76 version => $3,
77 release => $4,
78 arch => $5,
79 }
80 );
81 }
82 }
83  
84 0 return @pkg;
85 }
86  
87 1 ▶sub diff_package_list {
Subroutine diff_package_list: called CC=13 SCAR=25.7
Pod undocumented
88 1 my ( $self, $list1, $list2 ) = @_;
89  
90 1 my @old_installed = @{$list1};
91 1 my @new_installed = @{$list2};
92  
93 1 my @modifications;
94  
95 my %old_installed;
96 1 foreach my $old_pkg (@old_installed) {
97 3 my $name = $old_pkg->{name};
98 3 my $version = "$old_pkg->{version} $old_pkg->{release}";
99 3 $old_installed{$name}{$version} = $old_pkg;
100 }
101  
102 1 my %new_installed;
103 1 foreach my $new_pkg (@new_installed) {
104 3 my $name = $new_pkg->{name};
105 3 my $version = "$new_pkg->{version} $new_pkg->{release}";
106 3 ▶ if ( $old_installed{$name} and $old_installed{$name}{$version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_installed{$name} and $old_installed{$name}{$version}) 1 2 3
Condition66%2/3
$old_installed{$name} and $old_installed{$name}{$version}
!ll&&!rl&&r
021
MC/DC50%1/2
$old_installed{$name} and $old_installed{$name}{$version}
$old_installed{$name} $old_installed{$name}{$version}
Truth table66%2/3
A and B
A= $old_installed{$name}B= $old_installed{$name}{$version}
ABresult
0X0
100
111
107 1 delete $old_installed{$name}{$version};
108 1 ▶ if ( !keys %{ $old_installed{$name} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$old_installed{$name};}) 1 0 1
109 1 delete $old_installed{$name};
110 }
111 1 next;
112 }
113 2 $new_installed{$name}{$version} = $new_pkg;
114 }
115  
116 1 foreach my $new_name ( keys %new_installed ) {
117 2 ▶ if ( $old_installed{$new_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_installed{$new_name}) { } 1 1 2
118 1 foreach my $pkg ( values %{ $new_installed{$new_name} } ) {
119 1 push @modifications, { %{$pkg}, action => 'updated' };
120 }
121 }
122 else {
123 1 foreach my $pkg ( values %{ $new_installed{$new_name} } ) {
124 1 push @modifications, { %{$pkg}, action => 'installed' };
125 }
126 }
127 }
128  
129 1 foreach my $old_name ( keys %old_installed ) {
130 2 ▶ if ( !$new_installed{$old_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_installed{$old_name}) 1 1 2
131 1 foreach my $pkg ( values %{ $old_installed{$old_name} } ) {
132 1 push @modifications, { %{$pkg}, action => 'removed' };
133 }
134 }
135 }
136  
137 1 return @modifications;
138 }
139  
140 0 ▶sub add_repository {
Subroutine add_repository: not called CC=6 SCAR=37.4
Pod undocumented
141 0 my ( $self, %data ) = @_;
142  
143 0 my $name = $data{"name"};
144 0 ▶ my $desc = $data{"description"} || $data{"name"};
Condition0%0/3
$data{'description'} || $data{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$data{'description'} || $data{'name'}
$data{'description'} $data{'name'}
Truth table0%0/3
A || B
A= $data{'description'}B= $data{'name'}
ABresult
1X1
011
000
145  
146 0 ▶ if ( exists $data{"key_url"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data{"key_url"}) 0 0 0
147 0 i_run "rpm --import $data{key_url}";
148 }
149  
150 0 ▶ if ( exists $data{"key_file"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data{"key_file"}) 0 0 0
151 0 i_run "rpm --import $data{key_file}";
152 }
153  
154 0 my $fh = file_write "/etc/yum.repos.d/$name.repo";
155  
156 0 $fh->write("# This file is managed by Rex\n");
157 0 $fh->write("[$name]\n");
158 0 $fh->write("name=$desc\n");
159 0 $fh->write( "baseurl=" . $data{"url"} . "\n" );
160 0 $fh->write("enabled=1\n");
161 $fh->write( "gpgkey=" . $data{"gpgkey"} . "\n" )
162 0 ▶ if defined $data{"gpgkey"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data{"gpgkey"} 0 0 0
163 $fh->write( "gpgcheck=" . $data{"gpgcheck"} . "\n" )
164 0 ▶ if defined $data{"gpgcheck"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data{"gpgcheck"} 0 0 0
165  
166 0 $fh->close;
167 }
168  
169 0 ▶sub rm_repository {
Subroutine rm_repository: not called CC=1 SCAR=6.9
Pod undocumented
170 0 my ( $self, $name ) = @_;
171 0 unlink "/etc/yum.repos.d/$name.repo";
172 }
173  
174 7 ▶sub _yum {
Subroutine _yum: called CC=2 SCAR=7.2
175 7 my ( $self, @cmd ) = @_;
176  
177 7 my $str;
178  
179 7 ▶ if ($Rex::Logger::debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::Logger::debug) { } 0 7 7
180 0 $str = join( ' ', "yum ", @cmd );
181 }
182 else {
183 7 $str = join( ' ', "yum -q ", @cmd );
184 }
185  
186 7 return $str;
187 }
188  
189 2 1;
« lib/Rex/Test/Base.pm ↑ Summary lib/Rex/Pkg/SunOS/pkg.pm »