Skip to content

Commit

Permalink
Merge pull request voxpupuli#141 from syseleven/implement-version
Browse files Browse the repository at this point in the history
Implement ensure => $version for pacemaker and corosync package
  • Loading branch information
ffrank committed Jun 22, 2015
2 parents 8d725ae + 011da2b commit 98b65fe
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 8 deletions.
93 changes: 86 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@
# [*ttl*]
# Time To Live (multicast only).
#
# [*packages*]
# Define the list of software packages which should be installed.
# [*package_corosync*]
# Define if package corosync should be installed.
# Defaults to true
#
# [*version_corosync*]
# Define what version of corosync should be installed.
# Defaults to present
#
# [*package_pacemaker*]
# Define if package pacemaker should be installed.
# Defaults to true
#
# [*version_pacemaker*]
# Define what version of pacemaker should be installed.
# Defaults to present
#
# [*set_votequorum*]
# Set to true if corosync_votequorum should be used as quorum provider.
Expand All @@ -80,6 +93,12 @@
# [*token_retransmits_before_loss_const*]
# How many token retransmits before forming a new configuration
#
# === Deprecated Parameters
#
# [*packages*]
# Deprecated in favour of package_{corosync,pacemaker} and
# version_{corosync,pacemaker}. Array of packages to install.
#
# === Examples
#
# class { 'corosync':
Expand Down Expand Up @@ -110,7 +129,11 @@
$debug = $::corosync::params::debug,
$rrp_mode = $::corosync::params::rrp_mode,
$ttl = $::corosync::params::ttl,
$packages = $::corosync::params::packages,
$packages = undef,
$package_corosync = undef,
$version_corosync = undef,
$package_pacemaker = undef,
$version_pacemaker = undef,
$set_votequorum = $::corosync::params::set_votequorum,
$quorum_members = ['localhost'],
$token = $::corosync::params::token,
Expand All @@ -121,6 +144,66 @@
fail('set_votequorum is true, but no quorum_members have been passed.')
}

if $packages {
warning('$corosync::packages is deprecated, use $corosync::package_{corosync,pacemaker} instead!')

package{ $packages:
ensure => present,
}

# Ensure no options conflicting with $packages are set:

if $package_corosync {
fail('$corosync::package_corosync and $corosync::packages must not be mixed!')
}
if $package_pacemaker {
fail('$corosync::package_pacemaker and $corosync::packages must not be mixed!')
}
if $version_corosync {
fail('$corosync::version_corosync and $corosync::packages must not be mixed!')
}
if $version_pacemaker {
fail('$corosync::version_pacemaker and $corosync::packages must not be mixed!')
}
} else {
# Handle defaults for new-style package parameters here to allow co-existence with $packages.
if $package_corosync == undef {
$_package_corosync = true
} else {
$_package_corosync = $package_corosync
}

if $package_pacemaker == undef {
$_package_pacemaker = true
} else {
$_package_pacemaker = $package_pacemaker
}

if $version_corosync == undef {
$_version_corosync = present
} else {
$_version_corosync = $version_corosync
}

if $version_pacemaker == undef {
$_version_pacemaker = present
} else {
$_version_pacemaker = $version_pacemaker
}

if $_package_corosync == true {
package { 'corosync':
ensure => $_version_corosync,
}
}

if $_package_pacemaker == true {
package { 'pacemaker':
ensure => $_version_pacemaker,
}
}
}

if ! is_bool($enable_secauth) {
validate_re($enable_secauth, '^(on|off)$')
}
Expand Down Expand Up @@ -177,10 +260,6 @@
}
}

package {$packages:
ensure => present,
}

if $::osfamily == 'RedHat' {
package { 'pcs':
ensure => present,
Expand Down
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
$debug = false
$rrp_mode = 'none'
$ttl = false
$packages = ['corosync', 'pacemaker']
$token = 3000
$token_retransmits_before_lost_const = 10

Expand Down
70 changes: 70 additions & 0 deletions spec/classes/corosync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,76 @@
end
end


[ :package_corosync, :package_pacemaker, :version_corosync, :version_pacemaker ].each { |package_param|
context "new-style package parameter $#{package_param} mixed with deprecated $packages parameter" do
before :each do
params.merge!(
{
package_param => true, # value does not really matter here: these
# two params must not both be defined
# at the same time.
:packages => ['corosync', 'pacemaker'],
}
)
end

it 'raises error' do
should raise_error(
Puppet::Error,
/\$corosync::#{package_param} and \$corosync::packages must not be mixed!/
)
end
end
}


[ :corosync, :pacemaker ].each { |package|
context "install package #{package} with default version" do
before :each do
params.merge!( { "package_#{package}" => true, } )
end

it "does install #{package}" do
should contain_package(package).with(
:ensure => 'present'
)
end

end


context "install package #{package} with custom version" do
before :each do
params.merge!(
{ "package_#{package}" => true,
"version_#{package}" => '1.1.1' }
)
end

it "does install #{package} with version 1.1.1" do
should contain_package(package).with(
:ensure => '1.1.1'
)
end

end


context "do not install #{package}" do
before :each do
params.merge!( { "package_#{package}" => false, } )
end

it "does not install #{package}" do
should_not contain_package(package)
end

end

}


context 'when set_quorum is true and quorum_members are not set' do
before :each do
params.merge!(
Expand Down

0 comments on commit 98b65fe

Please sign in to comment.