| 1 | package Giovanni; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mouse::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::OpenSSH; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Giovanni::Stages; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | extends 'Giovanni::Stages'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '1.9'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | has 'debug' => ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | predicate => 'is_debug', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | has 'hostname' => ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | default => hostname(), | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | has 'repo' => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | default => cwd(), | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | has 'scm' => ( | |||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | default => 'git', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | has 'deploy_to' => ( | |||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | default => '/var/www', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | has 'user' => ( | |||||||||||||||||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | default => 'deploy', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | has 'version' => ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | default => 'v1', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | has 'error' => ( | |||||||||||||||||||||||||||||||||||||||||
| 62 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | has 'config' => ( | |||||||||||||||||||||||||||||||||||||||||
| 67 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | has 'notifyer' => ( | |||||||||||||||||||||||||||||||||||||||||
| 72 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | default => 'jabber', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # load SCM plugin | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->load_plugin($self->scm); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $tag = $self->tag(); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $ssh = $self->_get_ssh_conn; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->process_stages($ssh, 'deploy'); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub rollback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($self, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $ssh = $self->_get_ssh_conn; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->process_stages($ssh, 'rollback'); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub process_stages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_stages: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($self, $ssh, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $conf_key = ($mode eq 'restart' ? 'deploy' : $mode); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my @stages = split(/\s*,\s*/, $self->config->{$conf_key}); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | foreach my $stage (@stages) { | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if($mode eq 'restart'){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | next unless $stage =~ m/restart/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->process_hosts($ssh, $stage, $mode); | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $self->process_hosts($ssh, $stage, $mode); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # if one host produced an error while restarting, rollback all | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($self->error and ($stage =~ m/^restart/i) and ($mode eq 'deploy')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->error and $stage =~ /^restart/i and $mode eq "deploy"
$self->error and $stage =~ /^restart/i
MC/DC0%0/3
$self->error and $stage =~ /^restart/i and $mode eq "deploy"
$self->error
$stage =~ /^restart/i
$mode eq "deploy"
Truth table0%0/4
A and B and C
A= $self->errorB= $stage =~ /^restart/iC= $mode eq "deploy"
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->log('ERROR', $self->error); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->process_stages($ssh, 'rollback'); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub process_hosts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_hosts: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($self, $ssh, $stage, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my @hosts = split(/\s*,\s*/, $self->config->{hosts}); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | foreach my $host (@hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->log($ssh->{$host}, "running $stage"); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->$stage($ssh->{$host}); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _get_ssh_conn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_ssh_conn: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my @hosts = split(/\s*,\s*/, $self->config->{hosts}); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $ssh; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | foreach my $host (@hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $conn = $host; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $conn = ($self->config->{user} || $self->user) . '@' . $host; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->config->{'user'} || $self->user
MC/DC0%0/2
$self->config->{'user'} || $self->user
$self->config->{'user'}
$self->user
Truth table0%0/3
A || B
A= $self->config->{'user'}B= $self->user
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $ssh->{$host} = Net::OpenSSH->new($conn, async => 1); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # trigger noop command to check for connection | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | foreach my $host (@hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 141 | $ssh->{$host}->test('echo') | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | or confess "could not connect to $host: " . $ssh->{$host}->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->log($host, 'connected'); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return $ssh; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub restart { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $ssh = $self->_get_ssh_conn; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->process_stages($ssh, 'restart'); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub load_plugin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_plugin: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($self, $plugin) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $plug = 'Giovanni::Plugins::' . ucfirst(lc($plugin)); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | unless (Mouse::Util::is_class_loaded($plug)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | print STDERR "Loading $plugin Plugin\n" if $self->is_debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | with($plug); # or confess "Could not load Plugin: '$plugin'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my ($self, $host, $log) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return unless $log; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $name; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | given ($host) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | when (ref $host eq 'Net::OpenSSH') { $name = $host->get_host; } | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | default { $name = $host; } | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | chomp($log); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | print STDERR "[" . $name . "] " . $log . $/; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub notify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notify: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my ($self, $ssh, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # load notify plugin | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->load_plugin($self->notifyer); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->send_notify($ssh, $conf); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||||||||||||||||