| 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
| |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | print "D: Parsing [$_]\n" if -f $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | my $fd; | |||||||||||||||||||||||||||
| 16 | 0 | open $fd, "<$_"; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | next unless $fd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | 0 | croak "Must supply a srcimagebase to the Conan::Deploy constructor"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | unless( -d "$self->{srcimagebase}" ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | croak "$self->{srcimagebase} doesn't exist"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | unless( $self->{targetimagebase} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | croak "Must supply a targetimagebase to the Conan::Deploy constructor"; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | unless( -d "$self->{targetimagebase}" ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 74 | 1 | $image = $self->{srcimagebase} . "/" . $image; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | unless( -d $image || -f $image ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $image or -f $image
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | return 1; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||