Skip to content

Commit

Permalink
add Keepalived vrrp_sync_group configuration define
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Vigara committed Aug 27, 2013
1 parent fe2c604 commit 2e622ea
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 0 deletions.
47 changes: 47 additions & 0 deletions manifests/vrrp/sync_group.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# == Define: keepalived::vrrp::sync_group
#
# === Parameters:
#
# $group:: Define vrrp instances to group (Array)
#
# $ensure:: Default: present.
#
# $notify_script_master:: Define the notify master script.
# Default: undef.
#
# $notify_script_backup:: Define the notify backup script.
# Default: undef.
#
# $notify_script_fault:: Define the notify fault script.
# Default: undef.
#
# $notify_script:: Define the notify script.
# Default: undef.
#
# $smtp_alert:: Send email on status change (Boolean)
# Default: undef.
#
#
define keepalived::vrrp::sync_group (
$group,
$ensure = present,
$notify_script_master = undef,
$notify_script_backup = undef,
$notify_script_fault = undef,
$notify_script = undef,
$smtp_alert = undef,
) {
if is_array($group) {
$group_array = $group
}
else {
$group_array = [$group]
}
concat::fragment { "keepalived.conf_vrrp_sync_group_${name}":
ensure => $ensure,
target => "${keepalived::config_dir}/keepalived.conf",
content => template('keepalived/vrrp_sync_group.erb'),
order => 050,
}
}

139 changes: 139 additions & 0 deletions spec/defines/keepalived_vrrp_sync_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
require 'spec_helper'

describe 'keepalived::vrrp::sync_group', :type => :define do
let (:facts) { debian_facts }
let (:pre_condition) { '$concat_basedir = "/tmp"' }

describe 'without parameters' do
let (:title) { '_VALUE_' }

it do
expect { should create_class('keepalived') }.to raise_error(Puppet::Error)
end
end

describe 'with parameter group' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_VALUE_',
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /group {\n\s.*_VALUE_/
)
}
end

describe 'with parameter group' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => ['_VALUE1_','_VALUE2_'],
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /group {\n\s.*_VALUE1_\n\s.*_VALUE2_/
)
}
end

describe 'with parameter notify_script_master' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_GROUP_',
:notify_script_master => '_SCRIPT_',
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /notify_master\s.*_SCRIPT_/
)
}
end

describe 'with parameter notify_script_backup' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_GROUP_',
:notify_script_backup => '_SCRIPT_',
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /notify_backup\s.*_SCRIPT_/
)
}
end

describe 'with parameter notify_script_fault' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_GROUP_',
:notify_script_fault => '_SCRIPT_',
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /notify_fault\s.*_SCRIPT_/
)
}
end

describe 'with parameter notify_script' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_GROUP_',
:notify_script => '_SCRIPT_',
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /notify\s.*_SCRIPT_/
)
}
end

describe 'with parameter smtp_alert' do
let (:title) { '_NAME_' }
let (:params) {
{
:group => '_GROUP_',
:smtp_alert => true,
}
}

it { should create_keepalived__vrrp__sync_group('_NAME_') }
it {
should \
contain_concat__fragment('keepalived.conf_vrrp_sync_group__NAME_').with(
'content' => /smtp_alert/
)
}
end

end
46 changes: 46 additions & 0 deletions templates/vrrp_sync_group.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
vrrp_sync_group <%= @name %> {
group {
<%- @group_array.each do |vrrp_instance| -%>
<%= vrrp_instance %>
<%- end -%>
}

# notify scripts and alerts are optional
#
# filenames of scripts to run on transitions
# can be unquoted (if just filename)
# or quoted (if has parameters)
<%- if @notify_script_master -%>
# to MASTER transition
notify_master <%= @notify_script_master %>
<%- end -%>
<%- if @notify_script_backup -%>
# to BACKUP transition
notify_backup <%= @notify_script_backup %>
<%- end -%>
<%- if @notify_script_fault -%>
# FAULT transition
notify_fault <%= @notify_script_fault %>
<%- end -%>

<%- if @notify_script -%>
# for ANY state transition.
# "notify" script is called AFTER the
# notify_* script(s) and is executed
# with 3 arguments provided by keepalived
# (ie don't include parameters in the notify line).
# arguments
# $1 = "GROUP"|"INSTANCE"
# $2 = name of group or instance
# $3 = target state of transition
# ("MASTER"|"BACKUP"|"FAULT")
notify <%= @notify_script %>
<%- end -%>

# Send email notifcation during state transition,
# using addresses in global_defs above.
<%- if @smtp_alert -%>
smtp_alert
<%- end -%>
}

0 comments on commit 2e622ea

Please sign in to comment.