CBSD/bsnapshot_remove.pm

filter: Statementstmt 54.8% 17 / 31 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 43.1% 22 / 51 CC 6 SCAR 31.5
CC
6
Cov
40%
execute
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 23.4
« CBSD/bsnapshot_create.pm ↑ Summary CBSD/bsnapshot_rollback.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::bsnapshot_remove;
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=6 SCAR=37.4
Pod undocumented
17 0 my ( $class, %opts ) = @_;
18  
19 # make sure we have everything we need defined
20 0 ▶ if ( !defined( $opts{vm} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"vm"}) 0 0 0
21 0 die 'The required variable "vm" is not set';
22 }
23 0 ▶ if ( !defined( $opts{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"name"}) 0 0 0
24 0 die 'The required variable "name" is not set';
25 }
26  
27 # make sure all the keys are sane
28 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
29 || ( $opts{name} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) )
30 {
31 die 'The value either for "vm", "'
32 . $opts{vm}
33 . '" or "name", "'
34 . $opts{name}
35 0 . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
36 }
37  
38 # put together the command
39 my $command
40 0 = 'cbsd bsnapshot mode=destroy jname=' . $opts{vm} . " snapname='" . $opts{name} . "'";
41  
42 0 Rex::Logger::debug( "Removing a snapshot for a CBSD VM via... " . $command );
43  
44 0 my $returned = i_run( $command, fail_ok => 1 );
45  
46 # the output is colorized, if there is an error
47 0 $returned = colorstrip($returned);
48  
49 # check for this second as no VM will also exit non-zero
50 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
51 0 die( "Error running '" . $command . "'" );
52 }
53  
54 0 return 1;
55 }
56  
57 1 1;
« CBSD/bsnapshot_create.pm ↑ Summary CBSD/bsnapshot_rollback.pm »