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

filter: Statementstmt 61.6% 306 / 496 Branchbran 39.0% 57 / 146 Conditioncond 5.5% 1 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 76.5% 49 / 64 Podpod 30.7% 8 / 26 totaltotal 55.3% 421 / 761 CC 98 SCAR 34.9
CC
98
Cov
55%
get_testrun_overview
154.8
prepare_testrunlists
132.0
prepare_navi
30.0
CRAP 32.8
« blib/lib/Tapper/Reports/Web/Controller/Tapper/Overview.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Tap.pm »
1 package Tapper::Reports::Web::Controller::Tapper::Testruns;
2 13 our $AUTHORITY = 'cpan:TAPPER';
3 13 $Tapper::Reports::Web::Controller::Tapper::Testruns::VERSION = '5.0.17';
4 13 ▶use parent 'Tapper::Reports::Web::Controller::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Data::DPath 'dpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use DateTime::Format::DateParse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use List::Util 'max';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use Tapper::Cmd::Testrun;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Tapper::Cmd::Precondition;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 13 ▶use Tapper::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 13 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 13 ▶use Tapper::Reports::Web::Util::Testrun;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use Tapper::Reports::Web::Util::Filter::Testrun;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ## no critic (RequireUseStrict)
23  
24  
25  
26  
27 0 ▶sub index :Path :Args()
Subroutine index: not called CC=2 SCAR=17.9
28 {
29 0 my ( $self, $c, @args ) = @_;
30  
31 0 my $filter = Tapper::Reports::Web::Util::Filter::Testrun->new(context => $c);
32 0 my $filter_condition = $filter->parse_filters(\@args);
33  
34 0 ▶ if ($filter_condition->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter_condition->{"error"}) 0 0 0
35 0 $c->flash->{error_msg} = join("; ", @{$filter_condition->{error}});
36 0 $c->res->redirect("/tapper/testruns");
37 }
38 0 $c->forward('/tapper/testruns/prepare_testrunlists', [ $filter_condition, $filter->requested_day ]);
39 0 $c->forward('/tapper/testruns/prepare_navi');
40 0 return;
41 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43  
44 0 ▶sub get_test_list_from_precondition {
Subroutine get_test_list_from_precondition: not called CC=1 SCAR=6.9
Pod documented
45 0 my ($precond) = @_;
46  
47 0 return grep { defined } (
48 $precond->{testprogram}{execname},
49 map {
50 0 join( " ", $_->{program}, @{$_->{parameters}} )
51 0 } @{$precond->{testprogram_list}},
52 );
53 }
54  
55  
56 1 ▶sub get_testrun_overview : Private
Subroutine get_testrun_overview: called CC=16 SCAR=50.4
Pod documented
57 {
58 1 my ( $self, $c, $testrun ) = @_;
59  
60 1 my $retval = {};
61  
62 1 ▶ return $retval unless $testrun;
Branch: 1 branch
BranchTrueFalseTotal
unless $testrun 0 1 1
63  
64 1 $retval->{shortname} = $testrun->shortname;
65  
66 1 foreach ($testrun->ordered_preconditions) {
67 2 my $precondition = $_->precondition_as_hash;
68 2 ▶ if ($precondition->{precondition_type} eq 'virt' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($precondition->{'precondition_type'} eq 'virt') { } 0 2 2
elsif ($precondition->{'precondition_type'} eq 'image') { } 0 2 2
elsif ($precondition->{'precondition_type'} eq 'prc') { } 0 2 2
69 0 ▶ $retval->{name} = $precondition->{name} || "Virtualisation Test";
Condition0%0/2
$precondition->{'name'} || 'Virtualisation Test'
l!l
00
MC/DC0%0/1
$precondition->{'name'} || 'Virtualisation Test'
$precondition->{'name'}
Truth table0%0/2
A
A= $precondition->{'name'}
Aresult
11
00
70 0 $retval->{arch} = $precondition->{host}->{root}{arch};
71 0 ▶ $retval->{image} = $precondition->{host}->{root}{image} || $precondition->{host}->{root}{name}; # can be an image or copyfile or package
Condition0%0/3
$precondition->{'host'}{'root'}{'image'} || $precondition->{'host'}{'root'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$precondition->{'host'}{'root'}{'image'} || $precondition->{'host'}{'root'}{'name'}
$precondition->{'host'}{'root'}{'image'} $precondition->{'host'}{'root'}{'name'}
Truth table0%0/3
A || B
A= $precondition->{'host'}{'root'}{'image'}B= $precondition->{'host'}{'root'}{'name'}
ABresult
1X1
011
000
72 0 ($retval->{xen_package}) = grep { m!repository/packages/xen/builds! } dpath('/host/preconditions//filename')->match($precondition);
73 0 push @{$retval->{test}}, get_test_list_from_precondition($precondition->{host});
74  
75 0 foreach my $guest (@{$precondition->{guests}}) {
76 0 my $guest_summary;
77 0 $guest_summary->{arch} = $guest->{root}{arch};
78 0 ▶ $guest_summary->{image} = $guest->{root}{image} || $guest->{root}{name}; # can be an image or copyfile or package
Condition0%0/3
$guest->{'root'}{'image'} || $guest->{'root'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$guest->{'root'}{'image'} || $guest->{'root'}{'name'}
$guest->{'root'}{'image'} $guest->{'root'}{'name'}
Truth table0%0/3
A || B
A= $guest->{'root'}{'image'}B= $guest->{'root'}{'name'}
ABresult
1X1
011
000
79 0 push @{$guest_summary->{test}}, get_test_list_from_precondition($guest);
80 0 push @{$retval->{guests}}, $guest_summary;
81 }
82 # can stop here because virt preconditions usually defines everything we need for a summary
83 0 return $retval;
84 }
85 elsif ($precondition->{precondition_type} eq 'image' ) {
86 0 $retval->{image} = $precondition->{image};
87 0 ▶ if ($retval->{arch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval->{'arch'}) { } 0 0 0
88 0 $retval->{arch} = $precondition->{arch};
89 } else {
90 0 ▶ if ($precondition->{image} =~ m/(64b)|(x86_64)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($precondition->{'image'} =~ /(64b)|(x86_64)/) { } 0 0 0
elsif ($precondition->{'image'} =~ /(32b)|(i386)/) { } 0 0 0
91 0 $retval->{arch} = 'unknown (probably linux64)';
92 } elsif ($precondition->{image} =~ m/(32b)|(i386)/) {
93 0 $retval->{arch} = 'unknown (probably linux32)';
94 } else {
95 0 $retval->{arch} = 'unknown';
96 }
97 }
98 } elsif ($precondition->{precondition_type} eq 'prc') {
99 0 ▶ if ($precondition->{config}->{testprogram_list}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($precondition->{'config'}{'testprogram_list'}) { } 0 0 0
elsif ($precondition->{'config'}{'test_program'}) { } 0 0 0
100 0 foreach my $thisprogram (@{$precondition->{config}->{testprogram_list}}) {
101 0 push @{$retval->{test}}, $thisprogram->{program};
102 }
103 } elsif ($precondition->{config}->{test_program}) {
104 0 push @{$retval->{test}}, $precondition->{config}->{test_program};
105 }
106 }
107 }
108 1 return $retval;
109 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 13 ▶sub base : Chained PathPrefix CaptureArgs(0) { }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine base: called CC=1 SCAR=0.0
Pod undocumented
112  
113 2 ▶sub id : Chained('base') PathPart('') CaptureArgs(1)
Subroutine id: called CC=2 SCAR=8.4
Pod undocumented
114 {
115 2 my ( $self, $c, $testrun_id ) = @_;
116 2 $c->stash(testrun => $c->model('TestrunDB')->resultset('Testrun')->find($testrun_id));
117 2 ▶ if (not $c->stash->{testrun}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $c->stash->{"testrun"}) 0 2 2
118 0 $c->response->body(qq(No testrun with id "$testrun_id" found in the database!));
119 0 return;
120 }
121  
122 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 0 ▶sub delete : Chained('id') PathPart('delete')
Subroutine delete: not called CC=3 SCAR=24.8
Pod undocumented
125 {
126 0 my ( $self, $c, $force) = @_;
127 0 $c->stash(force => $force);
128  
129 0 ▶ return if not $force;
Branch: 1 branch
BranchTrueFalseTotal
unless $force 0 0 0
130  
131 0 my $cmd = Tapper::Cmd::Testrun->new();
132 0 my $retval = $cmd->del($c->stash->{testrun}->id);
133 0 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 0 0 0
134 0 $c->response->body(qq(Can not delete testrun: $retval));
135 0 return;
136 }
137 0 $c->stash(force => 1);
138 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
139  
140 0 ▶sub pause : Chained('id') PathPart('pause')
Subroutine pause: not called CC=2 SCAR=17.9
Pod undocumented
141 {
142 0 my ( $self, $c) = @_;
143  
144 0 my $cmd = Tapper::Cmd::Testrun->new();
145 0 my $retval = $cmd->pause($c->stash->{testrun}->id);
146 0 ▶ if (not $retval) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval) 0 0 0
147 0 $c->response->body(qq(Can not pause testrun));
148 0 return;
149 }
150 0 $c->stash(testrun => $c->stash->{testrun}->id);
151 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
152  
153 0 ▶sub continue : Chained('id') PathPart('continue')
Subroutine continue: not called CC=2 SCAR=17.9
Pod undocumented
154 {
155 0 my ( $self, $c) = @_;
156  
157 0 my $cmd = Tapper::Cmd::Testrun->new();
158 0 my $retval = $cmd->continue($c->stash->{testrun}->id);
159 0 ▶ if (not $retval) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval) 0 0 0
160 0 $c->response->body(qq(Can not continue testrun));
161 0 return;
162 }
163 0 $c->stash(testrun => $c->stash->{testrun}->id);
164 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
165  
166 0 ▶sub rerun : Chained('id') PathPart('rerun') Args(0)
Subroutine rerun: not called CC=2 SCAR=17.9
Pod undocumented
167 {
168 0 my ( $self, $c ) = @_;
169  
170 0 my $cmd = Tapper::Cmd::Testrun->new();
171 0 my $retval = $cmd->rerun($c->stash->{testrun}->id);
172 0 ▶ if (not $retval) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval) 0 0 0
173 0 $c->response->body(qq(Can not rerun testrun));
174 0 return;
175 }
176 0 $c->stash(testrun => $retval);
177 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
178  
179 0 ▶sub cancel : Chained('id') PathPart('cancel') Args(0)
Subroutine cancel: not called CC=2 SCAR=17.9
Pod undocumented
180 {
181 0 my ( $self, $c ) = @_;
182  
183 0 my $cmd = Tapper::Cmd::Testrun->new();
184 0 my $retval = $cmd->cancel($c->stash->{testrun}->id, "Cancelled in Web GUI");
185 0 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 0 0 0
186 0 $c->response->body(qq(Can not cancel testrun: $retval));
187 0 return;
188 }
189 0 $c->stash(testrun => $c->stash->{testrun}->id);
190 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
191  
192 2 ▶sub preconditions : Chained('id') PathPart('preconditions') CaptureArgs(0)
Subroutine preconditions: called CC=1 SCAR=0.0
Pod undocumented
193 {
194 2 my ( $self, $c ) = @_;
195 2 $c->stash(preconditions => [$c->stash->{testrun}->ordered_preconditions]);
196 2 my @preconditions_as_hash = map { $_->precondition_as_hash } $c->stash->{testrun}->ordered_preconditions;
197 2 $YAML::Syck::SortKeys = 1;
198 2 $c->stash->{precondition_string} = YAML::Syck::Dump(@preconditions_as_hash);
199 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
200  
201 0 ▶sub as_yaml : Chained('preconditions') PathPart('yaml') Args(0)
Subroutine as_yaml: not called CC=3 SCAR=24.8
Pod undocumented
202 {
203 0 my ( $self, $c ) = @_;
204  
205 0 my $id = $c->stash->{testrun}->id;
206  
207 0 ▶ if (@{$c->stash->{preconditions} || []}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$c->stash->{'preconditions'} or [];}) { } 0 0 0
Condition0%0/2
$c->stash->{'preconditions'} || []
l!l
00
MC/DC0%0/1
$c->stash->{'preconditions'} || []
$c->stash->{'preconditions'}
Truth table0%0/2
A
A= $c->stash->{'preconditions'}
Aresult
11
00
208 0 $c->response->content_type ('text/plain');
209 0 $c->response->header ("Content-Disposition" => 'inline; filename="precondition-'.$id.'.yml"');
210 0 $c->response->body ( $c->stash->{precondition_string});
211 } else {
212 0 $c->response->body ("No preconditions assigned");
213 }
214 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
215  
216 sub validate_yaml
217 1 ▶{
Subroutine validate_yaml: called CC=1 SCAR=0.0
Pod undocumented
218 1 my ($data) = @_;
219 1 eval {
220 1 YAML::Syck::Load($data);
221 };
222 1 return $@;
223 }
224  
225 2 ▶sub edit : Chained('preconditions') PathPart('edit') Args(0) :FormConfig
Subroutine edit: called CC=6 SCAR=18.4
Pod undocumented
226 {
227 2 my ($self, $c) = @_;
228 2 my ($max_line, $line_count) = (0,0);
229  
230 2 my @lines = split "\n", $c->stash->{precondition_string};
231 2 foreach my $line (@lines) {
232 18 $max_line = max($max_line, length($line));
233 }
234  
235 2 my $form = $c->stash->{form};
236  
237 2 ▶ if ($form->submitted_and_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) { } 1 1 2
238 1 my $data = $form->input->{preconditions};
239  
240 # check whether user entered valid YAML
241 1 my $error = validate_yaml($data);
242 1 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 0 1 1
243 0 $c->stash(message => "<emp>Error</emp>: $error");
244 } else {
245 1 my @precondition_ids = eval {
246 1 my $precond_cmd = Tapper::Cmd::Precondition->new();
247 1 $precond_cmd->add($data);
248 };
249 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
250 0 $c->stash(message => "<emp>Error</emp>: $@");
251 0 return;
252 }
253  
254 1 $c->stash->{testrun}->disassign_preconditions();
255 1 my $retval = $c->stash->{testrun}->assign_preconditions(@precondition_ids);
256 1 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) { } 0 1 1
257 0 $c->stash(message => "<emp>Error</emp>: $retval");
258 } else {
259 1 $c->stash(message => "New precondition assigned to testrun");
260 }
261 }
262 } else {
263 1 my $text = $form->get_element({type => 'Textarea',
264 name => 'preconditions'});
265 1 $text->rows(int @lines);
266 1 $text->cols($max_line);
267 1 $text->default($c->stash->{precondition_string});
268 }
269 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
270  
271 0 ▶sub update_precondition : Chained('base') PathPart('update_precondition')
Subroutine update_precondition: not called CC=1 SCAR=6.9
Pod undocumented
272 {
273 0 my ($self, $c) = @_;
274 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
275  
276  
277 0 ▶sub show_precondition : Chained('preconditions') PathPart('show') Args(0)
Subroutine show_precondition: not called CC=1 SCAR=6.9
Pod undocumented
278 {
279 0 my ( $self, $c ) = @_;
280  
281 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
282  
283  
284 0 ▶sub similar : Chained('id') PathPart('similar') Args(0)
Subroutine similar: not called CC=1 SCAR=0.0
Pod undocumented
285 {
286 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
287  
288  
289 5 ▶sub new_create : Chained('base') :PathPart('create') :Args(0) :FormConfig
Subroutine new_create: called CC=9 SCAR=22.0
Pod documented
290 {
291 5 my ($self, $c) = @_;
292 5 my $form = $c->stash->{form};
293  
294 5 ▶ if ($form->submitted_and_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) { } 1 4 5
295 1 my $data = $form->input();
296 1 $c->session->{testrun_data} = $data;
297 1 $c->session->{valid} = 1;
298 1 $c->session->{usecase_file} = $form->input->{use_case};
299 1 $c->res->redirect('/tapper/testruns/fill_usecase');
300  
301 } else {
302 4 my $select;
303  
304 4 $select = $form->get_element({type => 'Select', name => 'owner'});
305 4 $select->options($self->get_owner_names());
306  
307 4 $select = $form->get_element({type => 'Select', name => 'requested_hosts'});
308 4 $select->options($self->get_hostnames());
309  
310 4 my @use_cases;
311 4 my $path = Tapper::Config->subconfig->{paths}{use_case_path};
312 4 ▶ foreach my $file (glob "$path/*.mpc") {
Subroutine BEGIN: called CC=1 SCAR=0.0
313 24 ▶ open my $fh, "<", $file or $c->response->body(qq(Can not open $file: $!)), return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or $c->response->body("Can not open ${file}: $!"), return 24 0 24
314 24 my $desc;
315 my $hide;
316 24 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 52 0 52
317 52 ($desc) = $line =~/^#+ *(?:tapper[_-])?description:\s*(.+)/;
318 52 ▶ last if $desc;
Branch: 1 branch
BranchTrueFalseTotal
if $desc 24 28 52
319 }
320 24 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 4908 24 4932
321 4908 ($hide) = $line =~/^#+ *(?:tapper[_-])?hide-in-webgui:\s*(.+)/;
322 4908 ▶ last if $hide;
Branch: 1 branch
BranchTrueFalseTotal
if $hide 0 4908 4908
323 }
324  
325 24 my ($shortfile, undef, undef) = File::Basename::fileparse($file, ('.mpc'));
326 24 ▶ push @use_cases, [$file, "$shortfile - $desc"] unless $hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 24 0 24
327  
328 }
329 4 my $select = $form->get_element({type => 'Radiogroup', name => 'use_case'});
330 4 $select->options(\@use_cases);
331 }
332  
333 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
334  
335 sub get_topic_names
336 0 ▶{
Subroutine get_topic_names: not called CC=2 SCAR=17.9
Pod undocumented
337 0 my ($self) = @_;
338 0 my @all_topics = model("TestrunDB")->resultset('Topic')->all();
339 0 my @topic_names;
340 0 foreach my $topic (sort {$a->name cmp $b->name} @all_topics) {
341 0 push(@topic_names, [$topic->name, $topic->name." -- ".$topic->description]);
342 }
343 0 return \@topic_names;
344 }
345  
346 sub get_owner_names
347 4 ▶{
Subroutine get_owner_names: called CC=3 SCAR=11.6
Pod undocumented
348 4 my ($self) = @_;
349 4 my @all_owners = model("TestrunDB")->resultset('Owner')->all();
350 4 my @owners;
351 0 foreach my $owner (sort {$a->name cmp $b->name} @all_owners) {
352 3 ▶ if ($owner->login eq 'tapper') {
Branch: 1 branch
BranchTrueFalseTotal
if ($owner->login eq 'tapper') { } 0 3 3
353 0 unshift(@owners, [$owner->login, $owner->name." (".$owner->login.")"]);
354 } else {
355 3 push(@owners, [$owner->login, $owner->name." (".$owner->login.")"]);
356 }
357 }
358 4 return \@owners;
359 }
360  
361  
362 sub get_hostnames
363 5 ▶{
Subroutine get_hostnames: called CC=4 SCAR=16.1
Pod documented
364 5 my ($self) = @_;
365 5 my @all_machines = model("TestrunDB")->resultset('Host')->search({active => 1});
366 5 my @machines;
367 HOST:
368 5 foreach my $host (sort {$a->name cmp $b->name} @all_machines) {
369  
370 # if host is bound, is must be bound to
371 # new_testrun_queue (possibly among others)
372 8 ▶ if ($host->queuehosts->count()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host->queuehosts->count) 0 8 8
373 0 my $new_testrun_queue = Tapper::Config->subconfig->{new_testrun_queue};
374 next HOST unless
375 0 ▶ grep {$_->queue->name eq $new_testrun_queue} $host->queuehosts->all;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->queue->name eq $new_testrun_queue;} $host->queuehosts->all 0 0 0
376 }
377  
378 8 push(@machines, [ $host->name, $host->name ]);
379 }
380 5 return \@machines;
381  
382 }
383  
384  
385 sub get_resources
386 0 ▶{
Subroutine get_resources: not called CC=1 SCAR=6.9
Pod documented
387 0 my ($self) = @_;
388 0 my @all_resources = model("TestrunDB")->resultset('Resource')->all;
389 0 return \@all_resources;
390 }
391  
392  
393  
394 2 ▶sub parse_macro_precondition :Private
Subroutine parse_macro_precondition: called CC=17 SCAR=31.4
Pod documented
395 {
396 2 my ($self, $c, $file) = @_;
397 2 my $config;
398 2 my $home = $c->path_to();
399 2 my ($shortfile, undef, undef) = File::Basename::fileparse($file, ('.mpc'));
400  
401 2 ▶ open my $fh, "<", $file or return "Can not open use case description $file:$!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return "Can not open use case description ${file}:$!" 2 0 2
402 2 my ($required, $optional, $mpc_config) = ('', '', '');
403  
404 2 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 214 2 216
405 214 ▶ $config->{description_text} .= "$1\n" if $line =~ /^### ?(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^### ?(.*)$/ 10 204 214
406  
407 214 ▶ ($required) = $line =~/^#+ *(?:tapper[_-])?mandatory[_-]fields?:\s*(.+)/ if not $required;
Branch: 1 branch
BranchTrueFalseTotal
unless $required 214 0 214
408 214 ▶ ($optional) = $line =~/^#+ *(?:tapper[_-])?optional[_-]fields?:\s*(.+)/ if not $optional;
Branch: 1 branch
BranchTrueFalseTotal
unless $optional 2 212 214
409 214 ▶ ($mpc_config) = $line =~/^#+ *(?:tapper[_-])?config[_-]file:\s*(.+)/ if not $mpc_config;
Branch: 1 branch
BranchTrueFalseTotal
unless $mpc_config 4 210 214
410 }
411  
412 2 my $delim = qr/,+\s*/;
413 2 foreach my $field (split $delim, $required) {
414 0 my ($name, $type) = split /\./, $field;
415 0 ▶ $type = 'Text' if not $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
416 0 push @{$config->{required}}, {type => ucfirst($type),
417 name => $name,
418 label => $name,
419 constraints => [ 'Required' ]
420 }
421 }
422  
423 2 foreach my $field (split $delim, $optional) {
424 4 my ($name, $type) = split /\./, $field;
425 4 ▶ $type = 'Text' if not $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 2 2 4
426 4 push @{$config->{optional}},{type => ucfirst($type),
427 name => $name,
428 label => $name,
429 };
430 }
431  
432 2 ▶ if ($mpc_config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mpc_config) 2 0 2
433 2 my $use_case_path = Tapper::Config->subconfig->{paths}{use_case_path};
434 2 ▶ $mpc_config = "$use_case_path/$mpc_config"
Branch: 1 branch
BranchTrueFalseTotal
unless substr($mpc_config, 0, 1) eq "/" 2 0 2
435 unless substr($mpc_config, 0, 1) eq '/';
436  
437 # configs with relative paths are searched in FormFu's
438 # config_file_path which is somewhere in root/forms. We
439 # want our own config_path which starts at cwd when
440 # being a relative path
441 2 ▶ $mpc_config = getcwd()."/$mpc_config" if $mpc_config !~ m'^/'o;
Branch: 1 branch
BranchTrueFalseTotal
unless $mpc_config =~ m[^/]o 2 0 2
442  
443 2 ▶ if (not -r $mpc_config) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $mpc_config) 0 2 2
444 0 $c->stash(error => qq(Config file "$mpc_config" does not exists or is not readable));
445 0 return;
446 }
447 2 $config->{mpc_config} = $mpc_config;
448 }
449  
450 # Default field "testrun_topic" in every form
451 0 ▶ if (not grep { $_->{name} eq "testrun_topic" } @{$config->{required}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"name"} eq "testrun_topic";} @{$$config{"required"};}) 2 0 2
452 2 ▶ unshift @{$config->{required}},
Condition33%1/3
$shortfile || ()
l!l&&r!l&&!r
200
MC/DC0%0/2
$shortfile || ()
$shortfile ()
Truth table33%1/3
A || B
A= $shortfileB= ()
ABresult
1X1
011
000
453 {
454 type => "Text",
455 name => "testrun_topic",
456 label => "Testrun topic",
457 value => join("-", "usertest", ($shortfile || ())),
458 constraints => [ { type => 'Required', message_xml => '<span style="color:#B40404">Please fill mandatory field</span>' } ],
459 attributes => { size => 50 },
460 }
461 }
462  
463 2 return $config;
464 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
465  
466  
467  
468 sub handle_precondition
469 2 ▶{
Subroutine handle_precondition: called CC=13 SCAR=31.3
Pod documented
470 2 my ($self, $c, $config) = @_;
471 2 my $form = $c->stash->{form};
472 2 my %macros;
473 2 my %all_form_elements = %{$c->request->{parameters}};
474  
475 2 foreach my $element (@{$config->{required}}, @{$config->{optional}}) {
476 6 my $name = $element->{name};
477 6 ▶ next if not defined $all_form_elements{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $all_form_elements{$name} 2 4 6
478  
479 4 ▶ if (lc($element->{type}) eq 'file') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $element->{"type"} eq "file") 0 4 4
480 0 my $upload = $c->req->upload($name);
481 my $destdir = sprintf("%s/uploads/%s/%s",
482 0 Tapper::Config->subconfig->{paths}{package_dir}, $config->{testrun_id}, $name);
483 0 my $destfile = $destdir."/".$upload->basename;
484 0 my $error;
485  
486 0 mkpath( $destdir, {error => \$error} );
487  
488 0 foreach my $diag (@$error) {
489 0 my ($dir, $message) = each %$diag;
490 0 return("Can not create $dir: $message");
491 }
492 0 $upload->copy_to($destfile);
493 0 $macros{$name} = $destfile;
494 0 delete $all_form_elements{$name};
495 }
496  
497 4 ▶ if (defined($all_form_elements{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $all_form_elements{$name}) { } 4 0 4
498 4 $macros{$name} = $all_form_elements{$name};
499 4 delete $all_form_elements{$name};
500 } else {
501 # TODO: handle error
502 }
503  
504 }
505  
506 2 foreach my $name (keys %all_form_elements) {
507 2 ▶ next if $name eq 'submit';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "submit" 2 0 2
508 # checkboxgroups return an array but since you don't
509 # know its order in advance its easier to access a hash
510 0 ▶ if (ref $all_form_elements{$name} =~ /ARRAY/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $all_form_elements{$name} =~ /ARRAY/) { } 0 0 0
511 0 foreach my $element (@{$all_form_elements{$name}}) {
512 0 $macros{$name}->{$element} = 1;
513 }
514 } else {
515 0 $macros{$name} = $all_form_elements{$name};
516 }
517 }
518  
519 2 ▶ open my $fh, "<", $config->{file} or return(qq(Can not open $config->{file}: $!));
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $config->{"file"} or return qq[Can not open $config->{"file"}: $!] 2 0 2
520 2 my $mpc = do {local $/; <$fh>};
521  
522 2 my $ttapplied;
523  
524 2 my $tt = new Template ();
525 2 ▶ return $tt->error if not $tt->process(\$mpc, \%macros, \$ttapplied);
Branch: 1 branch
BranchTrueFalseTotal
unless $tt->process(\$mpc, \%macros, \$ttapplied) 0 2 2
526  
527 2 my $cmd = Tapper::Cmd::Precondition->new();
528 2 my @preconditions;
529 2 eval { @preconditions = $cmd->add($ttapplied)};
530 2 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
531  
532 2 $cmd->assign_preconditions($config->{testrun_id}, @preconditions);
533 2 return \@preconditions;
534 }
535  
536  
537 2 ▶sub fill_usecase : Chained('base') :PathPart('fill_usecase') :Args(0) :FormConfig
Subroutine fill_usecase: called CC=12 SCAR=26.0
Pod documented
538 {
539 2 my ($self, $c) = @_;
540 2 my $form = $c->stash->{form};
541 2 my $position = $form->get_element({type => 'Submit'});
542 2 my $file = $c->session->{usecase_file};
543 2 my ($shortfile, undef, undef) = File::Basename::fileparse($file, ('.mpc'));
544 2 my %macros;
545 2 ▶ $c->res->redirect('/tapper/testruns/create') unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 2 2
546  
547 2 my $config = $self->parse_macro_precondition($c, $file);
548  
549 # adding these elements to the form has to be done both before
550 # and _after_ submit. Otherwise FormFu won't see the constraint
551 # (required) in the form
552 2 $c->stash->{description_text} = $config->{description_text};
553 2 foreach my $element (@{$config->{required}}) {
554 2 $element->{label} .= '*'; # mark field as required
555 2 $form->element($element);
556 }
557  
558 2 foreach my $element (@{$config->{optional}}) {
559 4 $element->{label} .= ' ';
560 4 $form->element($element);
561 }
562  
563 2 ▶ if ($config->{mpc_config}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"mpc_config"}) 2 0 2
564 2 $form->load_config_file( $config->{mpc_config} );
565 }
566  
567 2 $form->elements({type => 'Submit', name => 'submit', value => 'Submit'});
568 2 $form->process();
569  
570 2 ▶ if ($form->submitted_and_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form->submitted_and_valid) 1 1 2
571 1 my $testrun_data = $c->session->{testrun_data};
572 1 my @testhosts;
573  
574 # allow overwrite testrun topic
575 1 my $testrun_topic = $form->input->{testrun_topic};
576 1 ▶ if ($testrun_topic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testrun_topic) { } 1 0 1
577 1 $testrun_data->{topic} = $testrun_topic;
578 } else {
579 0 $testrun_data->{topic} = "undefined-topic";
580 }
581  
582 # hosts
583 1 ▶ if ( defined ($testrun_data->{requested_hosts})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $testrun_data->{'requested_hosts'}) { } 0 1 1
584 0 ▶ if ( ref($testrun_data->{requested_hosts}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $testrun_data->{'requested_hosts'} eq 'ARRAY') { } 0 0 0
585 0 @testhosts = @{$testrun_data->{requested_hosts}};
586 } else {
587 0 @testhosts = ( $testrun_data->{requested_hosts} );
588 }
589 } else {
590 1 @testhosts = map { $_->[0] } @{get_hostnames()};
591 }
592  
593 1 $c->stash->{all_testruns} = [];
594 HOST:
595 1 ▶ for( my $i=0; $i < @testhosts; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @testhosts) 2 1 3
596 2 my $host = $testhosts[$i];
597 # we need a copy since we modify the hash before
598 # giving it to Tapper::Cmd and this
599 # modification would be used when the user clicks reload
600 2 my %testrun_settings = %$testrun_data;
601 2 $testrun_settings{queue} = Tapper::Config->subconfig->{new_testrun_queue};
602  
603 2 $c->stash->{all_testruns}[$i]{host} = $host;
604  
605 2 $testrun_settings{requested_hosts} = $host;
606 2 my $cmd = Tapper::Cmd::Testrun->new();
607 2 eval { $config->{testrun_id} = $cmd->add(\%testrun_settings)};
608 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
609 0 $c->stash->{all_testruns}[$i]{error} = $@;
610 0 next HOST;
611 }
612 2 $c->stash->{all_testruns}[$i]{id} = $config->{testrun_id};
613  
614 2 $config->{file} = $file;
615 2 my $preconditions = $self->handle_precondition($c, $config);
616 2 ▶ if (ref($preconditions) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $preconditions eq 'ARRAY') { } 2 0 2
617 2 $c->stash->{all_testruns}[$i]{ preconditions } = $preconditions;
618 } else {
619 0 $c->stash->{all_testruns}[$i]{ error } = $preconditions;
620 }
621  
622 }
623 }
624 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
625  
626  
627 0 ▶sub prepare_testrunlists : Private {
Subroutine prepare_testrunlists: not called CC=11 SCAR=48.8
Pod undocumented
628  
629 0 my ( $or_self, $or_c, $hr_filter_condition ) = @_;
630  
631 0 my $b_view_pager = 0;
632 0 my $hr_params = $or_c->req->params;
633 my $hr_query_vals = {
634 testrun_id => $hr_filter_condition->{testrun_id},
635 host => $hr_filter_condition->{host},
636 topic => $hr_filter_condition->{topic},
637 state => $hr_filter_condition->{state},
638 success => $hr_filter_condition->{success},
639 owner => $hr_filter_condition->{owner},
640 resource => $hr_filter_condition->{resource},
641 0 };
642  
643 0 require DateTime;
644 0 ▶ if ( $hr_params->{testrun_date} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hr_params->{'testrun_date'}) { } 0 0 0
elsif (not $hr_filter_condition->{'testrun_id'}) { } 0 0 0
645 $hr_filter_condition->{testrun_date} = DateTime::Format::Strptime->new(
646 pattern => '%F',
647 0 )->parse_datetime( $hr_params->{testrun_date} );
648 }
649 elsif (! $hr_filter_condition->{testrun_id} ) {
650 0 $hr_filter_condition->{testrun_date} = DateTime->now();
651 }
652 0 ▶ if ( $hr_params->{pager_sign} && $hr_params->{pager_value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_params->{"pager_sign"} and $hr_params->{"pager_value"}) 0 0 0
Condition0%0/3
$hr_params->{"pager_sign"} and $hr_params->{"pager_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$hr_params->{"pager_sign"} and $hr_params->{"pager_value"}
$hr_params->{"pager_sign"} $hr_params->{"pager_value"}
Truth table0%0/3
A and B
A= $hr_params->{"pager_sign"}B= $hr_params->{"pager_value"}
ABresult
0X0
100
111
653 0 ▶ if ( $hr_params->{pager_sign} eq 'negative' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hr_params->{'pager_sign'} eq 'negative') { } 0 0 0
elsif ($hr_params->{'pager_sign'} eq 'positive') { } 0 0 0
654 $hr_filter_condition->{testrun_date}->subtract(
655 0 $hr_params->{pager_value} => 1
656 );
657 }
658 elsif ( $hr_params->{pager_sign} eq 'positive' ) {
659 $hr_filter_condition->{testrun_date}->add(
660 0 $hr_params->{pager_value} => 1
661 );
662 }
663 }
664  
665 0 ▶ if ( $hr_filter_condition->{testrun_date} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_filter_condition->{'testrun_date'}) { } 0 0 0
666  
667 0 ▶ $or_c->stash->{pager_interval} = $hr_params->{pager_interval} || 1;
Condition0%0/2
$hr_params->{'pager_interval'} || 1
l!l
00
MC/DC0%0/1
$hr_params->{'pager_interval'} || 1
$hr_params->{'pager_interval'}
Truth table0%0/2
A
A= $hr_params->{'pager_interval'}
Aresult
11
00
668 0 $or_c->stash->{testrun_date} = $hr_filter_condition->{testrun_date};
669  
670 # set testrun date
671 0 my $d_testrun_date_from = $hr_filter_condition->{testrun_date}->clone->subtract( days => $or_c->stash->{pager_interval} - 1 )->strftime('%d %b %Y');
672 0 my $d_testrun_date_to = $hr_filter_condition->{testrun_date}->strftime('%d %b %Y');
673  
674 0 ▶ if ( $d_testrun_date_from ne $d_testrun_date_to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d_testrun_date_from ne $d_testrun_date_to) { } 0 0 0
675 0 $or_c->stash->{head_overview} = "Testruns ($d_testrun_date_to - $d_testrun_date_from)";
676 }
677 else {
678 0 $or_c->stash->{head_overview} = "Testruns ($d_testrun_date_from)";
679 }
680  
681 0 $hr_query_vals->{testrun_date_from} = $hr_filter_condition->{testrun_date}->clone->subtract( days => $or_c->stash->{pager_interval} - 1 )->strftime('%F');
682 0 $hr_query_vals->{testrun_date_to} = $hr_filter_condition->{testrun_date}->strftime('%F');
683  
684 0 $or_c->stash->{view_pager} = 1;
685  
686 }
687 else {
688 0 $or_c->stash->{head_overview} = 'Testruns';
689 }
690  
691 0 my $ar_testruns = $or_c->model('TestrunDB')->fetch_raw_sql({
692 query_name => 'testruns::web_list',
693 fetch_type => '@%',
694 query_vals => $hr_query_vals,
695 });
696  
697 0 foreach my $testrun (@$ar_testruns) {
698 my @res_requests = $or_c->model('TestrunDB')->resultset('TestrunRequestedResource')
699 0 ->search({ testrun_id => $testrun->{testrun_id}, selected_resource_id => { '!=', undef } },{ prefetch => 'selected_resource' });
700 0 $testrun->{resources} = [ map { $_->selected_resource } @res_requests ];
701 }
702  
703 0 $or_c->stash->{testruns} = $ar_testruns;
704  
705 0 return 1;
706  
707 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
708  
709 0 ▶sub prepare_navi : Private
Subroutine prepare_navi: not called CC=5 SCAR=34.0
Pod undocumented
710 {
711 0 my ( $self, $c ) = @_;
712  
713 0 my @a_args = @{$c->req->arguments};
714  
715 $c->stash->{navi} = [
716 {
717 0 title => 'Control',
718 href => q##,
719 active => 0,
720 subnavi => [
721 {
722 title => 'Create new Testrun',
723 href => '/tapper/testruns/create/',
724 },
725 ],
726 },
727 ];
728  
729 0 my @a_subnavi;
730 0 ▶ OUTER: for ( my $i = 0; $i < @a_args; $i+=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a_args) 0 0 0
731 0 my $s_reduced_filter_path = q##;
732 0 ▶ for ( my $j = 0; $j < @a_args; $j+=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @a_args) 0 0 0
733 0 ▶ next if $i == $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $j 0 0 0
734 0 $s_reduced_filter_path .= "/$a_args[$j]/".$a_args[$j+1];
735 }
736 push @a_subnavi, {
737 title => "$a_args[$i]: ".$a_args[$i+1],
738 image => '/tapper/static/images/minus.png',
739 href => '/tapper/testruns'
740 . $s_reduced_filter_path
741 . (
742 $c->stash->{view_pager}
743 ? '?testrun_date='
744 . $c->stash->{testrun_date}->strftime('%F')
745 . '&amp;pager_interval='
746 . $c->stash->{pager_interval}
747 0 ▶ : ''
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'view_pager'} ? : 0 0 0
748 )
749 };
750 } # OUTER
751  
752 0 push @{$c->stash->{navi}},
753 { title => 'Active Filters', subnavi => \@a_subnavi, },
754 { title => 'New Filters', id => 'idx_new_filter' },
755 { title => 'Help', id => 'idx_help', subnavi => [{ title => 'Press Shift for multiple Filters' }] },
756 ;
757  
758 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
759  
760  
761 13 1;
762  
763 __END__
« blib/lib/Tapper/Reports/Web/Controller/Tapper/Overview.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Tap.pm »