MCP/Config.pm

filter: Statementstmt 93.0% 429 / 461 Branchbran 68.3% 149 / 218 Conditioncond 52.5% 21 / 40 MC/DCmcdc 12.0% 3 / 25 Subroutinesub 88.7% 55 / 62 Podpod 92.3% 24 / 26 totaltotal 81.8% 681 / 832 CC 133 SCAR 23.3
CC
133
Cov
83%
parse_virt_preconditions
27.8
get_common_config
16.9
parse_precondition
15.5
CRAP 10.3
« MCP/Child.pm ↑ Summary MCP/Scheduler/Controller.pm »
1 package Tapper::MCP::Config;
2 26 our $AUTHORITY = 'cpan:TAPPER';
3 26 $Tapper::MCP::Config::VERSION = '5.0.9';
4 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 26 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 ▶use Data::DPath 'dpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 26 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use LockFile::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 26 ▶use Socket 'inet_ntoa';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 26 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶use YAML::Syck qw /Load Dump LoadFile DumpFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 26 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 26 ▶use Tapper::Cmd::Cobbler;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 26 ▶use Tapper::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 26 ▶use Tapper::MCP::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 26 ▶use Tapper::Producer;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 26 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 26 extends 'Tapper::MCP::Control';
26  
27 26 has mcp_info => (is => 'rw',
28 );
29  
30 sub BUILD
31 22 ▶{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
32 22 my ($self) = @_;
33 22 $self->{mcp_info} = Tapper::MCP::Info->new();
34 }
35  
36  
37  
38  
39 sub parse_simnow_preconditions
40 0 ▶{
Subroutine parse_simnow_preconditions: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($self, $config, $precondition) = @_;
42 0 $self->mcp_info->test_type('simnow');
43 0 $config->{log_to_file} = 1;
44 0 return $config;
45 }
46  
47  
48 sub parse_hint_preconditions
49 3 ▶{
Subroutine parse_hint_preconditions: called CC=8 SCAR=22.3
Pod documented
50 3 my ($self, $config, $precondition) = @_;
51 3 $config->{log_to_file} = 1;
52 3 ▶ if ($precondition->{simnow}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($precondition->{'simnow'}) { } 1 2 3
elsif ($precondition->{'ssh'}) { } 1 1 2
elsif ($precondition->{'local'}) { } 1 0 1
elsif ($precondition->{'minion'}) { } 0 0 0
53 1 $self->mcp_info->test_type('simnow');
54 1 $config->{paths}{base_dir}='/';
55 1 ▶ $config->{files}{simnow_script} = $precondition->{script} if $precondition->{script};
Branch: 1 branch
BranchTrueFalseTotal
if $precondition->{"script"} 1 0 1
56 1 push @{$config->{preconditions}}, {precondition_type => 'simnow_backend'};
57 } elsif ($precondition->{ssh}) {
58 1 $self->mcp_info->test_type('ssh');
59 1 $config->{paths}{base_dir}='/';
60 1 $config->{prcs}->[0]->{skip_startscript} = 1;
61 $config->{client_package} = {
62 arch => $precondition->{arch},
63 dest_path => $precondition->{dest_path},
64 1 ▶ } if $precondition->{arch};
Branch: 1 branch
BranchTrueFalseTotal
if $precondition->{"arch"} 1 0 1
65 } elsif ($precondition->{local}) {
66 1 $self->mcp_info->test_type('local');
67 1 $config->{prcs}->[0]->{skip_startscript} = 1;
68 1 ▶ $self->mcp_info->skip_install(1) if $precondition->{skip_install};
Branch: 1 branch
BranchTrueFalseTotal
if $precondition->{"skip_install"} 1 0 1
69 } elsif ($precondition->{minion}) {
70 0 $self->mcp_info->test_type('minion');
71 0 $config->{prcs}->[0]->{skip_startscript} = 1;
72 0 $self->mcp_info->skip_install(1);
73 }
74 3 return $config;
75 }
76  
77  
78  
79 sub add_tapper_package_for_guest
80 9 ▶{
Subroutine add_tapper_package_for_guest: called CC=3 SCAR=11.0
Pod documented
81  
82 9 my ($self, $config, $guest, $guest_number) = @_;
83 9 my $tapper_package->{precondition_type} = '';
84  
85 9 ▶ my $guest_arch = $guest->{root}{arch} or return "No architecture set for guest #$guest_number";
Branch: 1 branch
BranchTrueFalseTotal
my $guest_arch = $guest->{"root"}{"arch"} or return "No architecture set for guest #$guest_number" 7 2 9
86 7 $tapper_package->{filename} = $self->cfg->{files}->{tapper_package}{$guest_arch};
87  
88 7 $tapper_package->{precondition_type} = 'package';
89 7 $tapper_package->{mountpartition} = $guest->{mountpartition};
90 7 ▶ $tapper_package->{mountfile} = $guest->{mountfile} if $guest->{mountfile};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"mountfile"} 7 0 7
91  
92 7 push @{$config->{preconditions}}, $tapper_package;
93 7 return $config;
94 }
95  
96  
97  
98 sub handle_guest_tests
99 9 ▶{
Subroutine handle_guest_tests: called CC=5 SCAR=16.2
Pod documented
100 9 my ($self, $config, $guest, $guest_number) = @_;
101  
102 $config = $self->parse_testprogram($config, $guest->{testprogram}, $guest_number)
103 9 ▶ if $guest->{testprogram};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"testprogram"} 5 4 9
104 9 ▶ return $config unless ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 9 9
105  
106 $config = $self->parse_testprogram_list($config, $guest->{testprogram_list}, $guest_number)
107 9 ▶ if $guest->{testprogram_list};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"testprogram_list"} 4 5 9
108 9 ▶ return $config unless ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 9 9
109  
110 9 return $config;
111 }
112  
113  
114  
115 sub parse_virt_host
116 7 ▶{
Subroutine parse_virt_host: called CC=4 SCAR=13.9
Pod documented
117 7 my ($self, $config, $virt) = @_;
118 7 my $lc_type = lc($virt->{host}->{root}->{precondition_type});
119 7 ▶ if ($lc_type eq 'image') {
Branch: 2 branches
BranchTrueFalseTotal
if ($lc_type eq 'image') { } 5 2 7
elsif ($lc_type eq 'autoinstall') { } 1 1 2
120 5 $config = $self->parse_image_precondition($config, $virt->{host}->{root});
121 }
122 elsif ($lc_type eq 'autoinstall') {
123 1 $config = $self->parse_autoinstall($config, $virt->{host}->{root});
124 }
125  
126 # additional preconditions for virt host
127 7 ▶ if ($virt->{host}->{preconditions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($virt->{"host"}{"preconditions"}) 5 2 7
128 5 push @{$config->{preconditions}}, @{$virt->{host}->{preconditions}};
129 }
130 7 return $config;
131 }
132  
133  
134  
135  
136 sub parse_virt_preconditions
137 7 ▶{
Subroutine parse_virt_preconditions: called CC=26 SCAR=33.3
Pod documented
138  
139 7 my ($self, $config, $virt) = @_;
140 7 my $retval;
141  
142 7 $config = $self->parse_virt_host($config, $virt);
143 7 ▶ $config = $self->parse_testprogram($config, $virt->{host}->{testprogram}, 0) if $virt->{host}->{testprogram};
Branch: 1 branch
BranchTrueFalseTotal
if $virt->{"host"}{"testprogram"} 0 7 7
144 7 ▶ $config = $self->parse_testprogram_list($config, $virt->{host}->{testprogram_list}, 0) if $virt->{host}->{testprogram_list};
Branch: 1 branch
BranchTrueFalseTotal
if $virt->{"host"}{"testprogram_list"} 2 5 7
145 7 ▶ return $config unless ref($config) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 7 7
146 7 ▶ my $total_guests = int @{$virt->{guests} || []};
Condition50%1/2
$virt->{'guests'} || []
l!l
70
MC/DC0%0/1
$virt->{'guests'} || []
$virt->{'guests'}
Truth table50%1/2
A
A= $virt->{'guests'}
Aresult
11
00
147  
148 7 ▶ for (my $guest_number = 1; $guest_number <= int @{$virt->{guests} || []}; $guest_number++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guest_number <= int @{$virt->{"guests"} or [];}) 9 5 14
Condition50%1/2
$virt->{'guests'} || []
l!l
140
MC/DC0%0/1
$virt->{'guests'} || []
$virt->{'guests'}
Truth table50%1/2
A
A= $virt->{'guests'}
Aresult
11
00
149 9 my $guest = $virt->{guests}->[$guest_number-1];
150  
151 9 $guest->{mountfile} = $guest->{root}->{mountfile};
152 9 $guest->{mountpartition} = $guest->{root}->{mountpartition};
153 9 $guest->{mountdir} = $guest->{root}->{mountdir};
154 9 delete $guest->{root}->{mountpartition};
155 9 ▶ delete $guest->{root}->{mountfile} if $guest->{root}->{mountfile};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"root"}{"mountfile"} 8 1 9
156 9 delete $guest->{root}->{mountdir};
157  
158  
159 9 $retval = $self->mcp_info->add_prc($guest_number, $self->cfg->{times}{boot_timeout});
160 9 ▶ return $retval if $retval;
Branch: 1 branch
BranchTrueFalseTotal
if $retval 0 9 9
161  
162 # if we have a qcow image, we need a raw image to copy PRC stuff to
163 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
164 9 my $mtype = $guest->{root}{mounttype};
165 9 ▶ if ($mtype eq 'raw') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mtype eq 'raw') { } 6 3 9
elsif ($mtype eq 'windows') { } 1 2 3
166 my $raw_image = {
167 precondition_type => 'rawimage',
168 name => basename($guest->{mountfile}),
169 path => dirname($guest->{mountfile})
170 6 };
171 6 push @{$config->{preconditions}}, $raw_image;
172 }
173 elsif ($mtype eq 'windows') {
174 my $raw_image = {
175 precondition_type => 'copyfile',
176 name => $self->cfg->{files}{windows_test_image},
177 dest => $guest->{mountfile},
178 1 protocol => 'nfs',
179 };
180 1 push @{$config->{preconditions}}, $raw_image;
181 }
182 26 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 9 ▶ push @{$config->{preconditions}}, $guest->{root} if $guest->{root}->{precondition_type};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"root"}{"precondition_type"} 8 1 9
185 9 ▶ push @{$config->{preconditions}}, $guest->{config} if exists $guest->{config}->{precondition_type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $guest->{"config"}{"precondition_type"} 6 3 9
186 9 ▶ if ($guest->{config}->{svm}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($guest->{'config'}{'svm'}) { } 1 8 9
elsif ($guest->{'config'}{'kvm'}) { } 0 8 8
elsif ($guest->{'config'}{'exec'}) { } 6 2 8
187 1 push @{$config->{prcs}->[0]->{config}->{guests}}, {svm=>$guest->{config}->{svm}};
188 } elsif ($guest->{config}->{kvm}) {
189 0 push @{$config->{prcs}->[0]->{config}->{guests}}, {exec=>$guest->{config}->{kvm}};
190 } elsif ($guest->{config}->{exec}) {
191 6 push @{$config->{prcs}->[0]->{config}->{guests}}, {exec=>$guest->{config}->{exec}};
192 }
193  
194 9 ▶ if ($guest->{testprogram} or $guest->{testprogram_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guest->{"testprogram"} or $guest->{"testprogram_list"}) 9 0 9
Condition66%2/3
$guest->{"testprogram"} or $guest->{"testprogram_list"}
l!l&&r!l&&!r
540
MC/DC0%0/2
$guest->{"testprogram"} or $guest->{"testprogram_list"}
$guest->{"testprogram"} $guest->{"testprogram_list"}
Truth table66%2/3
A or B
A= $guest->{"testprogram"}B= $guest->{"testprogram_list"}
ABresult
1X1
011
000
195 9 $config = $self->handle_guest_tests($config, $guest, $guest_number);
196 9 ▶ return $config unless ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 9 9
197 }
198  
199 # put guest preconditions into precondition list
200 9 foreach my $guest_precondition(@{$guest->{preconditions}}) {
201 4 ▶ if ( $guest_precondition->{precondition_type} eq 'testprogram' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($guest_precondition->{'precondition_type'} eq 'testprogram') { } 1 3 4
elsif ($guest_precondition->{'precondition_type'} eq 'testprogram') { } 0 3 3
202 1 $config = $self->parse_testprogram($config, $guest_precondition, $guest_number);
203 } elsif ( $guest_precondition->{precondition_type} eq 'testprogram' ) {
204 0 $config = $self->parse_testprogram_list($config, $guest_precondition, $guest_number);
205 } else {
206 3 $guest_precondition->{mountpartition} = $guest->{mountpartition};
207 3 ▶ $guest_precondition->{mountfile} = $guest->{mountfile} if $guest->{mountfile};
Branch: 1 branch
BranchTrueFalseTotal
if $guest->{"mountfile"} 3 0 3
208 3 push @{$config->{preconditions}}, $guest_precondition;
209 }
210 4 ▶ return $config unless ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 4 4
211 }
212  
213 # add a PRC for every guest
214 9 $config = $self->add_tapper_package_for_guest($config, $guest, $guest_number);
215 9 ▶ return $config unless ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 2 7 9
216  
217 7 $config->{prcs}->[$guest_number]->{mountfile} = $guest->{mountfile};
218 7 $config->{prcs}->[$guest_number]->{mountpartition} = $guest->{mountpartition};
219 7 $config->{prcs}->[$guest_number]->{config}->{guest_number} = $guest_number;
220 7 $config->{prcs}->[$guest_number]->{config}->{total_guests} = $total_guests;
221 }
222 5 ▶ $config->{prcs}->[0]->{config}->{guest_count} = int @{$virt->{guests} || []};
Condition50%1/2
$virt->{'guests'} || []
l!l
50
MC/DC0%0/1
$virt->{'guests'} || []
$virt->{'guests'}
Truth table50%1/2
A
A= $virt->{'guests'}
Aresult
11
00
223  
224 5 return $config;
225 }
226  
227  
228  
229 sub parse_grub
230 1 ▶{
Subroutine parse_grub: called CC=1 SCAR=0.0
Pod documented
231 1 my ($self, $config, $precondition) = @_;
232 1 $config->{grub} = $precondition->{config};
233 1 return $config;
234 }
235  
236  
237  
238  
239 sub parse_reboot
240 1 ▶{
Subroutine parse_reboot: called CC=1 SCAR=0.0
Pod documented
241 1 my ($self, $config, $reboot) = @_;
242 1 $self->mcp_info->set_max_reboot(0, $reboot->{count});
243 1 $config->{prcs}->[0]->{config}->{max_reboot} = $reboot->{count};
244 1 return $config;
245 }
246  
247  
248 sub parse_image_precondition
249 7 ▶{
Subroutine parse_image_precondition: called CC=6 SCAR=18.3
Pod documented
250 7 my ($self, $config, $precondition) = @_;
251 7 my $opt_pkg;
252  
253 7 ▶ if ($precondition->{arch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precondition->{"arch"}) 6 1 7
254 $opt_pkg = {precondition_type => 'package',
255 filename => $self->cfg->{files}->{tapper_package}{$precondition->{arch}},
256 6 };
257 6 ▶ $opt_pkg->{mountfile} = $precondition->{mountfile} if $precondition->{mountfile};
Branch: 1 branch
BranchTrueFalseTotal
if $precondition->{"mountfile"} 0 6 6
258 6 ▶ $opt_pkg->{mountpartition} = $precondition->{mountpartition} if $precondition->{mountpartition};
Branch: 1 branch
BranchTrueFalseTotal
if $precondition->{"mountpartition"} 0 6 6
259 6 delete $precondition->{arch};
260 }
261  
262 7 ▶ if ($precondition->{mount} eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($precondition->{'mount'} eq '/') { } 7 0 7
263 7 unshift @{$config->{preconditions}}, $precondition;
264 } else {
265 0 push @{$config->{preconditions}}, $precondition;
266 }
267  
268 7 ▶ if ($opt_pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_pkg) 6 1 7
269 6 push @{$config->{preconditions}}, $opt_pkg;
270 6 push @{$config->{preconditions}}, {precondition_type => 'exec',
271 filename => '/opt/tapper/perl/perls/current/bin/tapper-testsuite-hwtrack',
272 continue_on_error => 1 };
273 }
274 7 return $config;
275 }
276  
277  
278  
279 sub parse_cobbler_preconditions
280 2 ▶{
Subroutine parse_cobbler_preconditions: called CC=5 SCAR=16.2
Pod documented
281 2 my ($self, $config, $cobbler) = @_;
282 2 my $cmd = Tapper::Cmd::Cobbler->new();
283 2 my $host = $self->testrun->testrun_scheduling->host->name;
284 2 my $error;
285  
286  
287 # add host if not already known to Cobbler
288 2 my @hosts = eval{ $cmd->host_list({name => $host})};
289 2 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
290 2 ▶ if (not @hosts) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@hosts) 1 1 2
291 # one possible error is a race condition between list and host_new
292 # this should be rare enough to justify the issue for easier development
293 1 $error = $cmd->host_new($host);
294 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
295 }
296  
297 2 $error = $cmd->host_update({name => $host, profile => $cobbler->{profile}, "netboot-enabled" => 1});
298 2 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 2 2
299 2 $config->{cobbler} = $cobbler->{profile};
300 2 return $config;
301 }
302  
303  
304 sub parse_testprogram
305 33 ▶{
Subroutine parse_testprogram: called CC=12 SCAR=25.6
Pod documented
306 33 my ($self, $config, $testprogram, $prc_number) = @_;
307 33 ▶ $prc_number //= 0;
Condition100%2/2
$prc_number //= 0
l!l
276
MC/DC100%1/1
$prc_number //= 0
$prc_number
Truth table100%2/2
A
A= $prc_number
Aresult
11
00
308 33 ▶ $prc_number = $testprogram->{prc} if $testprogram->{prc}; # allow overriding PRC number for nesting
Branch: 1 branch
BranchTrueFalseTotal
if $testprogram->{"prc"} 0 33 33
309  
310 33 ▶ if (not $testprogram->{timeout}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($testprogram->{"timeout"}) 11 22 33
311 11 $testprogram->{timeout} = $testprogram->{timeout_testprogram};
312 11 delete $testprogram->{timeout_testprogram};
313 }
314 33 ▶ if ($testprogram->{execname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testprogram->{"execname"}) 6 27 33
315 6 $testprogram->{program} = $testprogram->{execname};
316 6 delete $testprogram->{execname};
317 }
318 33 ▶ $testprogram->{runtime} = $testprogram->{runtime} || $self->cfg->{times}{test_runtime_default};
Condition66%2/3
$testprogram->{'runtime'} || $self->cfg->{'times'}{'test_runtime_default'}
l!l&&r!l&&!r
4290
MC/DC0%0/2
$testprogram->{'runtime'} || $self->cfg->{'times'}{'test_runtime_default'}
$testprogram->{'runtime'} $self->cfg->{'times'}{'test_runtime_default'}
Truth table66%2/3
A || B
A= $testprogram->{'runtime'}B= $self->cfg->{'times'}{'test_runtime_default'}
ABresult
1X1
011
000
319  
320 33 ▶ $testprogram->{timeout} = ($self->cfg->{times}{default_testprogram_timeout} // 600) unless defined $testprogram->{timeout};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $testprogram->{"timeout"} 5 28 33
Condition50%1/2
$self->cfg->{"times"}{"default_testprogram_timeout"} // 600
l!l
50
MC/DC0%0/1
$self->cfg->{"times"}{"default_testprogram_timeout"} // 600
$self->cfg->{"times"}{"default_testprogram_timeout"}
Truth table50%1/2
A
A= $self->cfg->{"times"}{"default_testprogram_timeout"}
Aresult
11
00
321 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
322 33 push @{$config->{prcs}->[$prc_number]->{config}->{testprogram_list}}, $testprogram;
323  
324 $config->{prcs}->[$prc_number]->{mountfile} = $testprogram->{mountfile}
325 33 ▶ if $testprogram->{mountfile} and not $config->{prcs}->[$prc_number]->{mountfile};
Branch: 1 branch
BranchTrueFalseTotal
if $testprogram->{"mountfile"} and not $config->{"prcs"}[$prc_number]{"mountfile"} 0 33 33
Condition33%1/3
$testprogram->{"mountfile"} and not $config->{"prcs"}[$prc_number]{"mountfile"}
!ll&&!rl&&r
3300
MC/DC0%0/2
$testprogram->{"mountfile"} and not $config->{"prcs"}[$prc_number]{"mountfile"}
$testprogram->{"mountfile"} not $config->{"prcs"}[$prc_number]{"mountfile"}
Truth table33%1/3
A and not(B)
A= $testprogram->{"mountfile"}B= not $config->{"prcs"}[$prc_number]{"mountfile"}
ABresult
0X0
100
111
326 $config->{prcs}->[$prc_number]->{mountpartition} = $testprogram->{mountpartition}
327 33 ▶ if $testprogram->{mountpartition} and not $config->{prcs}->[$prc_number]->{mountpartition};
Branch: 1 branch
BranchTrueFalseTotal
if $testprogram->{"mountpartition"} and not $config->{"prcs"}[$prc_number]{"mountpartition"} 0 33 33
Condition33%1/3
$testprogram->{"mountpartition"} and not $config->{"prcs"}[$prc_number]{"mountpartition"}
!ll&&!rl&&r
3300
MC/DC0%0/2
$testprogram->{"mountpartition"} and not $config->{"prcs"}[$prc_number]{"mountpartition"}
$testprogram->{"mountpartition"} not $config->{"prcs"}[$prc_number]{"mountpartition"}
Truth table33%1/3
A and not(B)
A= $testprogram->{"mountpartition"}B= not $config->{"prcs"}[$prc_number]{"mountpartition"}
ABresult
0X0
100
111
328  
329 33 $self->mcp_info->add_testprogram($prc_number, $testprogram);
330 26 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
331 33 return $config;
332  
333 }
334  
335  
336 sub parse_testprogram_list
337 6 ▶{
Subroutine parse_testprogram_list: called CC=3 SCAR=11.1
Pod documented
338 6 my ($self, $config, $testprogram_list, $prc_number) = @_;
339  
340 6 ▶ return $config unless ref $testprogram_list eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $testprogram_list eq "ARRAY" 0 6 6
341 6 foreach my $testprogram (@$testprogram_list) {
342 21 $config = $self->parse_testprogram($config, $testprogram, $prc_number);
343 }
344 6 return $config;
345 }
346  
347  
348  
349  
350 sub parse_autoinstall
351 3 ▶{
Subroutine parse_autoinstall: called CC=5 SCAR=21.5
Pod documented
352 3 my ($self, $config, $autoinstall) = @_;
353  
354 3 ▶ if ($autoinstall->{grub_text}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($autoinstall->{'grub_text'}) { } 3 0 3
elsif ($autoinstall->{'grub_file'}) { } 0 0 0
355 3 $config->{installer_grub} = $autoinstall->{grub_text};
356 } elsif ($autoinstall->{grub_file}) {
357 0 ▶ open my $fh, "<", $autoinstall->{grub_file} or return "Can not open grub file ( ".$autoinstall->{grub_file}." ):$!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $autoinstall->{"grub_file"} or return 'Can not open grub file ( ' . $autoinstall->{"grub_file"} . " ):$!" 0 0 0
358 0 $config->{installer_grub} = do {local $\; <$fh>};
359 0 close $fh;
360 } else {
361 0 return "Can not find autoinstaller grub config";
362 }
363  
364 3 $config->{autoinstall} = 1;
365 3 $config->{paths}{base_dir} = '/';
366 3 ▶ my $timeout = $autoinstall->{timeout} || $self->cfg->{times}{installer_timeout};
Condition66%2/3
$autoinstall->{'timeout'} || $self->cfg->{'times'}{'installer_timeout'}
l!l&&r!l&&!r
120
MC/DC0%0/2
$autoinstall->{'timeout'} || $self->cfg->{'times'}{'installer_timeout'}
$autoinstall->{'timeout'} $self->cfg->{'times'}{'installer_timeout'}
Truth table66%2/3
A || B
A= $autoinstall->{'timeout'}B= $self->cfg->{'times'}{'installer_timeout'}
ABresult
1X1
011
000
367 3 $self->mcp_info->set_installer_timeout($timeout);
368 3 return $config;
369 }
370  
371  
372 sub update_installer_grub
373 19 ▶{
Subroutine update_installer_grub: called CC=2 SCAR=6.9
Pod documented
374 19 my ($self, $config) = @_;
375  
376 19 ▶ $config->{installer_grub} = $self->cfg->{mcp}{installer}{default_grub} if not $config->{installer_grub};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"installer_grub"} 16 3 19
377 19 return $config;
378 }
379  
380  
381 sub produce
382 6 ▶{
Subroutine produce: called CC=3 SCAR=11.1
Pod documented
383 6 my ($self, $config, $precondition) = @_;
384 6 my $producer = Tapper::Producer->new();
385 6 my $producer_config = $producer->produce($self->testrun->testrun_scheduling, $precondition);
386  
387 6 ▶ die $producer_config if not ref($producer_config) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $producer_config eq "HASH" 0 6 6
388  
389 6 ▶ if ($producer_config->{topic}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($producer_config->{"topic"}) 6 0 6
390 6 $self->testrun->topic_name($producer_config->{topic});
391 6 $self->testrun->update;
392 }
393 6 my @precond_array = Load($producer_config->{precondition_yaml});
394 6 return \@precond_array;
395 }
396  
397  
398  
399 sub parse_produce_precondition
400 1 ▶{
Subroutine parse_produce_precondition: called CC=5 SCAR=16.4
Pod documented
401 1 my ($self, $config, $precondition) = @_;
402  
403 1 my $error;
404 0 ▶ my $produced_preconditions = try {$self->produce($config, $precondition->precondition_as_hash)} catch {$error = $_};
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
405 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
406  
407 1 ▶ return $produced_preconditions
Branch: 1 branch
BranchTrueFalseTotal
unless ref $produced_preconditions eq "ARRAY" 0 1 1
408 unless ref($produced_preconditions) eq 'ARRAY';
409 1 my $position = model->resultset('TestrunPrecondition')->search({testrun_id => $self->testrun->id,
410 precondition_id => $precondition->id}, {rows => 1})->first->succession;
411 1 $self->testrun->disassign_preconditions($precondition->id);
412  
413 1 foreach my $produced_precondition (@$produced_preconditions) {
414 2 my ($new_id) = model->resultset('Precondition')->add( [$produced_precondition] );
415 2 $self->testrun->insert_preconditions($position++, $new_id);
416  
417 2 my ($new_precondition) = model->resultset('Precondition')->find( $new_id );
418 2 $config = $self->parse_precondition($config, $new_precondition);
419 2 ▶ return $config unless ref($config) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 2 2
420 }
421 1 return $config;
422  
423 }
424  
425  
426 sub produce_preconds_in_arrayref
427 2 ▶{
Subroutine produce_preconds_in_arrayref: called CC=5 SCAR=16.3
Pod documented
428 2 my ($self, $config, $preconditions) = @_;
429 2 my @new_preconds;
430  
431 my $error;
432 2 ▶ return "Did not receive an array ref for 'produce_preconds_in_arrayref'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $preconditions eq "ARRAY" 0 2 2
433 unless ref $preconditions eq 'ARRAY';
434  
435 2 foreach my $precondition ( @$preconditions ) {
436 5 ▶ if (lc($precondition->{precondition_type}) eq 'produce') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $precondition->{'precondition_type'} eq 'produce') { } 1 4 5
437 0 ▶ my $produced_preconditions = try {$self->produce($config, $precondition)} catch {$error = $_};
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
438 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
439 1 push @new_preconds, @$produced_preconditions;
440 } else {
441 4 push @new_preconds, $precondition;
442 }
443 }
444 2 @$preconditions = @new_preconds;
445 2 return 0;
446 }
447  
448  
449 sub produce_virt_precondition
450 7 ▶{
Subroutine produce_virt_precondition: called CC=11 SCAR=25.2
Pod documented
451 7 my ($self, $config, $precondition) = @_;
452 7 local $Data::DPath::USE_SAFE; # path not from user, Safe.pm deactivated for debug and speed
453 7 my @producers = dpath('//*[key eq "precondition_type" and lc(value) eq "produce"]/../..')->match($precondition);
454 7 foreach my $producer (@producers) {
455 3 ▶ if (ref $producer eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $producer eq 'ARRAY') { } 1 2 3
elsif (ref $producer eq 'HASH') { } 2 0 2
456 1 my $error = $self->produce_preconds_in_arrayref($config, $producer);
457 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
458 } elsif (ref $producer eq 'HASH') {
459 2 foreach my $key ( keys %$producer ) {
460 5 ▶ if (ref($producer->{$key}) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $producer->{$key} eq 'ARRAY') { } 1 4 5
elsif (ref $producer->{$key} eq 'HASH' and lc $producer->{$key}{'precondition_type'} eq 'produce') { } 4 0 4
461 1 my $error = $self->produce_preconds_in_arrayref($config, $producer->{$key});
462 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
463 ▶ } elsif (ref($producer->{$key}) eq 'HASH' and
Condition33%1/3
ref $producer->{$key} eq "HASH" and lc $producer->{$key}{"precondition_type"} eq "produce"
!ll&&!rl&&r
004
MC/DC0%0/2
ref $producer->{$key} eq "HASH" and lc $producer->{$key}{"precondition_type"} eq "produce"
ref $producer->{$key} eq "HASH" lc $producer->{$key}{"precondition_type"} eq "produce"
Truth table33%1/3
A and B
A= ref $producer->{$key} eq "HASH"B= lc $producer->{$key}{"precondition_type"} eq "produce"
ABresult
0X0
100
111
464 lc($producer->{$key}->{precondition_type}) eq 'produce') {
465 4 my $error;
466 0 ▶ my $produced_preconditions = try {$self->produce($config, $producer->{$key})} catch {$error = $_};
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
467 4 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 4 4
468 4 $producer->{$key} = $produced_preconditions->[0];
469 }
470 }
471 }
472 }
473 7 return $precondition;
474 }
475  
476  
477  
478 sub parse_precondition
479 31 ▶{
Subroutine parse_precondition: called CC=15 SCAR=27.4
Pod documented
480 31 my ($self, $config, $precondition_result) = @_;
481 31 my $precondition = $precondition_result->precondition_as_hash;
482  
483 31 my $type = lc($precondition->{precondition_type});
484 31 ▶ if ($type eq 'produce') {
Branch: 13 branches
BranchTrueFalseTotal
if ($type eq 'produce') { } 1 30 31
elsif ($type eq 'image') { } 2 28 30
elsif ($type eq 'virt') { } 7 21 28
elsif ($type eq 'grub') { } 1 20 21
elsif ($type eq 'installer_stop') { } 1 19 20
elsif ($type eq 'testrun_stop') { } 0 19 19
elsif ($type eq 'reboot') { } 1 18 19
elsif ($type eq 'autoinstall') { } 2 16 18
elsif ($type eq 'testprogram') { } 6 10 16
elsif ($type eq 'testprogram_list') { } 0 10 10
elsif ($type eq 'simnow') { } 0 10 10
elsif ($type eq 'hint') { } 3 7 10
elsif ($type eq 'cobbler') { } 2 5 7
485 1 $config = $self->parse_produce_precondition($config, $precondition_result);
486 }
487 elsif ($type eq 'image' ) {
488 2 $config = $self->parse_image_precondition($config, $precondition);
489 }
490 elsif ($type eq 'virt' ) {
491 7 $precondition = $self->produce_virt_precondition($config, $precondition);
492 7 ▶ return $precondition unless ref $precondition eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $precondition eq "HASH" 0 7 7
493  
494  
495 7 $precondition_result->precondition(Dump($precondition));
496 7 $precondition_result->update;
497  
498 7 $config = $self->parse_virt_preconditions($config, $precondition);
499 }
500 elsif ($type eq 'grub') {
501 1 $config = $self->parse_grub($config, $precondition);
502 }
503 elsif ($type eq 'installer_stop') {
504 1 $config->{installer_stop} = 1;
505 }
506 elsif ($type eq 'testrun_stop') {
507 0 $config->{testrun_stop} = 1;
508 }
509 elsif ($type eq 'reboot') {
510 1 $config = $self->parse_reboot($config, $precondition);
511 }
512 elsif ($type eq 'autoinstall') {
513 2 $config = $self->parse_autoinstall($config, $precondition);
514 }
515 elsif ($type eq 'testprogram') {
516 6 $config = $self->parse_testprogram($config, $precondition);
517 }
518 elsif ($type eq 'testprogram_list') {
519 0 $config = $self->parse_testprogram_list($config, $precondition);
520 }
521 elsif ($type eq 'simnow' ) {
522 0 $config=$self->parse_simnow_preconditions($config, $precondition);
523 }
524 elsif ($type eq 'hint' ) {
525 3 $config=$self->parse_hint_preconditions($config, $precondition);
526 }
527 elsif ($type eq 'cobbler' ) {
528 2 $config=$self->parse_cobbler_preconditions($config, $precondition);
529 }
530 else {
531 5 push @{$config->{preconditions}}, $precondition;
532 }
533  
534  
535 31 return $config;
536 }
537  
538 # replace $TAPPER_PLACEHOLDERS in grub config file
539 sub grub_substitute_variables
540 38 ▶{
Subroutine grub_substitute_variables: called CC=4 SCAR=14.0
Pod undocumented
541 26 ▶ no warnings 'uninitialized'; # some options may not be set, especially during testing. This is ok.
Subroutine BEGIN: called CC=1 SCAR=0.0
542 38 my ($self, $config, $grubtext) = @_;
543  
544 38 my $tapper_host = $config->{mcp_host};
545 38 my $tapper_port = $config->{mcp_port};
546 38 my $packed_ip = gethostbyname($tapper_host);
547 38 ▶ die "Can not get an IP address for tapper_host ($tapper_host): $!" if not defined $packed_ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed_ip 0 38 38
548 38 my $tapper_ip = inet_ntoa($packed_ip);
549 38 my $tapper_environment = Tapper::Config::_getenv();
550 38 my $testrun = $config->{test_run};
551 38 my $nfsroot = $config->{paths}{nfsroot};
552 38 my $kernel = $config->{files}{installer_kernel};
553 38 my $tftp_server = $self->cfg->{tftp_server_address};
554 38 ▶ my $hostoptions = $self->cfg->{grub_completion_HOSTOPTIONS}{$config->{hostname}} || $self->cfg->{grub_completion_HOSTOPTIONS}{_default};
Condition33%1/3
$self->cfg->{'grub_completion_HOSTOPTIONS'}{$config->{'hostname'}} || $self->cfg->{'grub_completion_HOSTOPTIONS'}{'_default'}
l!l&&r!l&&!r
0380
MC/DC0%0/2
$self->cfg->{'grub_completion_HOSTOPTIONS'}{$config->{'hostname'}} || $self->cfg->{'grub_completion_HOSTOPTIONS'}{'_default'}
$self->cfg->{'grub_completion_HOSTOPTIONS'}{$config->{'hostname'}} $self->cfg->{'grub_completion_HOSTOPTIONS'}{'_default'}
Truth table33%1/3
A || B
A= $self->cfg->{'grub_completion_HOSTOPTIONS'}{$config->{'hostname'}}B= $self->cfg->{'grub_completion_HOSTOPTIONS'}{'_default'}
ABresult
1X1
011
000
555 38 ▶ my $xenhostoptions = $self->cfg->{grub_completion_XENHOSTOPTIONS}{$config->{hostname}} || $self->cfg->{grub_completion_XENHOSTOPTIONS}{_default};
Condition33%1/3
$self->cfg->{'grub_completion_XENHOSTOPTIONS'}{$config->{'hostname'}} || $self->cfg->{'grub_completion_XENHOSTOPTIONS'}{'_default'}
l!l&&r!l&&!r
0038
MC/DC0%0/2
$self->cfg->{'grub_completion_XENHOSTOPTIONS'}{$config->{'hostname'}} || $self->cfg->{'grub_completion_XENHOSTOPTIONS'}{'_default'}
$self->cfg->{'grub_completion_XENHOSTOPTIONS'}{$config->{'hostname'}} $self->cfg->{'grub_completion_XENHOSTOPTIONS'}{'_default'}
Truth table33%1/3
A || B
A= $self->cfg->{'grub_completion_XENHOSTOPTIONS'}{$config->{'hostname'}}B= $self->cfg->{'grub_completion_XENHOSTOPTIONS'}{'_default'}
ABresult
1X1
011
000
556  
557 38 $grubtext =~ s|\$TAPPER_OPTIONS\b|tapper_ip=$tapper_ip tapper_port=$tapper_port testrun=$testrun tapper_host=$tapper_host tapper_environment=$tapper_environment|g;
558 38 $grubtext =~ s|\$TAPPER_NFSROOT\b|$nfsroot|g;
559 38 $grubtext =~ s|\$TAPPER_TFTPSERVER\b|$tftp_server|g;
560 38 $grubtext =~ s|\$TAPPER_KERNEL\b|$kernel|g;
561 38 $grubtext =~ s|\$HOSTOPTIONS\b|$hostoptions|g;
562 38 $grubtext =~ s|\$XENHOSTOPTIONS\b|$xenhostoptions|g;
563  
564 38 return $grubtext;
565 }
566  
567  
568 sub get_install_config
569 21 ▶{
Subroutine get_install_config: called CC=12 SCAR=25.1
Pod documented
570 21 my ($self, $config) = @_;
571  
572  
573 21 my $retval = $self->mcp_info->add_prc(0, $self->cfg->{times}{boot_timeout});
574 21 ▶ return $retval if $retval;
Branch: 1 branch
BranchTrueFalseTotal
if $retval 0 21 21
575  
576 {
577 26 ▶ no warnings 'uninitialized'; # allowing this timeout to be undef is a feature
Subroutine BEGIN: called CC=1 SCAR=0.0
578 21 $retval = $self->mcp_info->set_keep_alive_timeout($self->cfg->{keep_alive}{timeout_receive});
579 21 $config->{times}{keep_alive_timeout} = $self->cfg->{keep_alive}{timeout_send};
580 21 $config->{mcp_callback_handler}{plugin} = $self->cfg->{mcp_callback_handler}{plugin};
581 21 $config->{mcp_callback_handler}{plugin_plugin} = $self->cfg->{mcp_callback_handler}{plugin_options};
582 }
583  
584 PRECONDITION:
585 21 foreach my $precondition_result ( $self->testrun->ordered_preconditions) {
586 29 $config = $self->parse_precondition($config, $precondition_result);
587 # was not able to parse precondition and thus
588 # return received error string
589 29 ▶ if (not ref($config) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $config eq "HASH") 2 27 29
590 2 return $config;
591 }
592 }
593  
594  
595  
596 # always have a PRC0 even without any test programs
597 19 ▶ unless ($self->mcp_info->test_type() eq 'simnow'
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->mcp_info->test_type eq "simnow" or $config->{"prcs"}) 6 13 19
Condition100%3/3
$self->mcp_info->test_type eq "simnow" or $config->{"prcs"}
l!l&&r!l&&!r
1126
MC/DC100%2/2
$self->mcp_info->test_type eq "simnow" or $config->{"prcs"}
$self->mcp_info->test_type eq "simnow" $config->{"prcs"}
Truth table100%3/3
A or B
A= $self->mcp_info->test_type eq "simnow"B= $config->{"prcs"}
ABresult
1X1
011
000
598 or $config->{prcs}) {
599 6 $config->{prcs}->[0] = {testprogram_list => []};
600 }
601  
602 # generate installer config
603 19 $config = $self->update_installer_grub($config);
604  
605 19 my $current_prc_number = 0;
606 19 ▶ while (my $prc_precondition = shift(@{$config->{prcs}})){
Branch: 1 branch
BranchTrueFalseTotal
if (my $prc_precondition = shift @{$$config{"prcs"};}) 25 19 44
607 25 $prc_precondition->{precondition_type} = "prc";
608 25 $prc_precondition->{config}->{guest_number} = $current_prc_number++;
609 25 push(@{$config->{preconditions}}, $prc_precondition);
610 }
611  
612 19 ▶ $config->{grub} = $self->cfg->{mcp}{test}{default_grub} if not $config->{grub};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"grub"} 18 1 19
613  
614 19 my $error;
615 19 ▶ $config->{installer_grub} = try { $self->grub_substitute_variables($config, $config->{installer_grub}) }
Subroutine __ANON__: called CC=1 SCAR=0.0
616 0 ▶ catch { $error = $_} if $config->{installer_grub}; return $error if $error;
Subroutine __ANON__: not called CC=1 SCAR=0.8
Branch: 2 branches
BranchTrueFalseTotal
if $config->{"installer_grub"} 19 0 19
if $error 0 19 19
617 19 ▶ $config->{grub} = try { $self->grub_substitute_variables($config, $config->{grub}) }
Subroutine __ANON__: called CC=1 SCAR=0.0
618 0 ▶ catch { $error = $_} if ($config->{grub}); return $error if $error;
Subroutine __ANON__: not called CC=1 SCAR=0.8
Branch: 2 branches
BranchTrueFalseTotal
if $config->{"grub"} 19 0 19
if $error 0 19 19
619 19 return $config;
620 }
621  
622  
623  
624 sub get_common_config
625 24 ▶{
Subroutine get_common_config: called CC=13 SCAR=28.2
Pod documented
626 24 my ($self) = @_;
627 24 my $config;
628 24 my $testrun = $self->testrun;
629  
630 24 $config->{paths} = $self->cfg->{paths};
631 24 $config->{times} = $self->cfg->{times};
632 24 $config->{files} = $self->cfg->{files};
633 24 ▶ $config->{mcp_host} = Sys::Hostname::hostname() || $self->cfg->{mcp_host};
Condition33%1/3
Sys::Hostname::hostname() || $self->cfg->{'mcp_host'}
l!l&&r!l&&!r
2400
MC/DC0%0/2
Sys::Hostname::hostname() || $self->cfg->{'mcp_host'}
Sys::Hostname::hostname() $self->cfg->{'mcp_host'}
Truth table33%1/3
A || B
A= Sys::Hostname::hostname()B= $self->cfg->{'mcp_host'}
ABresult
1X1
011
000
634 24 $config->{mcp_server} = $config->{mcp_host};
635 24 $config->{mcp_port} = $self->cfg->{mcp_port};
636 24 $config->{sync_port} = $self->cfg->{sync_port};
637 24 $config->{report_server} = $self->cfg->{report_server};
638 24 $config->{report_port} = $self->cfg->{report_port};
639 24 $config->{report_api_port} = $self->cfg->{report_api_port};
640 $config->{prc_nfs_server} = $self->cfg->{prc_nfs_server}
641 24 ▶ if $self->cfg->{prc_nfs_server}; # prc_nfs_path is set by merging paths above
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"prc_nfs_server"} 24 0 24
642 24 $config->{test_run} = $testrun->id;
643 24 $config->{testrun_id} = $testrun->id;
644  
645 24 ▶ if ($testrun->testplan_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testrun->testplan_id) 0 24 24
646 0 $config->{testplan} = { id => $testrun->testplan_id, path => $testrun->testplan_instance->path };
647 }
648  
649 24 ▶ if ($self->testrun->scenario_element) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testrun->scenario_element) 1 23 24
650 1 $config->{scenario_id} = $self->testrun->scenario_element->scenario_id;
651 1 $config->{paths}{sync_path}.="/".$config->{scenario_id}."/";
652 1 my $path = $config->{paths}{sync_path};
653 1 $config->{files}{sync_file} = "$path/syncfile";
654  
655 1 ▶ if ($self->testrun->scenario_element->peer_elements->search({}, {rows => 1})->first->testrun->id == $testrun->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testrun->scenario_element->peer_elements->search({}, {"rows", 1})->first->testrun->id == $testrun->id) 1 0 1
656 1 ▶ if (not -d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 1 0 1
657 1 File::Path::mkpath($path, {error => \my $retval});
658 ERROR:
659 1 foreach my $diag (@$retval) {
660 0 my ($file, $message) = each %$diag;
661 # $file might have been created by other scenario element between -d and mkpath
662 # in this case ignore the error
663 0 ▶ next ERROR if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 0 0 0
664 0 ▶ return "general error: $message\n" if $file eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "" 0 0 0
665 0 return "Can't create $file: $message";
666 }
667 }
668  
669 # shortest way to deal with undefined options
670 1 ▶ if (not eval {$self->testrun->scenario_element->scenario->options->{no_sync}})
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $self->testrun->scenario_element->scenario->options->{"no_sync"} } }) 1 0 1
671 {
672 1 my @peers = map {$_->testrun->testrun_scheduling->host->name} $self->testrun->scenario_element->peer_elements->all;
673 1 ▶ if (sysopen(my $fh, $config->{files}{sync_file}, O_CREAT | O_EXCL |O_RDWR )) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysopen my $fh, $config->{"files"}{"sync_file"}, 194) 1 0 1
674 1 print $fh $self->testrun->scenario_element->peer_elements->count;
675 1 close $fh;
676 } # else trust the creator
677 1 my $error;
678 1 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
679 1 YAML::DumpFile($config->{files}{sync_file}, \@peers);
680 0 ▶ } catch { $error = $_};
Subroutine __ANON__: not called CC=1 SCAR=1.2
681 1 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
682 }
683 }
684 }
685 24 return ($config);
686 }
687  
688  
689  
690  
691 sub get_test_config
692 2 ▶{
Subroutine get_test_config: called CC=2 SCAR=6.9
Pod documented
693 2 my ($self) = @_;
694 2 my $retval;
695  
696  
697 2 ▶ for (my $i=0; $i<=$self->mcp_info->get_prc_count(); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->mcp_info->get_prc_count) 2 2 4
698 2 push @$retval, {testprogram_list => [ $self->mcp_info->get_testprograms($i) ]};
699 }
700 2 return $retval;
701 }
702  
703  
704  
705 sub create_config
706 21 ▶{
Subroutine create_config: called CC=2 SCAR=7.0
Pod documented
707 21 my ($self) = @_;
708 21 my $config = $self->get_common_config();
709 21 ▶ return $config if not ref $config eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 21 21
710  
711 21 $config = $self->get_install_config($config);
712 21 return $config;
713 }
714  
715  
716 sub write_config
717 5 ▶{
Subroutine write_config: called CC=3 SCAR=11.1
Pod documented
718 5 my ($self, $config, $cfg_file) = @_;
719 5 my $cfg = YAML::Dump($config);
720 5 ▶ $cfg_file = $self->cfg->{paths}{localdata_path}."/$cfg_file" if not $cfg_file =~ m(^/);
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg_file =~ m[^/] 5 0 5
721 5 my $dir = dirname($cfg_file);
722 5 $self->makedir($dir);
723 5 ▶ open (my $file, ">", $cfg_file)
Branch: 1 branch
BranchTrueFalseTotal
open my $file, ">", $cfg_file or return "Can't open config file $cfg_file for writing: $!" 5 0 5
724 or return "Can't open config file $cfg_file for writing: $!";
725 5 print $file $cfg;
726 5 close $file;
727 5 return 0;
728 }
729  
730 26 1;
731  
732 __END__
« MCP/Child.pm ↑ Summary MCP/Scheduler/Controller.pm »