CBSD/bcheckpoint_create.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 37.2% 22 / 59 CC 8 SCAR 38.0
CC
8
Cov
34%
execute
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 44.7
« CBSD/vm_os_profiles_hash.pm ↑ Summary CBSD/bpause.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::bcheckpoint_create;
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=8 SCAR=42.8
Pod undocumented
17 0 my ( $class, %opts ) = @_;
18  
19 0 ▶ if ( !defined( $opts{vm} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"vm"}) 0 0 0
20 0 die 'The required variable "vm" is not set';
21 }
22  
23 # set the defaults
24 0 ▶ if ( !defined( $opts{suspend} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"suspend"}) 0 0 0
25 0 $opts{suspend} = 0;
26 }
27 0 ▶ if ( !defined( $opts{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"name"}) 0 0 0
28 0 $opts{name} = 'checkpoint';
29 }
30  
31 # make sure all the keys are sane
32 0 ▶ if ( ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] or $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]) 0 0 0
Condition0%0/3
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] or $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] or $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
Truth table0%0/3
A or B
A= $opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]]B= $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
ABresult
1X1
011
000
33 || ( $opts{name} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) )
34 {
35 die 'The value either for "vm", "'
36 . $opts{vm}
37 . '" or "name", "'
38 . $opts{name}
39 0 . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
40 }
41 0 ▶ if ( $opts{suspend} =~ /^[01]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"suspend"} =~ /^[01]$/) 0 0 0
42 die 'The value for "suspend", "'
43 . $opts{suspend}
44 0 . '", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value';
45 }
46  
47 # put together the command
48 my $command
49 0 = 'cbsd bcheckpoint mode=create jname=' . $opts{vm} . " name='" . $opts{name} . "' suspend=" . $opts{suspend};
50  
51 0 Rex::Logger::debug( "Checking a CBSD VM via... " . $command );
52  
53 0 my $returned = i_run( $command, fail_ok => 1 );
54  
55 # the output is colorized, if there is an error
56 0 $returned = colorstrip($returned);
57  
58 # check for this second as no VM will also exit non-zero
59 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
60 0 die( "Error running '" . $command . "'" );
61 }
62  
63 0 return 1;
64 }
65  
66 1 1;
« CBSD/vm_os_profiles_hash.pm ↑ Summary CBSD/bpause.pm »