blib/lib/Tapper/CLI/Host.pm

filter: Statementstmt 52.6% 237 / 450 Branchbran 39.3% 85 / 216 Conditioncond 27.1% 16 / 59 MC/DCmcdc 2.9% 1 / 34 Subroutinesub 75.0% 18 / 24 Podpod 85.0% 17 / 20 totaltotal 46.5% 374 / 803 CC 153 SCAR 40.5
CC
153
Cov
47%
b_free_host
156.0
i_add_queues
132.0
b_host_update
80.7
CRAP 57.3
« blib/lib/Tapper/CLI/API/Command/upload.pm ↑ Summary blib/lib/Tapper/CLI/API/Command/download.pm »
1 package Tapper::CLI::Host;
2 72 our $AUTHORITY = 'cpan:TAPPER';
3 72 $Tapper::CLI::Host::VERSION = '5.0.8';
4 72 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 72 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 sub host_feature_summary
12 2 ▶{
Subroutine host_feature_summary: called CC=1 SCAR=2.0
Pod undocumented
13 2 my ($host) = @_;
14  
15 return join(",",
16 0 map { $_->value }
17 0 sort { $a->entry cmp $b->entry }
18 0 grep { $_->entry =~ /^(key_word|socket_type|revision)$/ }
19 $host->features->all
20 );
21 }
22  
23  
24 0 ▶sub i_add_queues {
Subroutine i_add_queues: not called CC=11 SCAR=48.8
Pod documented
25  
26 0 my ( $or_host, $s_type, $ar_queues ) = @_;
27  
28 0 require Tapper::Model;
29  
30 0 my $i_success_counter = 0;
31 0 foreach my $s_queue ( @{$ar_queues} ) {
32 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $or_queue = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({'name', $s_queue}, {'prefetch', ['queuehosts', 'deniedhosts']})->first) { } 0 0 0
33 my $or_queue =
34 Tapper::Model::model('TestrunDB')
35 ->resultset('Queue')
36 ->search({
37 name => $s_queue,
38 },{
39 prefetch => [qw/ queuehosts deniedhosts /],
40 })
41 ->first
42 ) {
43 0 ▶ if ( $s_type eq 'bound' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s_type eq 'bound') { } 0 0 0
elsif ($s_type eq 'denied') { } 0 0 0
44 0 ▶ if ( grep { $_ == $or_host->id } $or_queue->deniedhosts->get_column('host_id')->all ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_ == $or_host->id;} $or_queue->deniedhosts->get_column('host_id')->all) { } 0 0 0
elsif (grep {$_ == $or_host->id;} $or_queue->queuehosts->get_column('host_id')->all) { } 0 0 0
45 0 die "error: you cannot add an bound-queue '$s_queue' for a already denied queue for host '" . $or_host->name . "'\n";
46 }
47 0 elsif ( grep { $_ == $or_host->id } $or_queue->queuehosts->get_column('host_id')->all ) {
48 0 die "error: queue '$s_queue' already bound to host '" . $or_host->name . "'\n";
49 }
50 else {
51 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (Tapper::Model::model('TestrunDB')->resultset('QueueHost')->new({'host_id', $or_host->id, 'queue_id', $or_queue->id})->insert) { } 0 0 0
52 Tapper::Model::model('TestrunDB')
53 ->resultset('QueueHost')
54 ->new({
55 host_id => $or_host->id,
56 queue_id => $or_queue->id,
57 })
58 ->insert()
59 ) {
60 0 $i_success_counter++;
61 }
62 else {
63 0 die "error: cannot add queue '$s_queue'\n";
64 }
65 }
66 }
67 elsif ( $s_type eq 'denied' ) {
68 0 ▶ if ( $or_queue->queuehosts->count ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($or_queue->queuehosts->count) { } 0 0 0
elsif ($or_queue->deniedhosts->count) { } 0 0 0
69 0 die "error: you cannot add an denied-queue '$s_queue' for a already bind queue for host '" . $or_host->name . "'\n";
70 }
71 elsif ( $or_queue->deniedhosts->count ) {
72 0 die "error: queue '$s_queue' already denied for host '" . $or_host->name . "'\n";
73 }
74 else {
75 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (Tapper::Model::model('TestrunDB')->resultset('DeniedHost')->new({'host_id', $or_host->id, 'queue_id', $or_queue->id})->insert) { } 0 0 0
76 Tapper::Model::model('TestrunDB')
77 ->resultset('DeniedHost')
78 ->new({
79 host_id => $or_host->id,
80 queue_id => $or_queue->id,
81 })
82 ->insert()
83 ) {
84 0 $i_success_counter++;
85 }
86 else {
87 0 die "error: cannot add queue '$s_queue'\n";
88 }
89 }
90 }
91 else {
92 0 warn "unknown type '$s_type' for sub i_delete_queues";
93 0 die "error: internal processing error\n";
94 }
95 }
96 else {
97 0 die "error: did not find queue '$s_queue'\n";
98 }
99 }
100  
101 0 return $i_success_counter;
102  
103 }
104  
105  
106 0 ▶sub i_delete_queues {
Subroutine i_delete_queues: not called CC=7 SCAR=40.3
Pod documented
107  
108 0 my ( $or_host, $s_type, $ar_queues ) = @_;
109  
110 0 my $s_relation_table;
111 0 ▶ if ( $s_type eq 'bound' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s_type eq 'bound') { } 0 0 0
elsif ($s_type eq 'denied') { } 0 0 0
112 0 $s_relation_table = 'QueueHost';
113 }
114 elsif ( $s_type eq 'denied' ) {
115 0 $s_relation_table = 'DeniedHost';
116 }
117 else {
118 0 die "error: unknown type '$s_type' for sub i_delete_queues\n";
119 }
120  
121 0 require Tapper::Model;
122  
123 0 my $i_success_counter = 0;
124 0 foreach my $s_queue ( @{$ar_queues} ) {
125 0 ▶ if ( $s_queue eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_queue eq '') { } 0 0 0
126 return
127 0 Tapper::Model::model('TestrunDB')
128 ->resultset( $s_relation_table )
129 ->search({host_id => $or_host->id})
130 ->delete_all
131 ;
132 }
133 else {
134 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $or_queue = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({'name', $s_queue}, {'rows', 1})->first) { } 0 0 0
135 my $or_queue =
136 Tapper::Model::model('TestrunDB')
137 ->resultset('Queue')
138 ->search({name => $s_queue}, {rows => 1})
139 ->first
140 ) {
141 0 my $or_queue_host =
142 Tapper::Model::model('TestrunDB')
143 ->resultset( $s_relation_table )
144 ->search({
145 host_id => $or_host->id,
146 queue_id => $or_queue->id
147 })
148 ;
149 0 ▶ if ( $or_queue_host->count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_queue_host->count) { } 0 0 0
150 0 $i_success_counter += $or_queue_host->delete_all;
151 }
152 else {
153 0 die "error: queue '$s_queue' isn't related with host '" . $or_host->name . "'\n";
154 }
155 }
156 else {
157 0 die "error: no such queue '$s_queue'\n";
158 }
159 }
160 }
161  
162 0 return $i_success_counter;
163  
164 }
165  
166  
167 2 ▶sub b_update_grub {
Subroutine b_update_grub: called CC=1 SCAR=0.0
Pod undocumented
168  
169 2 my ( $s_hostname ) = @_;
170  
171 2 require Tapper::Model;
172 return
173 2 Tapper::Model::model('TestrunDB')
174 ->resultset('Message')
175 ->new({
176 type => 'action',
177 message => {
178 action => 'updategrub',
179 host => $s_hostname,
180 },
181 })
182 ->insert
183 ;
184  
185 }
186  
187  
188 1 ▶sub hr_get_hosts_by_options {
Subroutine hr_get_hosts_by_options: called CC=3 SCAR=11.3
Pod documented
189  
190 1 my ( $hr_options ) = @_;
191  
192 1 require Tapper::Model;
193  
194 0 my %h_host_ids = map { $_ => q## } @{$hr_options->{id}};
195 1 foreach my $s_name ( @{$hr_options->{name}} ) {
196 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $or_host = Tapper::Model::model('TestrunDB')->resultset('Host')->find({'name', $s_name, 'is_deleted', 0})) { } 1 0 1
197 my $or_host =
198 Tapper::Model::model('TestrunDB')
199 ->resultset('Host')
200 ->find({
201 name => $s_name,
202 is_deleted => 0,
203 })
204 ) {
205 1 $h_host_ids{$or_host->id} = $or_host;
206 }
207 else {
208 0 die "error: Can't find host by name '$s_name'\n";
209 }
210 }
211  
212 1 return \%h_host_ids;
213  
214 }
215  
216  
217 0 ▶sub ar_get_free_host_parameters {
Subroutine ar_get_free_host_parameters: not called CC=1 SCAR=6.9
Pod documented
218 return [
219 0 'id|i=i@' , 'free particular hosts', 'Can be given multiple times.',
220 'name|n=s@' , 'free by host name', 'Can be given multiple times.',
221 'comment|c=s' , 'describe why the host is freed',
222 'verbose|v' , 'print all output, without only print ids',
223 'help|?' , 'Print this help message and exit.',
224 ];
225 }
226  
227  
228 0 ▶sub b_free_host {
Subroutine b_free_host: not called CC=12 SCAR=50.5
Pod documented
229  
230 0 my ( $or_app_rad ) = @_;
231  
232 0 my $ar_parameters = ar_get_free_host_parameters();
233 0 $or_app_rad->getopt( map { $_->[0] } @{$ar_parameters} );
234 0 my $hr_options = $or_app_rad->options;
235  
236 0 ▶ if ( $hr_options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"help"}) 0 0 0
237 0 say {*STDERR} "Usage: $PROGRAM_NAME host-free [options]";
238 0 require Tapper::CLI::Base;
239 0 Tapper::CLI::Base::b_print_help( $ar_parameters );
240 0 return;
241 }
242  
243 0 ▶ if ( !$hr_options->{id} && !$hr_options->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_options->{"id"} or $hr_options->{"name"}) 0 0 0
Condition0%0/3
$hr_options->{"id"} or $hr_options->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hr_options->{"id"} or $hr_options->{"name"}
$hr_options->{"id"} $hr_options->{"name"}
Truth table0%0/3
A or B
A= $hr_options->{"id"}B= $hr_options->{"name"}
ABresult
1X1
011
000
244 0 die "error: missing parameter 'id' or 'name'\n";
245 }
246  
247 0 my $hr_host_ids = hr_get_hosts_by_options( $hr_options );
248 0 my @a_sorted_hosts = sort { $hr_host_ids->{$a} cmp $hr_host_ids->{$b} } keys %{$hr_host_ids};
249  
250 0 foreach my $i_host_id ( @a_sorted_hosts ){
251  
252 0 my $or_host = $hr_host_ids->{$i_host_id};
253  
254 # host object isn't set by loop above. look for object by id.
255 0 ▶ if (! $or_host ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_host) 0 0 0
256 0 ▶ if (!
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_host = Tapper::Model::model("TestrunDB")->resultset("Host")->find($i_host_id)) 0 0 0
257 (
258 $or_host =
259 Tapper::Model::model('TestrunDB')
260 ->resultset('Host')
261 ->find( $i_host_id )
262 )
263 ) {
264 0 die "Can't find host by id '$i_host_id'\n";
265 }
266 }
267  
268 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my(@a_testrun_ids) = Tapper::Model::model('TestrunDB')->resultset('TestrunScheduling')->search({'host_id', $i_host_id, 'status', 'running'}, {'select', ['testrun_id']})->get_column('testrun_id')->all) { } 0 0 0
269 my @a_testrun_ids =
270 Tapper::Model::model('TestrunDB')
271 ->resultset('TestrunScheduling')
272 ->search({
273 host_id => $i_host_id,
274 status => 'running',
275 }, {
276 select => ['testrun_id'],
277 })
278 ->get_column('testrun_id')
279 ->all
280 ) {
281 0 my $hr_msg = { 'state' => 'quit', };
282 0 ▶ if ( $hr_options->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"comment"}) 0 0 0
283 0 $hr_msg->{error} = $hr_options->{comment};
284 }
285 0 for my $i_testrun_id ( @a_testrun_ids ) {
286 0 ▶ if (!
Branch: 1 branch
BranchTrueFalseTotal
unless (Tapper::Model::model("TestrunDB")->resultset("Message")->new({"testrun_id", $i_testrun_id, "message", $i_host_id})->insert) 0 0 0
287 Tapper::Model::model('TestrunDB')
288 ->resultset('Message')
289 ->new({
290 testrun_id => $i_testrun_id,
291 message => $i_host_id,
292 })
293 ->insert
294 ) {
295 0 die "freeing host failed: $i_host_id\n";
296 }
297 }
298 0 ▶ if ( $hr_options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"verbose"}) 0 0 0
299 0 say "info: freeing host successful: $i_host_id";
300 }
301 }
302 else {
303 0 say "info: host is already free: $i_host_id";
304 }
305  
306 }
307  
308 0 return;
309  
310 }
311  
312  
313 1 ▶sub ar_get_delete_parameters {
Subroutine ar_get_delete_parameters: called CC=1 SCAR=0.0
Pod documented
314 return [
315 1 [ 'id|i=i@' , 'delete particular hosts', 'Can be given multiple times.', ],
316 [ 'name|n=s@' , 'delete by host name', 'Can be given multiple times.', ],
317 [ 'force|f' , 'really execute the command', ],
318 [ 'verbose|v' , 'print all output, without only print ids', ],
319 [ 'help|?' , 'Print this help message and exit.', ],
320 ];
321 }
322  
323  
324 1 ▶sub b_delete {
Subroutine b_delete: called CC=11 SCAR=30.9
Pod documented
325  
326 1 my ( $or_app_rad ) = @_;
327  
328 1 require Tapper::Model;
329  
330 1 my $ar_parameters = ar_get_delete_parameters();
331 1 $or_app_rad->getopt( map { $_->[0] } @{$ar_parameters} );
332 1 my $hr_options = $or_app_rad->options;
333  
334 1 ▶ if ( $hr_options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"help"}) 0 1 1
335 0 say {*STDERR} "Usage: $PROGRAM_NAME host-delete [options]";
336 0 require Tapper::CLI::Base;
337 0 Tapper::CLI::Base::b_print_help( $ar_parameters );
338 0 return;
339 }
340  
341 1 ▶ if ( !$hr_options->{id} && !$hr_options->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_options->{"id"} or $hr_options->{"name"}) 0 1 1
Condition33%1/3
$hr_options->{"id"} or $hr_options->{"name"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$hr_options->{"id"} or $hr_options->{"name"}
$hr_options->{"id"} $hr_options->{"name"}
Truth table33%1/3
A or B
A= $hr_options->{"id"}B= $hr_options->{"name"}
ABresult
1X1
011
000
342 0 die "error: missing parameter 'id' or 'name'\n";
343 }
344  
345 1 my $hr_host_ids = hr_get_hosts_by_options( $hr_options );
346  
347 1 ▶ if (! $hr_options->{force} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_options->{"force"}) 0 1 1
348 0 say {*STDERR} "info: Skip actual host-delete unless --force is used.";
349 0 return;
350 }
351  
352 0 foreach my $i_host_id ( sort { $hr_host_ids->{$a} cmp $hr_host_ids->{$b} } keys %{$hr_host_ids} ){
353  
354 1 my $or_host = $hr_host_ids->{$i_host_id};
355  
356 # host object isn't set by loop above. look for object by id.
357 1 ▶ if (! $or_host ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_host) 0 1 1
358 0 ▶ if (!
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_host = Tapper::Model::model("TestrunDB")->resultset("Host")->find($i_host_id)) 0 0 0
359 (
360 $or_host =
361 Tapper::Model::model('TestrunDB')
362 ->resultset('Host')
363 ->find( $i_host_id )
364 )
365 ) {
366 0 die "Can't find host by id '$i_host_id'\n";
367 }
368 }
369  
370 1 my $s_name = $or_host->name;
371 1 ▶ if (! b_update_grub( $s_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (b_update_grub($s_name)) 0 1 1
372 0 die "error: Can't update grub by id '$i_host_id'\n";
373 }
374  
375 1 require DateTime;
376 1 $or_host->active( 0 );
377 1 $or_host->is_deleted( 1 );
378 1 $or_host->updated_at( DateTime->now->strftime('%F %T') );
379  
380 1 ▶ if ( $or_host->update() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_host->update) { } 1 0 1
381 1 ▶ if ( $hr_options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"verbose"}) 0 1 1
382 0 say "info: Deleted host $s_name: $i_host_id";
383 }
384 }
385 else {
386 0 die "error: Can't update host by id '$i_host_id'\n";
387 }
388  
389 }
390  
391 1 return;
392  
393 }
394  
395  
396 sub print_hosts_verbose
397 1 ▶{
Subroutine print_hosts_verbose: called CC=20 SCAR=34.1
Pod documented
398 1 my ($hosts, $verbosity_level) = @_;
399  
400 1 ▶ $verbosity_level //= 0;
Condition50%1/2
$verbosity_level //= 0
l!l
10
MC/DC0%0/1
$verbosity_level //= 0
$verbosity_level
Truth table50%1/2
A
A= $verbosity_level
Aresult
11
00
401  
402 # calculate width of columns
403 1 my %max = (
404 name => length('Name'),
405 features => length ('Features'),
406 comment => length('Comment'),
407 bindqueue => length('Bound Queues'),
408 denyqueue => length('Denied Queues'),
409 pool => length('Pool count (used/all)'),
410 );
411  
412 1 ▶ my @a_host = $hosts->isa('DBIx::Class::ResultSet') ? $hosts->all : $hosts;
Branch: 1 branch
BranchTrueFalseTotal
$hosts->isa('DBIx::Class::ResultSet') ? : 1 0 1
413  
414 HOST:
415 1 foreach my $host ( @a_host ) {
416 1 my $features = host_feature_summary($host);
417 1 ▶ $max{name} = length($host->name) if length($host->name) > $max{name};
Branch: 1 branch
BranchTrueFalseTotal
if length $host->name > $max{"name"} 1 0 1
418 1 ▶ $max{features} = length($features) if length($features) > $max{features};
Branch: 1 branch
BranchTrueFalseTotal
if length $features > $max{"features"} 0 1 1
419 1 ▶ $max{comment} = length($host->comment) if length($host->comment) > $max{comment};
Branch: 1 branch
BranchTrueFalseTotal
if length $host->comment > $max{"comment"} 0 1 1
420  
421 1 my $tmp_length = length(join ", ", map {$_->queue->name} $host->queuehosts->all);
422 1 ▶ $max{bindqueue} = $tmp_length if $tmp_length > $max{bindqueue} ;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp_length > $max{"bindqueue"} 0 1 1
423  
424 0 $tmp_length = length(join ", ", map {$_->queue->name} $host->denied_from_queue->all);
425 1 ▶ $max{denyqueue} = $tmp_length if $tmp_length > $max{bindqueue} ;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp_length > $max{"bindqueue"} 0 1 1
426 }
427  
428 my ($name_length, $feature_length, $comment_length, $bq_length, $dq_length, $pool_length) =
429 1 ($max{name}, $max{features}, $max{comment}, $max{bindqueue}, $max{denyqueue}, $max{pool});
430  
431 # use printf to get the wanted field width
432 1 ▶ if ($verbosity_level > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbosity_level > 1) { } 0 1 1
433 0 printf("%5s | %${name_length}s | %-${feature_length}s | %11s | %10s | %${comment_length}s | %-${bq_length}s | %-${dq_length}s | %-${pool_length}s\n",
434 'ID', 'Name', 'Features', 'Active', 'Testrun ID', 'Comment', 'Bound Queues', 'Denied Queues', 'Pool Count (used/all)');
435 } else {
436 1 printf("%5s | %${name_length}s | %-${feature_length}s | %11s | %10s | %${bq_length}s | %${dq_length}s | %-${pool_length}s\n",
437 'ID', 'Name', 'Features', 'Active', 'Testrun ID', 'Bound Queues', 'Denied Queues', 'Pool Count (used/all)');
438 1 $comment_length = 0;
439 }
440 1 say "="x(5+$name_length+$feature_length+11+length('Testrun ID')+$comment_length+$bq_length+$dq_length+$pool_length+7*length(' | '));
441  
442 1 require Tapper::Model;
443 1 foreach my $host ( @a_host ) {
444 1 my ($name_length, $feature_length, $queue_length) = ($max{name}, $max{features}, $max{queue});
445 1 my $testrun_id = 'unknown id';
446 1 ▶ if (not $host->free) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host->free) 1 0 1
447 1 my $job_rs = Tapper::Model::model('TestrunDB')->resultset('TestrunScheduling')->search({host_id => $host->id, status => 'running'});
448 1 ▶ $testrun_id = $job_rs->search({}, {rows => 1})->first->testrun_id if $job_rs->count;
Branch: 1 branch
BranchTrueFalseTotal
if $job_rs->count 1 0 1
449 }
450 1 my $features = host_feature_summary($host);
451 1 ▶ my $output = sprintf("%5d | %${name_length}s | %-${feature_length}s | %11s | %10s | ",
Branch: 3 branches
BranchTrueFalseTotal
$host->is_deleted ? : 0 1 1
$host->active ? : 0 1 1
$host->free ? : 0 1 1
452 $host->id,
453 $host->name,
454 $features,
455 $host->is_deleted ? 'deleted' : ( $host->active ? 'active' : 'deactivated' ),
456 $host->free ? 'free' : "$testrun_id",
457 );
458 1 ▶ if ($verbosity_level > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbosity_level > 1) 0 1 1
459 0 $output .= sprintf("%${comment_length}s | ", $host->comment);
460  
461 }
462 $output .= sprintf("%-${bq_length}s | %-${dq_length}s",
463 1 ▶ $host->queuehosts->count ? join(", ", map {$_->queue->name} $host->queuehosts->all) : '',
Branch: 1 branch
BranchTrueFalseTotal
$host->denied_from_queue->count ? : 0 1 1
464 0 ▶ $host->denied_from_queue->count ? join(", ", map {$_->queue->name} $host->denied_from_queue->all) : ''
Branch: 1 branch
BranchTrueFalseTotal
$host->queuehosts->count ? : 1 0 1
465 );
466 1 ▶ $output .= sprintf(" | %-${pool_length}s", $host->is_pool ? ($host->pool_count-$host->pool_free)."/".$host->pool_count : '-');
Branch: 1 branch
BranchTrueFalseTotal
$host->is_pool ? : 0 1 1
467 1 say $output;
468 }
469 }
470  
471  
472  
473  
474  
475 sub select_hosts
476 3 ▶{
Subroutine select_hosts: called CC=7 SCAR=19.6
Pod documented
477 3 my ($opt) = @_;
478 3 my %options= (order_by => 'name');
479 3 my %search;
480 3 ▶ $search{active} = 1 if $opt->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"active"} 0 3 3
481 3 ▶ $search{is_deleted} = [ 0, undef ] unless $opt->{all};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"all"} 3 0 3
482 3 ▶ $search{free} = 1 if $opt->{free};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"free"} 0 3 3
483 3 ▶ $search{pool_count} = { not => undef } if $opt->{pool};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"pool"} 0 3 3
484  
485 # ignore all options if host is requested by name
486 3 ▶ %search = (name => $opt->{name}) if $opt->{name};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"name"} 1 2 3
487  
488 3 require Tapper::Model;
489  
490 3 ▶ if ($opt->{queue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"queue"}) 2 1 3
491 2 my @queue_ids = map {$_->id} Tapper::Model::model('TestrunDB')->resultset('Queue')->search({name => {-in => [ @{$opt->{queue}} ]}});
492 2 $search{queue_id} = { -in => [ @queue_ids ]};
493 2 $options{join} = 'queuehosts';
494 2 $options{'+select'} = 'queuehosts.queue_id';
495 2 $options{'+as'} = 'queue_id';
496 }
497 3 my $hosts = Tapper::Model::model('TestrunDB')->resultset('Host')->search(\%search, \%options);
498 3 return $hosts;
499 }
500  
501  
502 sub print_hosts_yaml
503 0 ▶{
Subroutine print_hosts_yaml: not called CC=5 SCAR=34.0
Pod documented
504 0 my ($hosts) = @_;
505 0 ▶ while (my $host = $hosts->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $hosts->next) 0 0 0
506 0 my %host_data = (name => $host->name,
507 comment => $host->comment,
508 free => $host->free,
509 active => $host->active,
510 is_deleted => $host->is_deleted,
511 host_id => $host->id,
512 );
513 0 my $job = $host->testrunschedulings->search({status => 'running'}, {rows => 1})->first; # this should always be only one
514 0 ▶ if ($job) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job) 0 0 0
515 0 $host_data{running_testrun} = $job->testrun->id;
516 0 $host_data{running_since} = $job->testrun->starttime_testrun->iso8601;
517 }
518  
519 0 ▶ if ($host->queuehosts->count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host->queuehosts->count > 0) 0 0 0
520 0 my @queues = map {$_->queue->name} $host->queuehosts->all;
521 0 $host_data{queues} = \@queues;
522 }
523  
524 0 my %features;
525 0 foreach my $feature ($host->features->all) {
526 0 $features{$feature->entry} = $feature->value;
527 }
528 0 $host_data{features} = \%features;
529  
530 0 require YAML::XS;
531 0 print YAML::XS::Dump(\%host_data);
532 }
533 0 return;
534 }
535  
536  
537 sub print_hosts_json
538 0 ▶{
Subroutine print_hosts_json: not called CC=5 SCAR=34.0
Pod documented
539 0 my ($hosts) = @_;
540 0 my @info;
541 0 ▶ while (my $host = $hosts->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $hosts->next) 0 0 0
542 0 my %host_data = (name => $host->name,
543 comment => $host->comment,
544 free => $host->free,
545 active => $host->active,
546 is_deleted => $host->is_deleted,
547 host_id => $host->id,
548 );
549 0 my $job = $host->testrunschedulings->search({status => 'running'}, {rows => 1})->first; # this should always be only one
550 0 ▶ if ($job) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job) 0 0 0
551 0 $host_data{running_testrun} = $job->testrun->id;
552 0 $host_data{running_since} = $job->testrun->starttime_testrun->iso8601;
553 }
554  
555 0 ▶ if ($host->queuehosts->count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host->queuehosts->count > 0) 0 0 0
556 0 my @queues = map {$_->queue->name} $host->queuehosts->all;
557 0 $host_data{queues} = \@queues;
558 }
559  
560 0 my %features;
561 0 foreach my $feature ($host->features->all) {
562 0 $features{$feature->entry} = $feature->value;
563 }
564 0 $host_data{features} = \%features;
565  
566 0 push @info, \%host_data;
567 }
568  
569 0 require JSON::XS;
570 0 print JSON::XS->new->utf8->encode(\@info);
571 0 print "\n";
572 0 return;
573 }
574  
575  
576 sub listhost
577 3 ▶{
Subroutine listhost: called CC=6 SCAR=24.8
Pod documented
578 3 my ($c) = @_;
579 3 $c->getopt( 'free', 'name=s@', 'active', 'queue=s@', 'pool', 'all|a', 'verbose|v+', 'yaml', 'json', 'help|?' );
580 3 ▶ if ( $c->options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"help"}) 0 3 3
581 0 say STDERR "$0 host-list [ --verbose|v ] [ --free ] | [ --name=s ] [--pool] [ --active ] [ --queue=s@ ] [ --all|a] [ --yaml ] [ --json ]";
582 0 say STDERR " --verbose Increase verbosity level, without show only names, level one shows all but comments, level two shows all including comments";
583 0 say STDERR " --free List only free hosts";
584 0 say STDERR " --name Find host by name, implies verbose";
585 0 say STDERR " --active List only active hosts";
586 0 say STDERR " --queue List only hosts bound to this queue";
587 0 say STDERR " --pool List only pool hosts, even deleted ones";
588 0 say STDERR " --all List all hosts, even deleted ones";
589 0 say STDERR " --help Print this help message and exit";
590 0 say STDERR " --yaml Print information in YAML format, implies verbose";
591 0 say STDERR " --json Print information in JSON format, implies verbose, yaml takes precedence over json";
592 0 return;
593 }
594 3 my $hosts = select_hosts($c->options);
595  
596 3 ▶ if ($c->options->{yaml}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c->options->{'yaml'}) { } 0 3 3
elsif ($c->options->{'json'}) { } 0 3 3
elsif ($c->options->{'verbose'}) { } 1 2 3
597 0 print_hosts_yaml($hosts);
598 } elsif ($c->options->{json}) {
599 0 print_hosts_json($hosts);
600 } elsif ($c->options->{verbose}) {
601 1 print_hosts_verbose($hosts, $c->options->{verbose});
602 } else {
603 2 foreach my $host ($hosts->all) {
604 4 say sprintf("%10d | %s", $host->id, $host->name);
605 }
606 }
607  
608 3 return;
609 }
610  
611  
612 sub host_deny
613 2 ▶{
Subroutine host_deny: called CC=20 SCAR=42.5
Pod documented
614 2 my ($c) = @_;
615 2 $c->getopt( 'host=s@','queue=s@','really' ,'off','help|?' );
616 2 ▶ if ( $c->options->{help} or not (@{$c->options->{host} || []} and $c->options->{queue} )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}) 0 2 2
Condition37%3/8
$c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}
l!l&&r!l&&!r
002
@{$c->options->{'host'} or [];} && $c->options->{'queue'}
!ll&&!rl&&r
002
$c->options->{'host'} || []
l!l
20
MC/DC0%0/3
$c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}
$c->options->{"help"} @{$c->options->{'host'} or [];} $c->options->{'queue'}
MC/DC0%0/1
$c->options->{'host'} || []
$c->options->{'host'}
Truth table25%1/4
A or not(B && C)
A= $c->options->{"help"}B= @{$c->options->{'host'} or [];}C= $c->options->{'queue'}
ABCresult
1XX1
00X1
0101
0110
Truth table50%1/2
A
A= $c->options->{'host'}
Aresult
11
00
617 0 ▶ say STDERR "At least one queuename has to be provided!" unless @{$c->options->{queue} || []};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$c->options->{"queue"} or [];} 0 0 0
Condition0%0/2
$c->options->{'queue'} || []
l!l
00
MC/DC0%0/1
$c->options->{'queue'} || []
$c->options->{'queue'}
Truth table0%0/2
A
A= $c->options->{'queue'}
Aresult
11
00
618 0 ▶ say STDERR "At least one hostname has to be provided!" unless @{$c->options->{host} || []};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$c->options->{"host"} or [];} 0 0 0
Condition0%0/2
$c->options->{'host'} || []
l!l
00
MC/DC0%0/1
$c->options->{'host'} || []
$c->options->{'host'}
Truth table0%0/2
A
A= $c->options->{'host'}
Aresult
11
00
619 0 say STDERR "$0 host-deny --host=s@ --queue=s@ [--off] [--really]";
620 0 say STDERR " --host Deny this host for testruns of all given queues";
621 0 say STDERR " --queue Deny this queue to put testruns on all given hosts";
622 0 say STDERR " --off Remove previously installed denial of host/queue combination";
623 0 say STDERR " --really Force denial of host/queue combination even if it does not make sense (e.g. because host is also bound to queue)";
624 0 return;
625 }
626  
627 2 require Tapper::Model;
628  
629 2 my @queue_results; my @host_results;
630 2 foreach my $queue_name ( @{$c->options->{queue}}) {
631 2 my $queue_r = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({name => $queue_name}, {rows => 1})->first;
632 2 ▶ die "No such queue: '$queue_name'\n" unless $queue_r;
Branch: 1 branch
BranchTrueFalseTotal
unless $queue_r 0 2 2
633 2 push @queue_results, $queue_r;
634 }
635 2 foreach my $host_name ( @{$c->options->{host}}) {
636 2 my $host_r = Tapper::Model::model('TestrunDB')->resultset('Host')->search({name => $host_name}, {rows => 1})->first;
637 2 ▶ die "No such host: '$host_name'\n" unless $host_r;
Branch: 1 branch
BranchTrueFalseTotal
unless $host_r 0 2 2
638 2 push @host_results, $host_r;
639 }
640  
641 2 foreach my $queue_r (@queue_results) {
642 HOST:
643 2 foreach my $host_r (@host_results) {
644 2 ▶ if ($c->options->{off}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{'off'}) { } 1 1 2
645 1 my $deny_r = Tapper::Model::model('TestrunDB')->resultset('DeniedHost')->search({queue_id => $queue_r->id,
646 host_id => $host_r->id, },
647 {rows => 1}
648 )->first;
649 1 ▶ $deny_r->delete if $deny_r;
Branch: 1 branch
BranchTrueFalseTotal
if $deny_r 1 0 1
650 } else {
651  
652 1 ▶ if ($host_r->queuehosts->search({queue_id => $queue_r->id}, {rows => 1})->first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host_r->queuehosts->search({"queue_id", $queue_r->id}, {"rows", 1})->first) 0 1 1
653 0 my $msg = 'Host '.$host_r->name.' is bound to from queue '.$queue_r->name;
654 0 ▶ if ($c->options->{really}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{'really'}) { } 0 0 0
655 0 say STDERR "SUCCESS: $msg. Will still deny it too, because you requested it.";
656 } else {
657 0 say STDERR "ERROR: $msg. This does not make sense. Will not deny it from the queue. You can override it with --really";
658 0 next HOST;
659 }
660 }
661 # don't deny twice
662 1 ▶ next HOST if $host_r->denied_from_queue->search({queue_id => $queue_r->id}, {rows => 1})->first;
Branch: 1 branch
BranchTrueFalseTotal
if $host_r->denied_from_queue->search({"queue_id", $queue_r->id}, {"rows", 1})->first 0 1 1
663 1 Tapper::Model::model('TestrunDB')->resultset('DeniedHost')->new({queue_id => $queue_r->id,
664 host_id => $host_r->id,
665 })->insert;
666 }
667 }
668 }
669 2 return;
670 }
671  
672  
673 sub host_bind
674 2 ▶{
Subroutine host_bind: called CC=20 SCAR=42.5
Pod documented
675 2 my ($c) = @_;
676 2 $c->getopt( 'host=s@','queue=s@','really' ,'off','help|?' );
677 2 ▶ if ( $c->options->{help} or not (@{$c->options->{host} || []} and $c->options->{queue} )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}) 0 2 2
Condition37%3/8
$c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}
l!l&&r!l&&!r
002
@{$c->options->{'host'} or [];} && $c->options->{'queue'}
!ll&&!rl&&r
002
$c->options->{'host'} || []
l!l
20
MC/DC0%0/3
$c->options->{"help"} or not @{$c->options->{"host"} or [];} && $c->options->{"queue"}
$c->options->{"help"} @{$c->options->{'host'} or [];} $c->options->{'queue'}
MC/DC0%0/1
$c->options->{'host'} || []
$c->options->{'host'}
Truth table25%1/4
A or not(B && C)
A= $c->options->{"help"}B= @{$c->options->{'host'} or [];}C= $c->options->{'queue'}
ABCresult
1XX1
00X1
0101
0110
Truth table50%1/2
A
A= $c->options->{'host'}
Aresult
11
00
678 0 ▶ say STDERR "At least one queuename has to be provided!" unless @{$c->options->{queue} || []};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$c->options->{"queue"} or [];} 0 0 0
Condition0%0/2
$c->options->{'queue'} || []
l!l
00
MC/DC0%0/1
$c->options->{'queue'} || []
$c->options->{'queue'}
Truth table0%0/2
A
A= $c->options->{'queue'}
Aresult
11
00
679 0 ▶ say STDERR "At least one hostname has to be provided!" unless @{$c->options->{host} || []};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$c->options->{"host"} or [];} 0 0 0
Condition0%0/2
$c->options->{'host'} || []
l!l
00
MC/DC0%0/1
$c->options->{'host'} || []
$c->options->{'host'}
Truth table0%0/2
A
A= $c->options->{'host'}
Aresult
11
00
680 0 say STDERR "$0 host-bind --host=s@ --queue=s@ [--off] [--really]";
681 0 say STDERR " --host Bind this hosts to all given queues (can be given multiple times)";
682 0 say STDERR " --queue Bind all given hosts to this queue (can be given multiple times)";
683 0 say STDERR " --off Remove previously installed host/queue bindings";
684 0 say STDERR " --really Force binding host/queue combination even if it does not make sense (e.g. because host is also denied from queue)";
685 0 return;
686 }
687  
688 2 require Tapper::Model;
689  
690 2 my @queue_results; my @host_results;
691 2 foreach my $queue_name ( @{$c->options->{queue}}) {
692 2 my $queue_r = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({name => $queue_name}, {rows => 1})->first;
693 2 ▶ die "No such queue: '$queue_name'\n" unless $queue_r;
Branch: 1 branch
BranchTrueFalseTotal
unless $queue_r 0 2 2
694 2 push @queue_results, $queue_r;
695 }
696 2 foreach my $host_name ( @{$c->options->{host}}) {
697 2 my $host_r = Tapper::Model::model('TestrunDB')->resultset('Host')->search({name => $host_name}, {rows => 1})->first;
698 2 ▶ die "No such host: '$host_name'\n" unless $host_r;
Branch: 1 branch
BranchTrueFalseTotal
unless $host_r 0 2 2
699 2 push @host_results, $host_r;
700 }
701  
702 2 foreach my $queue_r (@queue_results) {
703 2 foreach my $host_r (@host_results) {
704 2 ▶ if ($c->options->{off}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{'off'}) { } 1 1 2
705 1 my $bind_r = Tapper::Model::model('TestrunDB')->resultset('QueueHost')->search({queue_id => $queue_r->id,
706 host_id => $host_r->id },
707 {rows => 1}
708 )->first;
709 1 ▶ $bind_r->delete if $bind_r;
Branch: 1 branch
BranchTrueFalseTotal
if $bind_r 1 0 1
710 } else {
711 1 ▶ if ($host_r->denied_from_queue->single({queue_id => $queue_r->id})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host_r->denied_from_queue->single({"queue_id", $queue_r->id})) 0 1 1
712 0 my $msg = 'Host '.$host_r->name.' is denied from from queue '.$queue_r->name;
713 0 ▶ if ($c->options->{really}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{'really'}) { } 0 0 0
714 0 say STDERR "SUCCESS: $msg. Will still deny it too, because you requested it.";
715 } else {
716 0 say STDERR "ERROR: $msg. This does not make sense. Will not bind it to the queue. You can override it with --really";
717 0 next HOST;
718 }
719 }
720 # don't bind twice
721 1 ▶ next HOST if $host_r->queuehosts->search({queue_id => $queue_r->id}, {rows => 1})->first;
Branch: 1 branch
BranchTrueFalseTotal
if $host_r->queuehosts->search({"queue_id", $queue_r->id}, {"rows", 1})->first 0 1 1
722 1 Tapper::Model::model('TestrunDB')->resultset('QueueHost')->new({queue_id => $queue_r->id,
723 host_id => $host_r->id,
724 })->insert;
725 }
726 }
727 }
728 2 return;
729 }
730  
731  
732  
733 sub host_new
734 7 ▶{
Subroutine host_new: called CC=12 SCAR=26.8
Pod documented
735 7 my ($c) = @_;
736 7 $c->getopt( 'name=s', 'queue=s@', 'active', 'pool_count=s', 'verbose|v', 'help|?' );
737 7 ▶ if ( $c->options->{help} or not $c->options->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"help"} or not $c->options->{"name"}) 0 7 7
Condition33%1/3
$c->options->{"help"} or not $c->options->{"name"}
l!l&&r!l&&!r
007
MC/DC0%0/2
$c->options->{"help"} or not $c->options->{"name"}
$c->options->{"help"} not $c->options->{"name"}
Truth table33%1/3
A or not(B)
A= $c->options->{"help"}B= not $c->options->{"name"}
ABresult
1X1
011
000
738 0 ▶ say STDERR "Host name missing!" unless $c->options->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->options->{"name"} 0 0 0
739 0 say STDERR "$0 host-new --name=s [ --queue=s@ ] [--pool_count=s] [--verbose|-v] [--help|-?]";
740 0 say STDERR " --name Name of the new host)";
741 0 say STDERR " --queue Bind host to this queue, can be given multiple times)";
742 0 say STDERR " --active Make host active; without it host will be initially deactivated)";
743 0 say STDERR " --verbose More verbose output)";
744 0 return;
745 }
746  
747 7 require Tapper::Model;
748  
749 7 ▶ if ($c->options->{queue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"queue"}) 4 3 7
750 4 foreach my $queue (@{$c->options->{queue}}) {
751 6 my $queue_rs = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({name => $queue});
752 6 ▶ if (not $queue_rs->count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($queue_rs->count) 1 5 6
753 1 say STDERR "No such queue: $queue";
754 1 my @queue_names = map {$_->name} Tapper::Model::model('TestrunDB')->resultset('Queue')->all;
755 1 say STDERR "Existing queues: ",join ", ",@queue_names;
756 }
757 }
758 }
759 my $host = {
760 name => $c->options->{name},
761 active => $c->options->{active},
762 free => 1,
763 pool_free => $c->options->{pool_count} ? $c->options->{pool_count} : undef, # need to turn 0 into undef, because 0 makes $host->is_pool true
764 7 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$c->options->{'pool_count'} ? : 0 7 7
765  
766 7 my $newhost = Tapper::Model::model('TestrunDB')->resultset('Host')->new($host);
767 7 $newhost->insert();
768 7 ▶ die "Can't create new host\n" if not $newhost; # actually, on this place DBIC should have died already
Branch: 1 branch
BranchTrueFalseTotal
unless $newhost 0 7 7
769  
770 7 ▶ if ($c->options->{queue}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->options->{"queue"}) 4 3 7
771 4 foreach my $queue (@{$c->options->{queue}}) {
772 6 my $queue_rs = Tapper::Model::model('TestrunDB')->resultset('Queue')->search({name => $queue});
773 6 ▶ if (not $queue_rs->count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($queue_rs->count) 1 5 6
774 1 $newhost->delete();
775 1 say STDERR qq(Did not find queue "$queue");
776 }
777 6 my $queue_host = Tapper::Model::model('TestrunDB')->resultset('QueueHost')->new({
778 host_id => $newhost->id,
779 queue_id => $queue_rs->search({}, {rows => 1})->first->id,
780 });
781 5 $queue_host->insert();
782 }
783 }
784 6 return $newhost->id;
785 }
786  
787  
788 5 ▶sub ar_get_host_update_parameters {
Subroutine ar_get_host_update_parameters: called CC=1 SCAR=0.0
Pod undocumented
789 return [
790 5 [ 'id|i=i' , 'change host with this id; this or selectbyname is required', ],
791 [ 'selectbyname=s' , 'change host with this name; this or id is required', ],
792 [ 'name|n=s' , 'update name', ],
793 [ 'comment|c:s' , 'Set a new comment for the host', ],
794 [ 'addboundqueue=s@' , 'Bind host to named queue without deleting other bindings (queue has to exists already)', ],
795 [ 'delboundqueue:s@' , q#delete queue from this host's bindings, empty string means 'all bindings'#, ],
796 [ 'adddeniedqueue=s@' , 'mark host as denied for a specific queue', ],
797 [ 'deldeniedqueue:s@' , 'remove denied queue for host', ],
798 [ 'active|a=i' , 'set active flag to this value, possible values 0 (inactive) and 1 (active)', ],
799 [ 'free=i' , 'set free flag; possible values: 0=not-free, 1=free; setting free=1 fails when a testrun runs there', ],
800 [ 'verbose|v' , 'some more informational output', ],
801 [ 'help|?' , 'Print this help message and exit.', ],
802 ];
803 }
804  
805  
806 5 ▶sub b_host_update {
Subroutine b_host_update: called CC=26 SCAR=43.9
Pod documented
807  
808 5 my ( $or_app_rad ) = @_;
809  
810 5 my $ar_parameters = ar_get_host_update_parameters();
811 5 $or_app_rad->getopt( map { $_->[0] } @{$ar_parameters} );
812 5 my $hr_options = $or_app_rad->options;
813  
814 5 ▶ if ( $hr_options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"help"}) 0 5 5
815 0 say {*STDERR} "Usage: $PROGRAM_NAME host-update [options]";
816 0 require Tapper::CLI::Base;
817 0 Tapper::CLI::Base::b_print_help( $ar_parameters );
818 0 return;
819 }
820  
821 5 ▶ if ( defined $hr_options->{active} && !grep { $hr_options->{active} == $_ } 0,1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hr_options->{"active"} and not grep({$hr_options->{"active"} == $_;} 0, 1)) 0 5 5
Condition66%2/3
defined $hr_options->{"active"} and not grep({$hr_options->{"active"} == $_;} 0, 1)
!ll&&!rl&&r
230
MC/DC0%0/2
defined $hr_options->{"active"} and not grep({$hr_options->{"active"} == $_;} 0, 1)
defined $hr_options->{"active"} not grep({$hr_options->{"active"} == $_;} 0, 1)
Truth table66%2/3
A and not(B)
A= defined $hr_options->{"active"}B= not grep({$hr_options->{"active"} == $_;} 0, 1)
ABresult
0X0
100
111
822 0 die "error: parameter '$hr_options->{active}' is not valid for 'active'\n";
823 }
824  
825 5 my $or_host;
826  
827 5 require Tapper::Model;
828 5 ▶ if ( $hr_options->{id} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hr_options->{'id'}) { } 3 2 5
elsif ($hr_options->{'selectbyname'}) { } 0 2 2
829 3 $or_host = Tapper::Model::model('TestrunDB')->resultset('Host')->find( $hr_options->{id} );
830 } elsif ( $hr_options->{selectbyname} ) {
831 # There should be only one host with the name
832 0 $or_host = Tapper::Model::model('TestrunDB')->resultset('Host')->search({ name => $hr_options->{selectbyname} })->first;
833 } else {
834 2 die "error: missing required parameter 'id' or 'selectbyname'\n";
835 }
836  
837 3 ▶ if ( $or_host ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_host) { } 3 0 3
838  
839 3 my $b_update = 0;
840 3 ▶ if ( defined $hr_options->{active} && $hr_options->{active} != $or_host->active ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hr_options->{"active"} and $hr_options->{"active"} != $or_host->active) 2 1 3
Condition66%2/3
defined $hr_options->{"active"} and $hr_options->{"active"} != $or_host->active
!ll&&!rl&&r
012
MC/DC50%1/2
defined $hr_options->{"active"} and $hr_options->{"active"} != $or_host->active
defined $hr_options->{"active"} $hr_options->{"active"} != $or_host->active
Truth table66%2/3
A and B
A= defined $hr_options->{"active"}B= $hr_options->{"active"} != $or_host->active
ABresult
0X0
100
111
841 2 $b_update = 1;
842 2 $or_host->active( $hr_options->{active} );
843 2 ▶ if ( $hr_options->{active} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"active"} == 0) 1 1 2
844 1 b_update_grub( $or_host->name );
845 }
846 }
847  
848 3 ▶ if ( $hr_options->{name} && $hr_options->{name} ne $or_host->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"name"} and $hr_options->{"name"} ne $or_host->name) 0 3 3
Condition33%1/3
$hr_options->{"name"} and $hr_options->{"name"} ne $or_host->name
!ll&&!rl&&r
300
MC/DC0%0/2
$hr_options->{"name"} and $hr_options->{"name"} ne $or_host->name
$hr_options->{"name"} $hr_options->{"name"} ne $or_host->name
Truth table33%1/3
A and B
A= $hr_options->{"name"}B= $hr_options->{"name"} ne $or_host->name
ABresult
0X0
100
111
849 0 $b_update = 1;
850 0 $or_host->name( $hr_options->{name} );
851 }
852 3 ▶ if ( defined $hr_options->{comment} && $hr_options->{comment} ne $or_host->comment ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hr_options->{"comment"} and $hr_options->{"comment"} ne $or_host->comment) 0 3 3
Condition33%1/3
defined $hr_options->{"comment"} and $hr_options->{"comment"} ne $or_host->comment
!ll&&!rl&&r
300
MC/DC0%0/2
defined $hr_options->{"comment"} and $hr_options->{"comment"} ne $or_host->comment
defined $hr_options->{"comment"} $hr_options->{"comment"} ne $or_host->comment
Truth table33%1/3
A and B
A= defined $hr_options->{"comment"}B= $hr_options->{"comment"} ne $or_host->comment
ABresult
0X0
100
111
853 0 $b_update = 1;
854 0 $or_host->comment( $hr_options->{comment} );
855 }
856 3 ▶ if ( defined $hr_options->{free} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hr_options->{"free"}) 0 3 3
857 0 $b_update = 1;
858 0 ▶ if ($hr_options->{free} == 1 and
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{'free'} == 1 and not $or_host->free and Tapper::Model::model('TestrunDB')->resultset('TestrunScheduling')->search({'host_id', $or_host->id, 'status', 'running'})->count) { } 0 0 0
Condition0%0/6
$hr_options->{"free"} == 1 and not $or_host->free and Tapper::Model::model("TestrunDB")->resultset("TestrunScheduling")->search({"host_id", $or_host->id, "status", "running"})->count
!ll&&!rl&&r
000
$hr_options->{"free"} == 1 and not $or_host->free
!ll&&!rl&&r
000
MC/DC0%0/3
$hr_options->{"free"} == 1 and not $or_host->free and Tapper::Model::model("TestrunDB")->resultset("TestrunScheduling")->search({"host_id", $or_host->id, "status", "running"})->count
$hr_options->{"free"} == 1 not $or_host->free Tapper::Model::model("TestrunDB")->resultset("TestrunScheduling")->search({"host_id", $or_host->id, "status", "running"})->count
Truth table0%0/4
A and not(B) and C
A= $hr_options->{"free"} == 1B= not $or_host->freeC= Tapper::Model::model("TestrunDB")->resultset("TestrunScheduling")->search({"host_id", $or_host->id, "status", "running"})->count
ABCresult
0XX0
10X0
1100
1111
859 not $or_host->free and
860 Tapper::Model::model('TestrunDB')->resultset('TestrunScheduling')->search({host_id => $or_host->id, status => 'running'})->count)
861 {
862 0 die "error: cannot free a used host (id=".$or_host->id.")\n";
863 }
864 else {
865 0 $or_host->free( $hr_options->{free} );
866 }
867 }
868 3 for my $s_type (qw/ bound denied /) {
869 6 ▶ if ( $hr_options->{"add${s_type}queue"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$hr_options{"add${s_type}queue"}) 0 6 6
870 0 ▶ $b_update ||= i_add_queues( $or_host, $s_type, $hr_options->{"add${s_type}queue"} );
Condition0%0/3
$b_update ||= i_add_queues($or_host, $s_type, $$hr_options{"add${s_type}queue"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$b_update ||= i_add_queues($or_host, $s_type, $$hr_options{"add${s_type}queue"})
$b_update i_add_queues($or_host, $s_type, $$hr_options{"add${s_type}queue"})
Truth table0%0/3
A ||= B
A= $b_updateB= i_add_queues($or_host, $s_type, $$hr_options{"add${s_type}queue"})
ABresult
1X1
011
000
871 }
872 6 ▶ if ( defined $hr_options->{"del${s_type}queue"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$hr_options{"del${s_type}queue"}) 1 5 6
873 1 ▶ $b_update ||= i_delete_queues( $or_host, $s_type, $hr_options->{"del${s_type}queue"} );
Condition33%1/3
$b_update ||= i_delete_queues($or_host, $s_type, $$hr_options{"del${s_type}queue"})
l!l&&r!l&&!r
100
MC/DC0%0/2
$b_update ||= i_delete_queues($or_host, $s_type, $$hr_options{"del${s_type}queue"})
$b_update i_delete_queues($or_host, $s_type, $$hr_options{"del${s_type}queue"})
Truth table33%1/3
A ||= B
A= $b_updateB= i_delete_queues($or_host, $s_type, $$hr_options{"del${s_type}queue"})
ABresult
1X1
011
000
874 }
875 }
876  
877 3 ▶ if ( $b_update ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_update) { } 2 1 3
878  
879 2 require DateTime;
880 2 $or_host->updated_at( DateTime->now->strftime('%F %T') );
881  
882 2 ▶ if (! $or_host->update ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($or_host->update) 0 2 2
883 0 die "error: cannot update host\n";
884 }
885  
886 }
887 else {
888 1 say {*STDERR} "info: nothing to update";
889 }
890 3 ▶ if ( $hr_options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"verbose"}) 0 3 3
891 0 print_hosts_verbose( $or_host );
892 }
893  
894 }
895 else {
896 0 die "error: no such host = $hr_options->{id}\n";
897 }
898  
899 3 return;
900  
901 }
902  
903  
904 sub setup
905 71 ▶{
Subroutine setup: called CC=2 SCAR=7.0
Pod documented
906 71 my ($c) = @_;
907  
908 71 $c->register('host-list' , \&listhost , 'Show all hosts matching a given condition');
909 71 $c->register('host-deny' , \&host_deny , 'Setup or remove forbidden host/queue combinations');
910 71 $c->register('host-bind' , \&host_bind , 'Setup or remove host/queue bindings');
911 71 $c->register('host-new' , \&host_new , 'Create a new host by name');
912 71 $c->register('host-update' , \&b_host_update , 'update host data');
913 71 $c->register('host-delete' , \&b_delete , 'Delete a host');
914  
915 #TODO: full implementation remaining
916 # $c->register('host-free' , \&b_free_host , 'Free host');
917  
918 71 ▶ if ($c->can('group_commands')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->can("group_commands")) 0 71 71
919 0 $c->group_commands(
920 'Host commands',
921 'host-list',
922 'host-new',
923 'host-update',
924 'host-delete',
925 'host-bind',
926 'host-deny',
927 );
928 }
929 71 return;
930 }
931  
932 72 1; # End of Tapper::CLI
933  
934 __END__
« blib/lib/Tapper/CLI/API/Command/upload.pm ↑ Summary blib/lib/Tapper/CLI/API/Command/download.pm »