lib/Conan/Deploy.pm

filter: Statementstmt 47.9% 35 / 73 Branchbran 26.9% 7 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 75.0% 3 / 4 totaltotal 45.3% 53 / 117 CC 23 SCAR 29.5
CC
23
Cov
42%
__config
35.6
md5dir
19.0
promote_image
16.1
CRAP 19.1
« lib/Conan/Configure/Xen.pm ↑ Summary blib/lib/Conan.pm »
1 package Conan::Deploy;
2  
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Rsync;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶sub __config {
Subroutine __config: called CC=9 SCAR=35.7
7 1 ▶ my @config_files = glob '/etc/conan.cfg ~/.conanrc';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 my %config_options;
10  
11 1 for( @config_files ){
12 2 ▶ next unless -f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 2 0 2
13 0 ▶ print "D: Parsing [$_]\n" if -f $_;
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ 0 0 0
14  
15 0 my $fd;
16 0 open $fd, "<$_";
17  
18 0 ▶ next unless $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless $fd 0 0 0
19  
20 0 my @lines = <$fd>;
21 0 chomp for @lines;
22  
23 0 s/#.*// for @lines;
24  
25 0 @lines = grep { /^\S/ } @lines;
26  
27 0 ▶ my %r = map { ($1,$2) if /^(\S+)=(\S+)/ } @lines;
Branch: 1 branch
BranchTrueFalseTotal
if /^(\S+)=(\S+)/ 0 0 0
28  
29 0 for ( keys %r ){
30 0 $config_options{"$_"} = $r{"$_"};
31 }
32 }
33 1 return %config_options;
34 }
35  
36 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
37 1 my $class = shift;
38  
39 1 my %config_options = __config @_;
40  
41 1 my $args = {
42 %config_options,
43 @_,
44 };
45  
46 1 return bless $args => $class;
47 }
48  
49 # Call for the "promot image" call
50 1 ▶sub promote_image {
Subroutine promote_image: called CC=9 SCAR=27.8
Pod documented
51 1 my $self = shift;
52 1 my $image = shift;
53 1 my $orig_image = $image;
54  
55 1 ▶ unless( defined $self->{srcimagebase} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"srcimagebase"}) 0 1 1
56 0 croak "Must supply a srcimagebase to the Conan::Deploy constructor";
57 }
58  
59 1 ▶ unless( -d "$self->{srcimagebase}" ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d qq[$self->{"srcimagebase"}]) 0 1 1
60 0 croak "$self->{srcimagebase} doesn't exist";
61 }
62  
63 1 ▶ unless( $self->{targetimagebase} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"targetimagebase"}) 0 1 1
64 0 croak "Must supply a targetimagebase to the Conan::Deploy constructor";
65 }
66  
67
68 1 ▶ unless( -d "$self->{targetimagebase}" ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d qq[$self->{"targetimagebase"}]) 0 1 1
69 0 croak "$self->{targetimagebase} doesn't exist";
70 }
71  
72 # Check if the source image has a / in it
73 1 ▶ unless( $image =~ /\// ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($image =~ m[/]) 1 0 1
74 1 $image = $self->{srcimagebase} . "/" . $image;
75 }
76  
77 1 ▶ unless( -d $image || -f $image ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $image or -f $image) 0 1 1
Condition33%1/3
-d $image or -f $image
l!l&&r!l&&!r
100
MC/DC0%0/2
-d $image or -f $image
-d $image -f $image
Truth table33%1/3
A or B
A= -d $imageB= -f $image
ABresult
1X1
011
000
78 0 croak "$image doesn't exist";
79 }
80  
81 1 printf "D: Copying [%s] to [%s]\n", $image, $self->{targetimagebase};
82  
83 1 my $obj = File::Rsync->new( { archive => 1, compress => 1 } );
84  
85 1 ▶ $obj->exec( { src => $image, dest => $self->{targetimagebase} } ) or croak "rsync failed";
Branch: 1 branch
BranchTrueFalseTotal
$obj->exec({"src", $image, "dest", $self->{"targetimagebase"}}) or croak("rsync failed") 0 0 0
86  
87 0 $self->md5( $orig_image );
88 }
89  
90 0 ▶sub md5 {
Subroutine md5: not called CC=3 SCAR=22.2
Pod documented
91 0 my $self = shift;
92 0 my $image = shift;
93  
94 0 ▶ sub md5dir {
Subroutine md5dir: not called CC=5 SCAR=29.4
Pod undocumented
95 0 my ($base, $image) = @_;
96  
97 0 my $cmd = 'find ' . $base . "/" . $image . " -type f | xargs md5sum";
98 0 print "D: Running [$cmd]\n";
99  
100 0 open $fd, "$cmd |";
101  
102 0 my @lines = <$fd>;
103  
104 0 close $fd;
105  
106 0 chomp for @lines;
107  
108 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 0 s/\s+$base\// / for @lines;
111 0 s/\s+$image/ / for @lines;
112  
113 0 ▶ my %r = map { ($2,$1) if /^(\S+)\s+(\S+)/ } @lines;
Branch: 1 branch
BranchTrueFalseTotal
if /^(\S+)\s+(\S+)/ 0 0 0
114 0 return %r;
115 }
116  
117 0 my %t = md5dir( $self->{targetimagebase}, $image );
118 0 my %s = md5dir( $self->{srcimagebase}, $image );
119  
120 0 for my $file ( keys %s ){
121 # Check that the md5s match
122 croak "Mismatch between target and source on [$file]"
123 0 ▶ if( $t{"$file"} ne $s{"$file"} );
Branch: 1 branch
BranchTrueFalseTotal
if $t{"$file"} ne $s{"$file"} 0 0 0
124 }
125  
126 0 return 1;
127 }
128  
129 1 1;
130  
131 __END__
« lib/Conan/Configure/Xen.pm ↑ Summary blib/lib/Conan.pm »