CBSD/vm_os_profiles_hash.pm

filter: Statementstmt 47.9% 23 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 41.6% 30 / 72 CC 9 SCAR 39.3
CC
9
Cov
37%
execute
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 51.1
« CBSD/bcreate.pm ↑ Summary CBSD/bcheckpoint_create.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::vm_os_profiles_hash;
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 1 ▶use Rex::Commands::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub execute {
Subroutine execute: not called CC=9 SCAR=45.0
Pod undocumented
19 0 my ( $class, %opts ) = @_;
20  
21 0 Rex::Logger::debug("Getting a list of VM OS types for CBSD ");
22  
23 # set cloudinit to false by default
24 0 ▶ if ( !defined( $opts{cloudinit} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"cloudinit"}) 0 0 0
25 0 $opts{cloudinit} = 0;
26 }
27  
28 # get where CBSD is installed to
29 0 my %cbsd;
30 0 ▶ eval { %cbsd = get_user('cbsd'); } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { %cbsd = get_user("cbsd") } } or do { my $error = $@ || "Unknown failure"; die q[get_user('cbsd') died with... ] . $error } 0 0 0
31 0 ▶ my $error = $@ || 'Unknown failure';
Condition0%0/2
$@ || 'Unknown failure'
l!l
00
MC/DC0%0/1
$@ || 'Unknown failure'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
32 0 die( "get_user('cbsd') died with... " . $error );
33 };
34  
35 0 my $cbsd_etc_defaults_dir = $cbsd{home} . '/etc/defaults/';
36  
37 # get the VM OS/profile config lists
38 0 my @vm_configs = grep { /^vm\-/ } list_files($cbsd_etc_defaults_dir);
39  
40 # find the requested ones
41 0 my %profiles;
42 0 foreach my $config (@vm_configs) {
43 0 my ( $vm, $os, $profile ) = split( /\-/, $config, 3 );
44 0 $profile =~ s/\.conf$//;
45  
46 0 my $add_profile = 1;
47  
48 # if cloudinit is defined, only add cloudinit images
49 0 ▶ if ( $opts{cloudinit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"cloudinit"}) 0 0 0
50  
51 # since we are default adding, make sure it is not a cloudinit
52 # profile and don't add it if it is not
53 0 ▶ if ( $profile !~ /^cloud\-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($profile =~ /^cloud\-/) 0 0 0
54 0 $add_profile = 0;
55 }
56 }
57  
58 # add the profile if needed
59 0 ▶ if ($add_profile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_profile) 0 0 0
60 0 ▶ if ( !defined( $profiles{$os} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $profiles{$os}) { } 0 0 0
61 0 $profiles{$os} = { $profile => 1 };
62 }
63 else {
64 0 $profiles{$os}{$profile} = 1;
65 }
66 }
67 }
68  
69 0 return %profiles;
70 }
71  
72 1 1;
« CBSD/bcreate.pm ↑ Summary CBSD/bcheckpoint_create.pm »