CBSD/bstart.pm

filter: Statementstmt 45.9% 17 / 37 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 37.9% 22 / 58 CC 8 SCAR 38.0
CC
8
Cov
33%
execute
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 44.7
« CBSD/bpause.pm ↑ Summary CBSD/p9shares_add.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::bstart;
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.1.0'; # 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, $vm, %opts ) = @_;
18  
19 0 ▶ if ( !defined($vm) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $vm) 0 0 0
20 0 die('No VM name defined');
21 }
22  
23 # make sure all the VM is sane
24 0 ▶ if ( $opts{vn} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"vn"} =~ m[[\t\ \=\\/\'\"\n\;\&]]) 0 0 0
25 {
26 die 'The value either for "vm", "'
27 . $opts{vm}
28 0 . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
29 }
30  
31 0 my $command='cbsd bstart jname=' . $vm;
32  
33 0 ▶ if (defined($opts{checkpoint})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"checkpoint"}) 0 0 0
34 # make sure all the VM is sane
35 0 ▶ if ( $opts{checkpoint} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"checkpoint"} =~ m[[\t\ \=\\/\'\"\n\;\&]]) 0 0 0
36 {
37 die 'The value either for "checkpoint", "'
38 . $opts{checkpoint}
39 0 . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
40 }
41  
42 0 $command=$command." checkpoint='".$opts{checkpoint}."'";
43 }
44  
45 0 Rex::Logger::debug( "CBSD VM start via... ".$command );
46  
47 0 my $returned = i_run( 'cbsd bstart jname=' . $vm, fail_ok => 1 );
48  
49 # the output is colorized
50 0 $returned = colorstrip($returned);
51  
52 # check for failures caused by it not existing
53 0 ▶ if ( $returned =~ /^No\ such/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returned =~ /^No\ such/) 0 0 0
54 0 die( '"' . $vm . '" does not exist' );
55 }
56  
57 # check for failures caused by it already running
58 0 ▶ if ( $returned =~ /already\ running/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returned =~ /already\ running/) 0 0 0
59 0 die( '"' . $vm . '" is already running' );
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 bstart " . $vm . "'" );
65 }
66  
67 0 return 1;
68 }
69  
70 1 1;
« CBSD/bpause.pm ↑ Summary CBSD/p9shares_add.pm »