blib/lib/HPUX/Ioscan.pm

filter: Statementstmt 51.3% 111 / 216 Branchbran 25.9% 28 / 108 Conditioncond 45.4% 5 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 80.0% 12 / 15 Podpod 100% 6 / 6 totaltotal 44.7% 162 / 362 CC 69 SCAR 40.7
CC
69
Cov
43%
ioscan
132.0
new
88.9
get_device_hwpath
72.0
CRAP 58.8
↑ Summary
1 package HPUX::Ioscan;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use warnings;
6  
7 1 require Exporter;
8 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw(Exporter);
11  
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15  
16 # This allows declaration use HPUX::Ioscan ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw(
20
21 ) ] );
22  
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24  
25 1 our @EXPORT = qw(ioscan
26
27 );
28 1 our $VERSION = '1.09_01';
29  
30 # Preloaded methods go here.
31  
32 # Autoload methods go after =cut, and are processed by the autosplit program.
33  
34  
35 ## start
36  
37  
38 1 ▶use FileHandle ;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use vars qw/@ISA @EXPORT $test $VERSION $AUTOLOAD/;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 my @list =
44 qw/bus_type
45 cdio
46 is_block
47 is_char
48 is_pseudo
49 block_major_number
50 character_major_number
51 minor_number
52 class
53 driver
54 hardware_path
55 identify_bytes
56 instance_number
57 module_path
58 module_name
59 software_state
60 hardware_type
61 description
62 card_instance/;
63  
64 1 my $cache ;
65  
66 sub ioscan
67 0 ▶ {
Subroutine ioscan: not called CC=11 SCAR=48.8
Pod documented
68 0 my %args = @_ ;
69 0 my $tmp_path ;
70 0 ▶ my $force = $args{force} || 0;
Condition0%0/2
$args{'force'} || 0
l!l
00
MC/DC0%0/1
$args{'force'} || 0
$args{'force'}
Truth table0%0/2
A
A= $args{'force'}
Aresult
11
00
71  
72 0 ▶ if (not defined $cache or $force)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cache or $force) 0 0 0
Condition0%0/3
not defined $cache or $force
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $cache or $force
not defined $cache $force
Truth table0%0/3
not(A) or B
A= not defined $cacheB= $force
ABresult
1X1
011
000
73 {
74 0 my @scan ;
75 0 ▶ if (defined $test)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $HPUX::Ioscan::test) { } 0 0 0
76 {
77 0 @scan = @$test ;
78 }
79 else
80 {
81 0 my $fh = new FileHandle;
82 0 ▶ $fh->open ('ioscan -nF |')
Branch: 1 branch
BranchTrueFalseTotal
$fh->open("ioscan -nF |") or croak("can't open ioscan pipe $!\n") 0 0 0
83 or croak "can't open ioscan pipe $!\n";
84 0 @scan = <$fh>;
85 0 $fh->close;
86 0 ▶ die "Ioscan error: $!\n" if $! ;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
87 }
88  
89 0 foreach my $line (@scan)
90 {
91 #print $line ,"\n";
92 0 ▶ if ($line =~ s/^\s+//)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\s+//) { } 0 0 0
93 {
94 # file line
95 0 push @{$cache->{$tmp_path}{device_files}}, split /\s+/,$line ;
96 }
97 else
98 {
99 #device line
100 0 my @fields = split(':',$line) ;
101 #print "nb field ", scalar @fields, " nb list ", scalar @list, "\n";
102 0 my $i=0;
103 0 my %tmp ;
104 0 ▶ while (defined $list[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $list[$i]) 0 0 0
105 {
106 #print "$i: $list[$i], $fields[$i]\n";
107 0 $tmp{$list[$i++]} = $fields[$i] ;
108 }
109  
110 0 $tmp_path = $tmp{hardware_path} ;
111 0 $cache->{$tmp_path} = \%tmp ;
112 }
113 }
114 }
115  
116 0 ▶ return $cache->{hardware_path} if defined $args{hardware_path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"hardware_path"} 0 0 0
117  
118 0 return $cache ;
119 }
120  
121 sub new
122 1 ▶ {
Subroutine new: called CC=18 SCAR=44.9
Pod documented
123 1 my $debug=0;
124 1 my $debug2=0;
125  
126 1 my ($class, @subargs) = @_ ;
127  
128 1 my %arglist = (
129 target_type => "local" ,
130 persistance => "new" ,
131 datafile => "/tmp/ioscan.dat" ,
132 access_prog => "ssh" ,
133 access_system => "localhost" ,
134 access_user => "root" ,
135 remote_command1 => '/usr/sbin/ioscan -Fn',
136 @subargs,
137 );
138  
139 1 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1 1
140 0 print "target_type : $arglist{target_type}\n";
141 0 print "persistance : $arglist{persistance}\n";
142 0 print "datafile : $arglist{datafile}\n";
143 0 print "access_prog : $arglist{access_prog}\n";
144 0 print "access_system: $arglist{access_system}\n";
145 0 print "access_user : $arglist{access_user}\n";
146 0 print "remote_command1: $arglist{remote_command1}\n";
147 }
148  
149 1 my $source_access =$arglist{target_type};
150 1 my $new_or_saved =$arglist{persistance};
151 1 my $datafile =$arglist{datafile};
152 1 my $remote_access =$arglist{access_prog};
153 1 my $remote_system =$arglist{access_system};
154 1 my $remote_user =$arglist{access_user};
155 1 my $remote_command =$arglist{remote_command1};
156  
157 1 my $line;
158 my $ioscan_hashref;
159 1 my @ioscan_out;
160 1 my %ioscan_info;
161 1 my $ioscan_object_ref = \%ioscan_info;
162  
163 1 ▶ print "I'm :".ref($ioscan_object_ref)."\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
164  
165 1 my @ioscan_split;
166 my $tmp_path ;
167  
168 1 ▶ print "I'm in class: $class\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
169 1 ▶ print "Command: $remote_access $remote_system -l $remote_user -n $remote_command\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
170  
171 1 ▶ if ( $new_or_saved eq "old" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_or_saved eq "old") 1 0 1
172 1 ▶ print "retrieving a copy from prosperity...\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
173 1 ▶ $ioscan_hashref = Storable::retrieve $datafile
Branch: 1 branch
BranchTrueFalseTotal
$ioscan_hashref = Storable::retrieve($datafile) or die "unable to retrieve hash data in /tmp\n" 1 0 1
174 or die "unable to retrieve hash data in /tmp\n";
175 1 return bless($ioscan_hashref,$class);
176 }
177  
178 0 ▶ @ioscan_out=`$remote_access $remote_system -l $remote_user -n $remote_command`
Branch: 1 branch
BranchTrueFalseTotal
@ioscan_out = or die "Could not execute remote command: $@\n" 0 0 0
179 or die "Could not execute remote command: $@\n";
180  
181 0 foreach my $line (@ioscan_out)
182 {
183 0 ▶ print $line ,"\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
184 0 ▶ if ($line =~ s/^\s+//)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\s+//) { } 0 0 0
185 { # file line
186 0 ▶ print "Matched line starting with device file\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
187 0 push @{ $ioscan_info{$ioscan_split[10]}->{device_files} }, split /\s+/, $line;
188  
189 }
190 else
191 {
192 0 ▶ print "Matched actual device line\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
193 0 @ioscan_split = split /:/, $line;
194 # match keys to values from list above
195 0 ▶ for (my $i=0 ; $i<19 ; $i++) { $ioscan_info{$ioscan_split[10]}{$list[$i]} = $ioscan_split[$i] };
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 19) 0 0 0
196 }
197 }
198 0 ▶ if ( $new_or_saved eq "new" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_or_saved eq "new") 0 0 0
199 0 ▶ print "saving a copy for prosperity...\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
200 0 ▶ Storable::nstore \%ioscan_info, $datafile
Branch: 1 branch
BranchTrueFalseTotal
Storable::nstore(\%ioscan_info, $datafile) or die "unable to store hash data in $datafile\n" 0 0 0
201 or die "unable to store hash data in $datafile\n";
202 }
203 0 return bless($ioscan_object_ref,$class);
204 }
205  
206 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=11 SCAR=26.1
207 7 my ($self, @subargs) = @_;
208  
209 7 my %arglist = (
210 hwpath => "" ,
211 @subargs,
212 );
213 7 my $debug = 0;
214 7 ▶ print "Passed: @_<--\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
215 7 ▶ print "Yoyoyoyo got called here\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
216 7 my $HWPATH = $arglist{hwpath};
217 7 ▶ print "HWPATH: $HWPATH\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
218 7 ▶ print "AUTOLOAD: $AUTOLOAD\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
219 7 ▶ $AUTOLOAD =~ /.*::get_(\w+)/ or croak "No Such method: $AUTOLOAD\n";
Branch: 1 branch
BranchTrueFalseTotal
$HPUX::Ioscan::AUTOLOAD =~ /.*::get_(\w+)/ or croak("No Such method: $HPUX::Ioscan::AUTOLOAD\n") 6 1 7
220 6 ▶ print "AUTOLOAD is now: $AUTOLOAD\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 6 6
221 6 ▶ croak "$self not an object" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 6 6
222 6 ▶ return if $AUTOLOAD =~ /::DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
if $HPUX::Ioscan::AUTOLOAD =~ /::DESTROY$/ 0 6 6
223 6 ▶ unless (exists $self->{$HWPATH}->{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$HWPATH}{$1}) 0 6 6
224 0 croak "Cannot access $1 field in $self->{$HWPATH}\n";
225 }
226 6 ▶ print "self says its: $self->{$1}\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 6 6
227 6 return $self->{$HWPATH}->{$1};
228 }
229  
230 0 ▶sub traverse {
Subroutine traverse: not called CC=5 SCAR=34.0
Pod documented
231 0 my $self = shift;
232 0 my $debug=1;
233 0 ▶ print "I am self: $self\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
234 0 my $mainkey;
235 my $subkey;
236 0 my $dev_file;
237  
238 0 foreach $mainkey ( keys %{ $self } ) {
239 0 print "Main Key: $mainkey\n";
240 0 print "Values:\n";
241 0 foreach $subkey ( keys %{ $self->{$mainkey} } ) {
242 0 print "SubKey: $subkey, Value: $self->{$mainkey}->{$subkey}\n";
243 }
244 0 foreach $dev_file ( @{ $self->{$mainkey}->{device_files} } ) {
245 0 print "Mainkey : $mainkey\n";
246 0 print "Device File: $dev_file\n";
247 }
248 }
249 }
250  
251 1 ▶sub get_disk_controllers {
Subroutine get_disk_controllers: called CC=4 SCAR=13.9
Pod documented
252 1 my $self = shift;
253 1 my $debug = 1;
254 1 my $mainkey;
255 my $subkey;
256  
257 1 my @controllers;
258 1 my @disks;
259  
260 1 foreach $mainkey ( keys %{ $self } ) {
261 31 foreach $subkey ( keys %{ $self->{$mainkey} } ) {
262 601 ▶ if ($self->{$mainkey}->{$subkey} eq "ext_bus") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$mainkey}{$subkey} eq "ext_bus") 4 597 601
263 4 push @controllers, $mainkey;
264 }
265 }
266 }
267 1 return \@controllers;
268 }
269  
270 1 ▶sub get_all_disks_on_controller {
Subroutine get_all_disks_on_controller: called CC=18 SCAR=39.4
Pod documented
271 1 my ($self, @subargs) = @_;
272  
273 1 my %arglist = (
274 controller => "" ,
275 @subargs,
276 );
277 1 my $debug=0;
278 1 my $mainkey;
279 my $subkey;
280 1 my $subval;
281 1 my $instance;
282 1 my @disks;
283  
284 1 my $cval; # added to support device file sort
285 1 my $tval; # added to support device file sort
286 1 my $dval; # added to support device file sort
287 1 my %devfile; #added to numerically sort device files
288 1 my $devfile1; #temp variable in foreach loop
289 1 my $total; # added to support device file sort
290 1 my @sorted_disks;
291  
292 # First find the instance
293
294 1 $instance = $self->{ $arglist{controller} }->{card_instance};
295 1 ▶ print "Instance: $instance\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
296 1 foreach $mainkey ( keys %{ $self } ) {
297 31 ▶ print "MainKey: $mainkey\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 31 31
298 31 ▶ while ( ($subkey, $subval)= sort each %{ $self->{ $mainkey } } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = sort(each %{$$self{$mainkey};})) 601 31 632
299 601 ▶ print "Subkey: $subkey\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 601 601
300 601 ▶ print "Subval: $subval\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 601 601
301 601 ▶ if ( $subkey eq "class" && $subval eq "disk" && $self->{ $mainkey }->{card_instance} eq $instance ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subkey eq "class" and $subval eq "disk" and $self->{$mainkey}{"card_instance"} eq $instance) 0 601 601
Condition83%5/6
$subkey eq "class" and $subval eq "disk" and $self->{$mainkey}{"card_instance"} eq $instance
!ll&&!rl&&r
59920
$subkey eq "class" and $subval eq "disk"
!ll&&!rl&&r
575242
MC/DC0%0/3
$subkey eq "class" and $subval eq "disk" and $self->{$mainkey}{"card_instance"} eq $instance
$subkey eq "class" $subval eq "disk" $self->{$mainkey}{"card_instance"} eq $instance
Truth table75%3/4
A and B and C
A= $subkey eq "class"B= $subval eq "disk"C= $self->{$mainkey}{"card_instance"} eq $instance
ABCresult
0XX0
10X0
1100
1111
302 0 ▶ print "Gotta match of class, disk and instance\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
303 0 ▶ print "This is what it is: @{ $self->{ $mainkey}->{device_files} }\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
304 0 push @disks, ${ $self->{ $mainkey }->{device_files} }[0];
305 }
306 }
307 }
308 1 ▶ while (<@disks>) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = glob(join($", @disks)))) 0 1 1
309  
310 0 /c(\d+)t(\d+)d(\d+)/;
311  
312 0 $cval = $1;
313 0 ▶ if ( length($cval) < 2 ) { $cval="0".$cval };
Branch: 1 branch
BranchTrueFalseTotal
if (length $cval < 2) 0 0 0
314 0 $tval = $2;
315 0 ▶ if ( length($tval) < 2 ) { $tval="0".$tval };
Branch: 1 branch
BranchTrueFalseTotal
if (length $tval < 2) 0 0 0
316 0 $dval = $3;
317 0 ▶ if ( length($dval) < 2 ) { $dval="0".$dval };
Branch: 1 branch
BranchTrueFalseTotal
if (length $dval < 2) 0 0 0
318  
319 0 $total = $cval.$tval.$dval;
320 0 ▶ print "total: $total\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
321  
322 0 $devfile{$total}=$_;
323 }
324 1 foreach $devfile1 ( sort keys %devfile ) {
325 0 push @sorted_disks, $devfile{$devfile1};
326 }
327 1 return \@sorted_disks;
328 }
329  
330 0 ▶sub get_device_hwpath {
Subroutine get_device_hwpath: not called CC=8 SCAR=42.8
Pod documented
331 0 my ($self, @subargs) = @_;
332  
333 0 my %arglist = (
334 device_name => "" ,
335 @subargs,
336 );
337 0 my $debug=0;
338 0 my $mainkey;
339 my $subkey;
340 0 my $subval;
341 0 my $device_name = $arglist{device_name};
342 0 my $hwpath;
343  
344 # First find the instance
345
346 0 foreach $mainkey ( sort keys %{ $self } ) {
347 0 ▶ print "MainKey: $mainkey\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
348  
349 0 ▶ while ( ($subkey, $subval)= sort each %{ $self->{ $mainkey } } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = sort(each %{$$self{$mainkey};})) 0 0 0
350 0 ▶ print "Subkey: $subkey\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
351 0 ▶ print "Subval: $subval\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
352 0 ▶ if (defined ${ $self->{$mainkey}->{device_files} }[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined do { $$self{$mainkey}{"device_files"} }->[0]) 0 0 0
353 0 ▶ if ( ${ $self->{ $mainkey }->{device_files} }[0] eq "$device_name" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { $$self{$mainkey}{"device_files"} }->[0] eq "$device_name") 0 0 0
354 0 $hwpath = $self->{ $mainkey }->{hardware_path};
355 0 return $hwpath;
356 }
357 }
358 }
359 }
360 0 $device_name=0;
361 0 return undef;
362 }
363 1 1;
364 __END__
↑ Summary