CBSD/bstop.pm

filter: Statementstmt 42.5% 17 / 40 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 32.3% 22 / 68 CC 10 SCAR 43.0
CC
10
Cov
29%
execute
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 73.7
↑ Summary CBSD/vm_os_profiles.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::bstop;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.0.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Term::ANSIColor qw(colorstrip);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub execute {
Subroutine execute: not called CC=10 SCAR=47.0
Pod undocumented
17 0 my ( $class, $name, %opts ) = @_;
18  
19 # set the hard_timeout if needed
20 0 my $hard_timeout = '';
21 0 ▶ if ( defined( $opts{hard_timeout} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"hard_timeout"}) 0 0 0
22  
23 # make sure we have a valid value
24 0 ▶ if ( $opts{hard_timeout} !~ /^[0123456789]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"hard_timeout"} =~ /^[0123456789]+$/) 0 0 0
25 0 die 'hard_timeout value,"' . $opts{hard_timeout} . '", is not numeric';
26 }
27  
28 0 $hard_timeout = 'hard_timeout=' . $opts{hard_timeout};
29 }
30  
31 # set the noacpi value if needed
32 0 my $noacpi = '';
33 0 ▶ if ( defined( $opts{noacpi} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"noacpi"}) 0 0 0
34  
35 # make sure we have a valid value
36 0 ▶ if ( ( $opts{noacpi} ne '0' )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"noacpi"} ne 0 and $opts{"noacpi"} ne 1) 0 0 0
Condition0%0/3
$opts{"noacpi"} ne 0 and $opts{"noacpi"} ne 1
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"noacpi"} ne 0 and $opts{"noacpi"} ne 1
$opts{"noacpi"} ne 0 $opts{"noacpi"} ne 1
Truth table0%0/3
A and B
A= $opts{"noacpi"} ne 0B= $opts{"noacpi"} ne 1
ABresult
0X0
100
111
37 && ( $opts{noacpi} ne '1' ) )
38 {
39 0 die 'noacpi is set and it is not equal to "0" or "1"';
40 }
41  
42 0 $noacpi = 'noacpi=' . $opts{noacpi};
43 }
44  
45 # make sure we have a
46 0 ▶ if ( !defined($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 0 0
47 0 die('No VM name defined');
48 }
49  
50 0 Rex::Logger::debug( "CBSD VM stop via cbsd bstop " . $name );
51  
52 0 my $returned = i_run( 'cbsd bstop jname=' . $name . ' ' . $hard_timeout . ' ' . $noacpi, fail_ok => 1 );
53  
54 # the output is colorized
55 0 $returned = colorstrip($returned);
56  
57 # check for failures caused by it not existing
58 0 ▶ if ( $returned =~ /^No\ such/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returned =~ /^No\ such/) 0 0 0
59 0 die( '"' . $name . '" does not exist' );
60 }
61  
62 # test after no such as that will also exit non-zero
63 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
64 0 die( "Error running 'cbsd bstop " . $name . "'" );
65 }
66  
67 # this is warning message will be thrown if stop fails.... does not return 0 though
68 0 ▶ if ( $returned =~ /unable\ to\ determine\ bhyve\ pid/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returned =~ /unable\ to\ determine\ bhyve\ pid/) 0 0 0
69 0 die( "Either already stopped or other issue determining bhyve PID for '" . $name . "'" );
70 }
71  
72 0 return 1;
73 }
74  
75 1 1;
↑ Summary CBSD/vm_os_profiles.pm »