Distribconf/Checks.pm

filter: Statementstmt 35.2% 50 / 142 Branchbran 21.4% 15 / 70 Conditioncond 22.8% 8 / 35 MC/DCmcdc 5.0% 1 / 20 Subroutinesub 64.7% 11 / 17 Podpod 66.6% 6 / 9 totaltotal 31.0% 91 / 293 SCAR 74.0
CC
67
Cov
30%
check_config
462.0
check_media_coherency
240.0
checkdistrib
72.0
CRAP 1636.3
« Distribconf/Build.pm ↑ Summary Distribconf.pm »
1 # $Id: Checks.pm 59285 2006-09-01 00:10:10Z nanardon $
2  
3 package MDV::Distribconf::Checks;
4  
5 3 our $VERSION = (qq$Revision: 59285 $ =~ /(\d+)/)[0];
6  
7 =head1 NAME
8  
9 MDV::Distribconf::Checks - A Subclass to MDV::Distribconf::Build to check distribution trees
10  
11 =head1 METHODS
12  
13 =over 4
14  
15 =cut
16  
17 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use MDV::Distribconf::MediaCFG;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use MDV::Packdrakeng;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use MDV::Distribconf::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use base qw(MDV::Distribconf);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 sub new {
26 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
27 0 my $self = $class->SUPER::new(@_);
28 0 bless $self, $class;
29 }
30  
31 sub _report_err {
32 1 ▶ my ($out, $err_code, $fmt, @args) = @_;
Subroutine _report_err: called CC=7 SCAR=23.7
33 1 my %errs = (
34 'UNSYNC_HDLIST' => 'E',
35 'UNSYNC_MD5' => 'E',
36 'WRONG_CONFIG' => 'W',
37 'MISSING_MEDIA' => 'W',
38 'MISSING_MEDIADIR' => 'E',
39 'SAME_INDEX' => 'E',
40 'NOMEDIA' => 'E',
41 'MISSING_INDEX' => 'E',
42 'MISSING_INFO' => 'W',
43 );
44 1 my $message = sprintf($fmt, @args);
45  
46 1 ▶ if (ref $out eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $out eq 'CODE') { } 1 0 1
47 $out->(
48 errcode => $err_code || '?',
49 1 ▶ level => $errs{$err_code} || '?',
Condition50%2/4
$err_code || '?'
l!l
10
$errs{$err_code} || '?'
l!l
10
MC/DC0%0/1
$err_code || '?'
$err_code
MC/DC0%0/1
$errs{$err_code} || '?'
$errs{$err_code}
Truth table50%1/2
A
A= $err_code
Aresult
11
00
Truth table50%1/2
A
A= $errs{$err_code}
Aresult
11
00
50 message => $message,
51 );
52 } else {
53 0 ▶ printf $out "%s: %s\n", $errs{$err_code} || '?', $message;
Condition0%0/2
$errs{$err_code} || '?'
l!l
00
MC/DC0%0/1
$errs{$err_code} || '?'
$errs{$err_code}
Truth table0%0/2
A
A= $errs{$err_code}
Aresult
11
00
54 }
55 1 ▶ return($errs{$err_code} || '?' eq 'E' ? 1 : 0)
Branch: 1 branch
BranchTrueFalseTotal
$errs{$err_code} || !1 ? : 1 0 1
Condition50%1/2
$errs{$err_code} or
l!l
10
MC/DC0%0/1
$errs{$err_code} or
$errs{$err_code}
Truth table50%1/2
A
A= $errs{$err_code}
Aresult
11
00
56 }
57  
58 =item $distrib->check_config
59  
60 =cut
61  
62 sub check_config {
63 0 ▶ my ($self, $fhout) = @_;
Subroutine check_config: not called CC=21 SCAR=61.4
Pod documented
64 0 ▶ $fhout ||= \*STDERR;
Condition0%0/2
$fhout ||= \*STDERR
l!l
00
MC/DC0%0/1
$fhout ||= \*STDERR
$fhout
Truth table0%0/2
A
A= $fhout
Aresult
11
00
65  
66 0 my $error = 0;
67  
68 0 foreach my $var ($self->{cfg}->Parameters('media_info')) {
69 0 ▶ $self->{cfg}->val('media_info', $var) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cfg"}->val("media_info", $var) or next 0 0 0
70 my @er = MDV::Distribconf::MediaCFG::_valid_param(
71 'media_info',
72 $var,
73 0 $self->{cfg}->val('media_info', $var),
74 );
75 0 foreach (@er) {
76 0 $error += _report_err(
77 $fhout,
78 'WRONG_CONFIG',
79 "%s %s: %s", 'media_info', $var, $_
80 );
81 }
82 }
83 0 foreach my $media ($self->listmedia()) {
84 0 foreach my $var ($self->{cfg}->Parameters($media)) {
85 0 ▶ $self->{cfg}->val($media, $var) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cfg"}->val($media, $var) or next 0 0 0
86 0 my @er = MDV::Distribconf::MediaCFG::_valid_param(
87 'media_info',
88 $var,
89 $self->getvalue($media, $var),
90 );
91 0 foreach (@er) {
92 0 $error += _report_err(
93 $fhout,
94 'WRONG_CONFIG',
95 "%s %s: %s", $media, $var, $_
96 );
97 }
98 0 ▶ my $varinfo = MDV::Distribconf::MediaCFG::_value_info($var) || {};
Condition0%0/2
MDV::Distribconf::MediaCFG::_value_info($var) || {}
l!l
00
MC/DC0%0/1
MDV::Distribconf::MediaCFG::_value_info($var) || {}
MDV::Distribconf::MediaCFG::_value_info($var)
Truth table0%0/2
A
A= MDV::Distribconf::MediaCFG::_value_info($var)
Aresult
11
00
99 0 ▶ if ($varinfo->{deny}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($varinfo->{"deny"}) 0 0 0
100 0 ▶ if ($self->getvalue($media, $varinfo->{deny})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getvalue($media, $varinfo->{"deny"})) 0 0 0
101 $error += _report_err(
102 $fhout,
103 'WRONG_CONFIG',
104 '%s and %s cannot be set together (media %s)',
105 0 $var, $varinfo->{deny}, $media
106 );
107 }
108 }
109 0 ▶ if ($varinfo->{ismedialist} || $varinfo->{cross}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($varinfo->{"ismedialist"} or $varinfo->{"cross"}) 0 0 0
Condition0%0/3
$varinfo->{"ismedialist"} or $varinfo->{"cross"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$varinfo->{"ismedialist"} or $varinfo->{"cross"}
$varinfo->{"ismedialist"} $varinfo->{"cross"}
Truth table0%0/3
A or B
A= $varinfo->{"ismedialist"}B= $varinfo->{"cross"}
ABresult
1X1
011
000
110 0 foreach my $sndmedia (split(/ /, $self->getvalue($media, $var, ''))) {
111 0 ▶ if (!$self->mediaexists($sndmedia)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->mediaexists($sndmedia)) { } 0 0 0
elsif ($varinfo->{'cross'}) { } 0 0 0
112 0 $error += _report_err(
113 $fhout,
114 'MISSING_MEDIA',
115 "`%s' refer as %s to non existant `%s'",
116 $media,
117 $var,
118 $sndmedia,
119 );
120 } elsif($varinfo->{cross}) {
121 0 ▶ if(!grep { $media eq $_ }
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$media eq $_;} split(/ /, $self->getvalue($sndmedia, $varinfo->{"cross"}), 0)) 0 0 0
122 split(/ /,
123 $self->getvalue($sndmedia, $varinfo->{cross})
124 )) {
125 $error += _report_err(
126 $fhout,
127 'WRONG_CONFIG',
128 "`%s' has not `%s' as %s",
129 $sndmedia, $media, $varinfo->{cross},
130 0 );
131 }
132 }
133 }
134 }
135 }
136 }
137  
138 # checking overlap
139 {
140 0 my %foundname;
141 0 push(@{$foundname{$self->getvalue($_, 'name')}}, $_)
142 0 foreach($self->listmedia());
143  
144 0 foreach (keys %foundname) {
145 0 ▶ if (@{$foundname{$_}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$foundname{$_};} > 1) 0 0 0
146 $error += _report_err(
147 $fhout,
148 'WRONG_CONFIG',
149 "`%s' have same name (%s)",
150 0 join(', ', @{$foundname{$_}}),
151 $_,
152 );
153 }
154 }
155 }
156  
157 $error
158 0 }
159 =item $distrib->check_media_coherency($fhout)
160  
161 Performs basic checks on the distribution and prints to $fhout (STDERR by
162 default) warnings and errors found. Returns the number of errors reported.
163  
164 =cut
165  
166 sub check_media_coherency {
167 0 ▶ my ($distrib, $fhout) = @_;
Subroutine check_media_coherency: not called CC=15 SCAR=54.8
Pod undocumented
168 0 ▶ $fhout ||= \*STDERR;
Condition0%0/2
$fhout ||= \*STDERR
l!l
00
MC/DC0%0/1
$fhout ||= \*STDERR
$fhout
Truth table0%0/2
A
A= $fhout
Aresult
11
00
169  
170 0 my $error = 0;
171  
172 0 ▶ $distrib->listmedia or $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
$distrib->listmedia or $error += _report_err("NOMEDIA", "No media found in this config") 0 0 0
173 'NOMEDIA', "No media found in this config"
174 );
175  
176 # Checking no overlap
177 0 foreach my $var (qw/hdlist synthesis path/) {
178 0 my %e;
179 0 foreach ($distrib->listmedia) {
180 0 my $v = $distrib->getpath($_, $var);
181 0 push @{$e{$v}}, $_;
182 }
183  
184 0 foreach my $key (keys %e) {
185 0 ▶ if (@{$e{$key}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$e{$key};} > 1) 0 0 0
186 $error += _report_err(
187 $fhout,
188 'SAME_INDEX',
189 "media `%s' have same %s (%s)",
190 0 join (", ", @{$e{$key}}),
191 $var,
192 $key
193 );
194 }
195 }
196 }
197  
198 0 foreach my $media ($distrib->listmedia) {
199 0 ▶ -d $distrib->getfullpath($media, 'path') or $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
-d $distrib->getfullpath($media, "path") or $error += _report_err($fhout, "MISSING_MEDIADIR", "dir %s does't exist for media `%s'", $distrib->getpath($media, "path"), $media) 0 0 0
200 $fhout,
201 'MISSING_MEDIADIR', "dir %s does't exist for media `%s'",
202 $distrib->getpath($media, 'path'),
203 $media
204 );
205 0 foreach (qw/hdlist synthesis MD5SUM/) {
206 0 ▶ -f $distrib->getfullmediapath($media, $_) or $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
-f $distrib->getfullmediapath($media, $_) or $error += _report_err($fhout, "MISSING_INDEX", "$_ %s doesn't exist for media `%s'", $distrib->getmediapath($media, $_), $media) 0 0 0
207 $fhout,
208 'MISSING_INDEX', "$_ %s doesn't exist for media `%s'",
209 $distrib->getmediapath($media, $_),
210 $media
211 );
212 0 ▶ /^MD5SUM$/ and next;
Branch: 1 branch
BranchTrueFalseTotal
/^MD5SUM$/ and next 0 0 0
213 0 ▶ -f $distrib->getfullpath($media, $_) or $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
-f $distrib->getfullpath($media, $_) or $error += _report_err($fhout, "MISSING_INDEX", "$_ %s doesn't exist for media `%s'", $distrib->getpath($media, $_), $media) 0 0 0
214 $fhout,
215 'MISSING_INDEX', "$_ %s doesn't exist for media `%s'",
216 $distrib->getpath($media, $_),
217 $media
218 );
219 }
220 0 foreach (qw/pubkey/) {
221 0 ▶ -f $distrib->getfullpath($media, $_) or $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
-f $distrib->getfullpath($media, $_) or $error += _report_err($fhout, "MISSING_INFO", "$_ %s doesn't exist for media `%s'", $distrib->getpath($media, $_), $media) 0 0 0
222 $fhout,
223 'MISSING_INFO', "$_ %s doesn't exist for media `%s'",
224 $distrib->getpath($media, $_),
225 $media
226 );
227 }
228  
229 }
230 0 return $error;
231 }
232  
233 =item $distrib->check_index_sync($media)
234  
235 Check the synchronisation between rpms contained by media $media
236 and its hdlist:
237  
238 - all rpms should be in the hdlist
239 - the hdlist should not contains rpms that does not exists
240  
241 Return 1 if no problem were found
242  
243 =cut
244  
245 sub check_index_sync {
246 2 ▶ return (get_index_sync_offset(@_))[0]
Subroutine check_index_sync: called CC=1 SCAR=0.0
Pod documented
247 }
248  
249 sub get_index_sync_offset {
250 2 ▶ my ($self, $media, $submedia) = @_;
Subroutine get_index_sync_offset: called CC=14 SCAR=31.1
Pod undocumented
251 2 my $rpmspath = $self->getfullpath($media, 'path');
252 2 ▶ my $hdlist = ($submedia && -d $self->getfullpath($media, 'path') . '/media_info') ?
Branch: 1 branch
BranchTrueFalseTotal
$submedia && -d $self->getfullpath($media, 'path') . '/media_info' ? : 0 2 2
Condition33%1/3
$submedia and -d $self->getfullpath($media, "path") . '/media_info'
!ll&&!rl&&r
200
MC/DC0%0/2
$submedia and -d $self->getfullpath($media, "path") . '/media_info'
$submedia -d $self->getfullpath($media, "path") . '/media_info'
Truth table33%1/3
A and B
A= $submediaB= -d $self->getfullpath($media, "path") . '/media_info'
ABresult
0X0
100
111
253 $self->getfullmediapath($media, 'hdlist') :
254 $self->getfullpath($media, 'hdlist');
255 2 ▶ my $synthesis = ($submedia && -d $self->getfullpath($media, 'path') . '/media_info') ?
Branch: 1 branch
BranchTrueFalseTotal
$submedia && -d $self->getfullpath($media, 'path') . '/media_info' ? : 0 2 2
Condition33%1/3
$submedia and -d $self->getfullpath($media, "path") . '/media_info'
!ll&&!rl&&r
200
MC/DC0%0/2
$submedia and -d $self->getfullpath($media, "path") . '/media_info'
$submedia -d $self->getfullpath($media, "path") . '/media_info'
Truth table33%1/3
A and B
A= $submediaB= -d $self->getfullpath($media, "path") . '/media_info'
ABresult
0X0
100
111
256 $self->getfullmediapath($media, 'synthesis') :
257 $self->getfullpath($media, 'synthesis');
258  
259 2 ▶ -f $hdlist && -f $synthesis or return 0; # avoid warnings
Branch: 1 branch
BranchTrueFalseTotal
-f $hdlist and -f $synthesis or return 0 0 2 2
Condition33%1/3
-f $hdlist and -f $synthesis
!ll&&!rl&&r
002
MC/DC0%0/2
-f $hdlist and -f $synthesis
-f $hdlist -f $synthesis
Truth table33%1/3
A and B
A= -f $hdlistB= -f $synthesis
ABresult
0X0
100
111
260 2 my ($inp, $ind) = MDV::Distribconf::Utils::hdlist_vs_dir($hdlist, $rpmspath);
261 2 ▶ if (!defined($inp) || (@{$inp || []} + @{$ind || []})) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $inp or @{$inp or [];} + @{$ind or [];}) 1 1 2
$inp or [] 0 2 2
$ind or [] 0 2 2
Condition66%2/3
not defined $inp or @{$inp or [];} + @{$ind or [];}
l!l&&r!l&&!r
011
MC/DC50%1/2
not defined $inp or @{$inp or [];} + @{$ind or [];}
not defined $inp @{$inp or [];} + @{$ind or [];}
Truth table66%2/3
not(A) or B
A= not defined $inpB= @{$inp or [];} + @{$ind or [];}
ABresult
1X1
011
000
262 1 ▶ return (0, (defined($inp) ? scalar(@{$inp || []}) : undef), scalar(@{$ind || []}));
Branch: 3 branches
BranchTrueFalseTotal
defined $inp ? : 1 0 1
$inp or [] 0 1 1
$ind or [] 0 1 1
263 }
264 1 return (1, 0, 0);
265 }
266  
267 =item $distrib->check_media_md5($media)
268  
269 Check md5sum for hdlist and synthesis for the media $media are the same
270 than value contains in the existing MD5SUM file.
271  
272 The function return an error also if the value is missing
273  
274 Return 1 if no error were found.
275  
276 =cut
277  
278 sub check_media_md5 {
279 2 ▶ my ($self, $media) = @_;
Subroutine check_media_md5: called CC=3 SCAR=11.0
Pod documented
280 my ($unsync) = MDV::Distribconf::Utils::checkmd5(
281 $self->getfullmediapath($media, 'MD5SUM'),
282 2 map { $self->getfullmediapath($media, $_) } (qw(hdlist synthesis))
283 );
284 2 ▶ if (@{$unsync || []}) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$unsync or [];}) { } 1 1 2
$unsync or [] 0 2 2
285 1 return 0;
286 } else {
287 1 return 1;
288 }
289 }
290  
291 sub check_global_md5 {
292 0 ▶ my ($self) = @_;
Subroutine check_global_md5: not called CC=4 SCAR=30.0
Pod undocumented
293 0 my @indexes;
294 0 foreach my $media ($self->listmedia()) {
295 0 push(@indexes, map { $self->getfullpath($media, $_) } (qw(hdlist synthesis)));
296 }
297 0 my ($unsync) = MDV::Distribconf::Utils::checkmd5(
298 $self->getfullpath(undef, 'MD5SUM'),
299 @indexes,
300 );
301 0 ▶ if (@{$unsync || []}) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$unsync or [];}) { } 0 0 0
$unsync or [] 0 0 0
302 0 return 0;
303 } else {
304 0 return 1;
305 }
306 }
307  
308 =item $distrib->checkdistrib($fhout)
309  
310 Performs all light checks on the distribution and prints to $fhout (STDERR by
311 default) warnings and errors found. Returns the number of errors reported.
312  
313 =cut
314  
315 sub checkdistrib {
316 0 ▶ my ($self, $fhout) = @_;
Subroutine checkdistrib: not called CC=8 SCAR=42.8
Pod documented
317 0 ▶ $fhout ||= \*STDERR;
Condition0%0/2
$fhout ||= \*STDERR
l!l
00
MC/DC0%0/1
$fhout ||= \*STDERR
$fhout
Truth table0%0/2
A
A= $fhout
Aresult
11
00
318  
319 0 my $error = 0;
320  
321 0 $error += $self->check_config($fhout);
322 0 $error += $self->check_media_coherency($fhout);
323  
324 0 foreach my $media ($self->listmedia) {
325 0 my ($e, $inhd, $indir) = $self->get_index_sync_offset($media);
326 0 ▶ if (!$e) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 0 0 0
327 0 ▶ $error += _report_err(
Branch: 1 branch
BranchTrueFalseTotal
defined $inhd ? : 0 0 0
Condition0%0/2
$indir || 0
l!l
00
MC/DC0%0/1
$indir || 0
$indir
Truth table0%0/2
A
A= $indir
Aresult
11
00
328 $fhout,
329 'UNSYNC_HDLIST',
330 "hdlist for media `%s' is not sync with its rpms" .
331 (defined($inhd) ? " (+%d -%d rpms)" : ' (missing or unreadable hdlist: +%d rpms)'),
332 $media, ($indir || 0), $inhd
333 );
334 }
335  
336 0 ▶ if(!$self->check_media_md5($media)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_media_md5($media)) 0 0 0
337 0 $error += _report_err(
338 $fhout,
339 'UNSYNC_MD5',
340 "md5sum for media `%s' is not ok",
341 $media,
342 );
343 }
344 }
345  
346 0 ▶ if (!$self->check_global_md5()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_global_md5) 0 0 0
347 0 $error += _report_err(
348 $fhout,
349 'UNSYNC_MD5',
350 'Global md5sum file is not ok',
351 );
352 }
353
354 $error
355 0 }
356  
357 =item $distrib->check($fhout)
358  
359 =cut
360  
361 sub check {
362 0 ▶ my ($self, $fhout) = @_;
Subroutine check: not called CC=2 SCAR=17.9
Pod documented
363 0 ▶ $fhout ||= \*STDERR;
Condition0%0/2
$fhout ||= \*STDERR
l!l
00
MC/DC0%0/1
$fhout ||= \*STDERR
$fhout
Truth table0%0/2
A
A= $fhout
Aresult
11
00
364  
365 0 my $error = $self->check_config($fhout);
366 0 $error += $self->check_media_coherency($fhout);
367  
368 0 $error
369 }
370  
371 3 1;
372  
373 __END__
« Distribconf/Build.pm ↑ Summary Distribconf.pm »