lib/Rex/Inventory/HP/ACU.pm

filter: Statementstmt 10.4% 13 / 124 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 5 totaltotal 7.8% 17 / 218 CC 36 SCAR 66.5
CC
36
Cov
7%
parse_config
1056.0
V
12.0
get
6.0
CRAP 769.5
« lib/Rex/User/Linux.pm ↑ Summary lib/Rex/Resource/firewall/Provider/iptables.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Inventory::HP::ACU;
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::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
16  
17 0 ▶ if ( can_run("hpacucli") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run('hpacucli')) { } 0 0 0
18 0 my @lines = i_run "/usr/sbin/hpacucli controller all show config detail",
19 fail_ok => 1;
20 0 my $ret = parse_config(@lines);
21 0 return $ret;
22 }
23 else {
24 0 return 0;
25 }
26  
27 }
28  
29 #
30 # The bellow code is from Parse::HP::ACU
31 #
32 # Copyright 2010 Jeremy Cole.
33 #
34 # This program is free software; you can redistribute it and/or modify it
35 # under the terms of either: the GNU General Public License as published
36 # by the Free Software Foundation; or the Artistic License.
37 #
38 # See http://dev.perl.org/licenses/ for more information.
39 #
40 0 ▶sub parse_config {
Subroutine parse_config: not called CC=32 SCAR=69.6
Pod undocumented
41 0 my (@lines) = @_;
42  
43 0 my $controller = {};
44 0 my $current_controller = 0;
45 0 my $current_array = undef;
46 0 my $current_logical_drive = undef;
47 0 my $current_mirror_group = undef;
48 0 my $current_physical_drive = undef;
49  
50 0 LINE: for my $line (@lines) {
51 0 chomp $line;
52  
53 0 ▶ next if ( $line =~ /^$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^$/u 0 0 0
54  
55 0 ▶ if ( $line !~ /^[ ]+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^[ ]+/u) 0 0 0
56 0 $current_controller = $current_controller + 1;
57 0 $current_array = undef;
58 0 $current_logical_drive = undef;
59 0 $current_mirror_group = undef;
60 0 $current_physical_drive = undef;
61 0 $controller->{$current_controller} = {};
62 0 $controller->{$current_controller}->{'description'} = $line;
63 0 next;
64 }
65  
66 0 ▶ next if ( !defined($current_controller) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current_controller 0 0 0
67  
68 0 $line =~ s/^\s+//g;
69 0 $line =~ s/\s+$//g;
70 0 $line =~ s/[ ]+/ /g;
71  
72 0 ▶ if ( $line =~ /unassigned/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /unassigned/u) 0 0 0
73 0 $current_array = "unassigned";
74 0 $current_logical_drive = undef;
75 0 $current_mirror_group = undef;
76 0 $current_physical_drive = undef;
77 0 $controller->{$current_controller}->{'unassigned'} = {};
78 0 $controller->{$current_controller}->{'unassigned'}->{'physical_drive'} =
79 {};
80 0 next;
81 }
82  
83 0 ▶ if ( $line =~ /Array: ([A-Z]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Array: ([A-Z]+)/u) 0 0 0
84 0 $current_array = $1;
85 0 $current_logical_drive = undef;
86 0 $current_mirror_group = undef;
87 0 $current_physical_drive = undef;
88 0 $controller->{$current_controller}->{'array'}->{$current_array} = {};
89 $controller->{$current_controller}->{'array'}->{$current_array}
90 0 ->{'logical_drive'} = {};
91 $controller->{$current_controller}->{'array'}->{$current_array}
92 0 ->{'physical_drive'} = {};
93 0 next;
94 }
95  
96 0 ▶ if ( $line =~ /Logical Drive: ([0-9]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Logical Drive: ([0-9]+)/u) 0 0 0
97 0 $current_logical_drive = $1;
98 0 $current_physical_drive = undef;
99 0 $current_mirror_group = undef;
100 $controller->{$current_controller}->{'array'}->{$current_array}
101 0 ->{'logical_drive'}->{$current_logical_drive} = {};
102 $controller->{$current_controller}->{'array'}->{$current_array}
103 0 ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'} = {};
104 0 next;
105 }
106  
107 0 ▶ if ( $line =~ /physicaldrive ([0-9IC:]+)/ and $line !~ /port/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /physicaldrive ([0-9IC:]+)/u and not $line =~ /port/u) 0 0 0
Condition0%0/3
$line =~ /physicaldrive ([0-9IC:]+)/u and not $line =~ /port/u
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /physicaldrive ([0-9IC:]+)/u and not $line =~ /port/u
$line =~ /physicaldrive ([0-9IC:]+)/u not $line =~ /port/u
Truth table0%0/3
A and not(B)
A= $line =~ /physicaldrive ([0-9IC:]+)/uB= not $line =~ /port/u
ABresult
0X0
100
111
108 0 $current_logical_drive = undef;
109 0 $current_physical_drive = $1;
110 0 $current_mirror_group = undef;
111 0 ▶ if ( $current_array eq 'unassigned' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_array eq 'unassigned') { } 0 0 0
112 $controller->{$current_controller}->{'unassigned'}->{'physical_drive'}
113 0 ->{$current_physical_drive} = {};
114 }
115 else {
116 $controller->{$current_controller}->{'array'}->{$current_array}
117 0 ->{'physical_drive'}->{$current_physical_drive} = {};
118 }
119 0 next;
120 }
121  
122 0 ▶ if ( $line =~ /Mirror Group ([0-9]+):/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Mirror Group ([0-9]+):/u) 0 0 0
123 0 $current_mirror_group = $1;
124 $controller->{$current_controller}->{'array'}->{$current_array}
125 ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'}
126 0 ->{$current_mirror_group} = [];
127 0 next;
128 }
129  
130 0 ▶ if ( defined($current_array)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_array and defined $current_logical_drive and defined $current_mirror_group) 0 0 0
Condition0%0/6
defined $current_array and defined $current_logical_drive and defined $current_mirror_group
!ll&&!rl&&r
000
defined $current_array and defined $current_logical_drive
!ll&&!rl&&r
000
MC/DC0%0/3
defined $current_array and defined $current_logical_drive and defined $current_mirror_group
defined $current_array defined $current_logical_drive defined $current_mirror_group
Truth table0%0/4
A and B and C
A= defined $current_arrayB= defined $current_logical_driveC= defined $current_mirror_group
ABCresult
0XX0
10X0
1100
1111
131 and defined($current_logical_drive)
132 and defined($current_mirror_group) )
133 {
134 0 ▶ if ( $line =~ /physicaldrive ([0-9IC:]+) \(/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /physicaldrive ([0-9IC:]+) \(/u) 0 0 0
135 my $current_mirror_group_list =
136 $controller->{$current_controller}->{'array'}->{$current_array}
137 ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'}
138 0 ->{$current_mirror_group};
139  
140 0 foreach my $pd ( @{$current_mirror_group_list} ) {
141 0 ▶ next LINE if ( $pd eq $1 );
Branch: 1 branch
BranchTrueFalseTotal
if $pd eq $1 0 0 0
142 }
143 0 push @{$current_mirror_group_list}, $1;
144 }
145 0 next;
146 }
147  
148 0 ▶ if ( defined($current_array)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_array and defined $current_logical_drive) 0 0 0
Condition0%0/3
defined $current_array and defined $current_logical_drive
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current_array and defined $current_logical_drive
defined $current_array defined $current_logical_drive
Truth table0%0/3
A and B
A= defined $current_arrayB= defined $current_logical_drive
ABresult
0X0
100
111
149 and defined($current_logical_drive) )
150 {
151 0 ▶ if ( my ( $k, $v ) = &K_V($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &K_V($line)) 0 0 0
152 0 ▶ next unless defined($k);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 0 0
153 $controller->{$current_controller}->{'array'}->{$current_array}
154 0 ->{'logical_drive'}->{$current_logical_drive}->{$k} = $v;
155 }
156 0 next;
157 }
158  
159 0 ▶ if ( defined($current_array)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_array and defined $current_physical_drive) 0 0 0
Condition0%0/3
defined $current_array and defined $current_physical_drive
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current_array and defined $current_physical_drive
defined $current_array defined $current_physical_drive
Truth table0%0/3
A and B
A= defined $current_arrayB= defined $current_physical_drive
ABresult
0X0
100
111
160 and defined($current_physical_drive) )
161 {
162 0 ▶ if ( my ( $k, $v ) = &K_V($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &K_V($line)) 0 0 0
163 0 ▶ next unless defined($k);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 0 0
164 0 ▶ if ( $current_array eq 'unassigned' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_array eq 'unassigned') { } 0 0 0
165 $controller->{$current_controller}->{'unassigned'}
166 0 ->{'physical_drive'}->{$current_physical_drive}->{$k} = $v;
167 }
168 else {
169 $controller->{$current_controller}->{'array'}->{$current_array}
170 0 ->{'physical_drive'}->{$current_physical_drive}->{$k} = $v;
171 }
172 }
173 0 next;
174 }
175  
176 0 ▶ if ( defined($current_array) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_array) 0 0 0
177 0 ▶ if ( my ( $k, $v ) = &K_V($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &K_V($line)) 0 0 0
178 0 ▶ next unless defined($k);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 0 0
179 0 $controller->{$current_controller}->{'array'}->{$current_array}->{$k} =
180 $v;
181 }
182 0 next;
183 }
184  
185 0 ▶ if ( my ( $k, $v ) = &K_V($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &K_V($line)) 0 0 0
186 0 ▶ next unless defined($k);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 0 0
187 0 $controller->{$current_controller}->{$k} = $v;
188 }
189 0 next;
190 }
191  
192 0 return $controller;
193 }
194  
195 0 ▶sub K {
Subroutine K: not called CC=1 SCAR=6.9
Pod undocumented
196 0 my ($k) = @_;
197  
198 0 $k = lc $k;
199 0 $k =~ s/[ \/\-]/_/g;
200 0 $k =~ s/[\(\)]//g;
201  
202 0 return $k;
203 }
204  
205 0 ▶sub V {
Subroutine V: not called CC=3 SCAR=24.8
Pod undocumented
206 0 my ( $k, $v ) = @_;
207  
208 0 ▶ if ( $k eq 'accelerator_ratio' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "accelerator_ratio") 0 0 0
209 0 ▶ if ( $v =~ /([0-9]+)% Read \/ ([0-9]+)% Write/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[([0-9]+)% Read / ([0-9]+)% Write]u) 0 0 0
210 0 return { 'read' => $1, 'write' => $2 };
211 }
212 }
213  
214 0 return $v;
215 }
216  
217 0 ▶sub K_V {
Subroutine K_V: not called CC=2 SCAR=17.9
Pod undocumented
218 0 my ($line) = @_;
219  
220 0 ▶ if ( $line =~ /(.+):\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(.+):\s+(.+)/u) 0 0 0
221 0 my $k = &K($1);
222 0 my $v = &V( $k, $2 );
223 0 return ( $k, $v );
224 }
225  
226 0 return ( undef, undef );
227 }
228  
229 1 1;
« lib/Rex/User/Linux.pm ↑ Summary lib/Rex/Resource/firewall/Provider/iptables.pm »