blib/lib/Tapper/Reports/Web/Controller/Tapper/ContinuousTestruns.pm

filter: Statementstmt 28.1% 51 / 181 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 48.4% 16 / 33 Podpod 0.0% 0 / 10 totaltotal 24.4% 67 / 274 CC 26 SCAR 43.9
CC
26
Cov
23%
__ANON__
272.0
edit_page
30.0
update_testrun
20.0
CRAP 80.5
« blib/lib/Tapper/Reports/Web/Controller/Tapper/ReportFile/Id.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Rss.pm »
1 package Tapper::Reports::Web::Controller::Tapper::ContinuousTestruns;
2 13 our $AUTHORITY = 'cpan:TAPPER';
3 13 $Tapper::Reports::Web::Controller::Tapper::ContinuousTestruns::VERSION = '5.0.17';
4 # ABSTRACT: Tapper - List and edit continuous tests
5  
6 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use parent 'Tapper::Reports::Web::Controller::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub index :Path : Args() {
Subroutine index: not called CC=1 SCAR=6.9
15  
16 0 my ( $or_self, $or_c ) = @_;
17  
18 0 $or_c->go('/tapper/continuoustestruns/prepare_list');
19  
20 0 return 1;
21  
22 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 0 ▶sub prepare_list : Private {
Subroutine prepare_list: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 0 my ( $or_self, $or_c ) = @_;
27  
28 0 $or_c->stash->{head_overview} = 'Continuous Testruns';
29 0 $or_c->stash->{continuous_testruns} = $or_c->model('TestrunDB')->fetch_raw_sql({
30 query_name => 'testruns::continuous_list',
31 fetch_type => '@%',
32 });
33  
34 0 return 1;
35  
36 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 0 ▶sub update_testrun : Private {
Subroutine update_testrun: not called CC=4 SCAR=30.0
Pod undocumented
39  
40 0 my ( $or_self, $or_schema, $hr_atts ) = @_;
41  
42 0 for my $s_key (qw/ old_state testrun_id /) {
43 0 ▶ if (! $hr_atts->{$s_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_atts->{$s_key}) 0 0 0
44 0 return "missing attribute: '$s_key'";
45 }
46 }
47  
48 0 require DateTime;
49 0 my $dt_now = DateTime->now()->strftime('%F %T');
50  
51 0 my $i_success = 0;
52 0 ▶ if ( $hr_atts->{testrun_id} =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_atts->{'testrun_id'} =~ /^\d+$/) { } 0 0 0
53  
54 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 ▶ $or_schema->txn_do(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
56  
57 0 my $hr_update = {};
58 0 ▶ if ( exists $hr_atts->{new_state} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hr_atts->{"new_state"}) 0 0 0
59 0 $hr_update->{status} = $hr_atts->{new_state};
60 }
61 0 ▶ if ( exists $hr_atts->{auto_rerun} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hr_atts->{"auto_rerun"}) 0 0 0
62 0 $hr_update->{auto_rerun} = $hr_atts->{auto_rerun};
63 }
64  
65 $or_schema->resultset("TestrunScheduling")
66 ->search({
67 auto_rerun => 1,
68 testrun_id => $hr_atts->{testrun_id},
69 status => $hr_atts->{old_state},
70 })
71 0 ->update( $hr_update )
72 ;
73  
74 0 });
75 }
76 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 return "Transaction failed: $_";
78 0 };
79  
80 0 return '';
81 }
82 else {
83 0 return "Testrun-ID has a wrong format";
84 }
85  
86 0 return '';
87  
88 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 0 ▶sub pause : Local {
Subroutine pause: not called CC=1 SCAR=6.9
Pod undocumented
91  
92 0 my ( $or_self, $or_c ) = @_;
93  
94 $or_c->stash->{error} = $or_self->update_testrun(
95 $or_c->model('TestrunDB'),
96 {
97 old_state => 'schedule',
98 new_state => 'prepare',
99 testrun_id => $or_c->req->params->{testrun_id}
100 },
101 0 );
102  
103 0 $or_c->response->redirect('/tapper/continuoustestruns');
104 0 $or_c->detach();
105  
106 0 return 1;
107  
108 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 0 ▶sub continue : Local {
Subroutine continue: not called CC=1 SCAR=6.9
Pod undocumented
111  
112 0 my ( $or_self, $or_c ) = @_;
113  
114 $or_c->stash->{error} = $or_self->update_testrun(
115 $or_c->model('TestrunDB'),
116 {
117 old_state => 'prepare',
118 new_state => 'schedule',
119 testrun_id => $or_c->req->params->{testrun_id}
120 },
121 0 );
122  
123 0 $or_c->response->redirect('/tapper/continuoustestruns');
124 0 $or_c->detach();
125  
126 0 return 1;
127  
128 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 0 ▶sub cancel : Local {
Subroutine cancel: not called CC=1 SCAR=6.9
Pod undocumented
131  
132 0 my ( $or_self, $or_c ) = @_;
133  
134 $or_c->stash->{error} = $or_self->update_testrun(
135 $or_c->model('TestrunDB'),
136 {
137 auto_rerun => 0,
138 old_state => [ 'prepare', 'schedule' ],
139 testrun_id => $or_c->req->params->{testrun_id}
140 },
141 0 );
142  
143 0 $or_c->response->redirect('/tapper/continuoustestruns');
144 0 $or_c->detach();
145  
146 0 return 1;
147  
148 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
149  
150 0 ▶sub clone : Local {
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
151  
152 0 my ( $or_self, $or_c ) = @_;
153  
154 0 $or_c->stash->{command} = 'clone';
155 0 $or_c->go('/tapper/continuoustestruns/edit_page');
156  
157 0 return 1;
158  
159 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 0 ▶sub edit : Local {
Subroutine edit: not called CC=1 SCAR=6.9
Pod undocumented
162  
163 0 my ( $or_self, $or_c ) = @_;
164  
165 0 $or_c->stash->{command} = 'edit';
166 0 $or_c->go('/tapper/continuoustestruns/edit_page');
167  
168 0 return 1;
169  
170 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
171  
172 0 ▶sub edit_page : Private {
Subroutine edit_page: not called CC=5 SCAR=34.0
Pod undocumented
173  
174 0 my ( $or_self, $or_c ) = @_;
175  
176 0 $or_c->stash->{head_overview} = 'Continuous Testruns - ' . ucfirst( $or_c->stash->{command} );
177  
178 0 ▶ if (! $or_c->stash->{continuous_testrun} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_c->stash->{"continuous_testrun"}) 0 0 0
179 my $or_testrun = $or_c
180 ->model('TestrunDB')
181 ->resultset('Testrun')
182 ->search({
183 'testrun_scheduling.auto_rerun' => 1,
184 'testrun_scheduling.testrun_id' => $or_c->req->params->{testrun_id},
185 0 'testrun_scheduling.status' => [qw/ prepare schedule /],
186 },{
187 'join' => [
188 'testrun_scheduling',
189 { 'testrun_requested_host' => 'host' },
190 { 'testrun_precondition' => 'precondition' },
191 ],
192 'order_by' => {
193 -asc => 'testrun_precondition.succession',
194 },
195 })
196 ->first()
197 ;
198 $or_c->stash->{continuous_testrun} = {
199 testrun_id => $or_c->req->params->{testrun_id},
200 topic => $or_testrun->topic_name,
201 queue => $or_testrun->testrun_scheduling->queue_id,
202 host => [
203 map {
204 0 [ $_->host_id, $_->host->name ]
205 } $or_testrun->testrun_requested_host
206 ],
207 preconditions => [
208 map {
209 0 {
210 0 ▶ text => $_->precondition->precondition,
Condition0%0/2
$_->precondition->shortname || ''
l!l
00
MC/DC0%0/1
$_->precondition->shortname || ''
$_->precondition->shortname
Truth table0%0/2
A
A= $_->precondition->shortname
Aresult
11
00
211 shortname => $_->precondition->shortname || q##,
212 }
213 } $or_testrun->testrun_precondition
214 ],
215 };
216  
217 0 my $trr = $or_testrun->testrun_requested_resource->first;
218  
219 0 ▶ if (defined($trr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trr) 0 0 0
220 0 ▶ my $res = $trr->alternatives->first->resource if defined $trr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trr 0 0 0
221 0 $or_c->stash->{continuous_testrun}->{resource} = $res->name;
222 }
223 }
224  
225 0 return 1;
226  
227 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
228  
229 0 ▶sub save : Local {
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
230  
231 0 my ( $or_self, $or_c ) = @_;
232  
233 0 my $or_schema = $or_c->model('TestrunDB');
234 0 my $ar_precondition_texts = toarrayref( $or_c->req->params->{precondition_text} );
235 0 my $ar_precondition_shorts = toarrayref( $or_c->req->params->{precondition_short} );
236  
237 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
238 0 ▶ $or_schema->txn_do(sub {
Subroutine __ANON__: not called CC=16 SCAR=56.1
239  
240 0 my $i_testrun_id;
241 my $hr_topic_search = {
242 'topic_name' => $or_c->req->params->{topic},
243 0 'testrun_scheduling.auto_rerun' => 1,
244 'testrun_scheduling.status' => ['prepare','schedule'],
245 };
246  
247 0 my $or_target_testrun;
248  
249 0 ▶ if ( $or_c->req->params->{command} eq 'edit' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($or_c->req->params->{'command'} eq 'edit') { } 0 0 0
elsif ($or_c->req->params->{'command'} eq 'clone') { } 0 0 0
250  
251 0 $i_testrun_id = $or_c->req->params->{testrun_id};
252 0 $hr_topic_search->{-not} = { 'me.id' => $i_testrun_id };
253  
254 # check topic name
255 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($or_schema->resultset("Testrun")->search($hr_topic_search, {"join", "testrun_scheduling"})->count > 0) 0 0 0
256 $or_schema
257 ->resultset('Testrun')
258 ->search($hr_topic_search,{
259 'join' => 'testrun_scheduling',
260 })
261 ->count() > 0
262 ) {
263 0 die "topic name already exists $i_testrun_id\n";
264 }
265  
266 0 $or_target_testrun = $or_schema
267 ->resultset('Testrun')
268 ->find($i_testrun_id);
269  
270 # update topic
271 0 ▶ if ( $or_target_testrun->topic_name ne $or_c->req->params->{topic} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_target_testrun->topic_name ne $or_c->req->params->{"topic"}) 0 0 0
272 0 $or_target_testrun->topic_name($or_c->req->params->{topic});
273 0 $or_target_testrun->update;
274 }
275  
276 # update queue
277 $or_schema
278 ->resultset('TestrunScheduling')
279 ->search({
280 -not => { queue_id => $or_c->req->params->{queue_id}, },
281 testrun_id => $i_testrun_id,
282 auto_rerun => 1,
283 status => ['prepare','schedule'],
284 })
285 ->update({
286 queue_id => $or_c->req->params->{queue}
287 })
288 0 ;
289  
290 # delete old preconditions
291 0 $or_schema
292 ->resultset('TestrunPrecondition')
293 ->search({ testrun_id => $i_testrun_id })
294 ->delete_all()
295 ;
296  
297 # delete old testruns
298 0 $or_schema
299 ->resultset('TestrunRequestedHost')
300 ->search({ testrun_id => $i_testrun_id })
301 ->delete_all()
302 ;
303  
304 0 my @resource_requests = $or_schema
305 ->resultset('TestrunRequestedResource')
306 ->search({ testrun_id => $i_testrun_id })
307 ->all();
308  
309 0 foreach my $req (@resource_requests) {
310 0 $req->alternatives->delete_all();
311 0 $req->delete();
312 }
313 }
314 elsif ( $or_c->req->params->{command} eq 'clone' ) {
315  
316 # check topic name
317 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($or_schema->resultset("Testrun")->search($hr_topic_search, {"join", "testrun_scheduling"})->count > 0) 0 0 0
318 $or_schema
319 ->resultset('Testrun')
320 ->search($hr_topic_search,{
321 'join' => 'testrun_scheduling',
322 })
323 ->count() > 0
324 ) {
325 0 die "topic name already exists\n";
326 }
327  
328 # add a new testrun entry
329 my $or_testrun = $or_schema
330 ->resultset('Testrun')
331 ->find( $or_c->req->params->{testrun_id} )
332 0 ;
333 my $or_new_testrun = $or_schema
334 ->resultset('Testrun')
335 ->new({
336 shortname => $or_testrun->shortname,
337 notes => $or_testrun->notes,
338 topic_name => $or_c->req->params->{topic},
339 0 owner_id => $or_testrun->owner_id,
340 testplan_id => $or_testrun->testplan_id,
341 wait_after_tests => $or_testrun->wait_after_tests,
342 rerun_on_error => $or_testrun->rerun_on_error,
343 })
344 ->insert()
345 ;
346 0 $or_target_testrun = $or_new_testrun;
347  
348 # add a new testrun scheduling entry
349 my $or_testrun_scheduling = $or_schema
350 ->resultset('TestrunScheduling')
351 ->search({
352 testrun_id => $or_c->req->params->{testrun_id},
353 0 auto_rerun => 1,
354 status => ['prepare','schedule'],
355 })
356 ->first()
357 ;
358  
359 0 $i_testrun_id = $or_new_testrun->id();
360  
361 $or_schema
362 ->resultset('TestrunScheduling')
363 ->new({
364 testrun_id => $i_testrun_id,
365 queue_id => $or_c->req->params->{queue},
366 0 prioqueue_seq => $or_testrun_scheduling->prioqueue_seq,
367 status => 'schedule',
368 auto_rerun => 1,
369 })
370 ->insert()
371 ;
372  
373 }
374 else {
375 0 die 'unknown command "' . $or_c->req->params->{command} . '"' . "\n";
376 }
377  
378 # insert testrun preconditions
379 0 $or_schema
380 ->resultset('TestrunPrecondition')
381 ->search({ testrun_id => $i_testrun_id })
382 ->delete_all()
383 ;
384  
385 0 my $i_counter = 0;
386 0 for my $s_text ( @{$ar_precondition_texts} ) {
387  
388 0 ▶ my $s_short = $ar_precondition_shorts->[$i_counter] || q##;
Condition0%0/2
$ar_precondition_shorts->[$i_counter] || ''
l!l
00
MC/DC0%0/1
$ar_precondition_shorts->[$i_counter] || ''
$ar_precondition_shorts->[$i_counter]
Truth table0%0/2
A
A= $ar_precondition_shorts->[$i_counter]
Aresult
11
00
389 0 ▶ my $or_precond =
Condition0%0/3
$or_schema->resultset('Precondition')->search({'shortname', $s_short, 'precondition', $s_text}, {'order_by', {'-asc', 'id'}})->first || $or_schema->resultset('Precondition')->new({'shortname', $s_short, 'precondition', $s_text})->insert
l!l&&r!l&&!r
000
MC/DC0%0/2
$or_schema->resultset('Precondition')->search({'shortname', $s_short, 'precondition', $s_text}, {'order_by', {'-asc', 'id'}})->first || $or_schema->resultset('Precondition')->new({'shortname', $s_short, 'precondition', $s_text})->insert
$or_schema->resultset('Precondition')->search({'shortname', $s_short, 'precondition', $s_text}, {'order_by', {'-asc', 'id'}})->first $or_schema->resultset('Precondition')->new({'shortname', $s_short, 'precondition', $s_text})->insert
Truth table0%0/3
A || B
A= $or_schema->resultset('Precondition')->search({'shortname', $s_short, 'precondition', $s_text}, {'order_by', {'-asc', 'id'}})->firstB= $or_schema->resultset('Precondition')->new({'shortname', $s_short, 'precondition', $s_text})->insert
ABresult
1X1
011
000
390 $or_schema
391 ->resultset('Precondition')
392 ->search({
393 shortname => $s_short,
394 precondition => $s_text,
395 },{
396 order_by => { -asc => 'id' },
397 })
398 ->first()
399 ||
400 $or_schema
401 ->resultset('Precondition')
402 ->new({
403 shortname => $s_short,
404 precondition => $s_text,
405 })
406 ->insert()
407 ;
408  
409 # insert testrun - precondition relation
410 0 $or_schema
411 ->resultset('TestrunPrecondition')
412 ->new({
413 testrun_id => $i_testrun_id,
414 precondition_id => $or_precond->id,
415 succession => $i_counter + 1,
416 })
417 ->insert()
418 ;
419  
420 0 $i_counter++;
421  
422 }
423  
424 # insert testrun requested hosts
425 0 for my $s_host ( @{toarrayref( $or_c->req->params->{host} )} ) {
426 0 my $or_host = $or_schema->resultset('Host')->search({ name => $s_host })->first;
427  
428 0 ▶ die "Host with name '$s_host' does not exist"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $or_host 0 0 0
429 unless defined $or_host;
430  
431 0 $or_schema
432 ->resultset('TestrunRequestedHost')
433 ->new({
434 host_id => $or_host->id,
435 testrun_id => $i_testrun_id,
436 })
437 ->insert()
438 ;
439 }
440  
441 # insert resource
442 0 my $resname = $or_c->req->params->{resource};
443 0 ▶ $resname =~ s/^\s+|\s+$//g if defined $resname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $resname 0 0 0
444 0 ▶ if (defined $resname && $resname ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resname and $resname ne "") 0 0 0
Condition0%0/3
defined $resname and $resname ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resname and $resname ne ""
defined $resname $resname ne ""
Truth table0%0/3
A and B
A= defined $resnameB= $resname ne ""
ABresult
0X0
100
111
445 0 ▶ if (!$or_target_testrun->add_requested_resource_by_name($or_c->req->params->{resource})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $or_target_testrun->add_requested_resource_by_name($or_c->req->params->{"resource"})) 0 0 0
446 0 die "Resource with name ".$or_c->req->params->{resource}." does not exist.";
447 }
448 }
449 0 });
450 }
451 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
452  
453 0 my $i_precondition_counter = 0;
454 0 $or_c->stash->{error} = "Transaction failed: $_";
455 0 $or_c->stash->{command} = $or_c->req->params->{command};
456 $or_c->stash->{continuous_testrun} = {
457 testrun_id => $or_c->req->params->{testrun_id},
458 topic => $or_c->req->params->{topic},
459 queue => $or_c->req->params->{queue},
460 host => [
461 map {[
462 0 $_, $or_schema->resultset('Host')->find( $_ )->name,
463 0 ]} @{toarrayref( $or_c->req->params->{host} )}
464 ],
465 preconditions => [
466 map {
467 {
468 0 text => $ar_precondition_texts->[$i_precondition_counter],
469 shortname => $ar_precondition_shorts->[$i_precondition_counter++],
470 };
471  
472 0 } @{$ar_precondition_texts}
473 ],
474 };
475 0 $or_c->go('/tapper/continuoustestruns/'.$or_c->req->params->{command});
476 0 };
477  
478 0 $or_c->response->redirect('/tapper/continuoustestruns');
479 0 $or_c->detach();
480  
481 0 return 1;
482  
483 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
484  
485 0 ▶sub toarrayref : Private {
Subroutine toarrayref: not called CC=2 SCAR=17.9
Pod undocumented
486  
487 0 my ( $value ) = @_;
488  
489 0 ▶ if ( ref( $value ) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne "ARRAY") 0 0 0
490 0 return [ $value ];
491 }
492  
493 0 return $value;
494  
495 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
496  
497 13 1;
498  
499 __END__
« blib/lib/Tapper/Reports/Web/Controller/Tapper/ReportFile/Id.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Rss.pm »