Cleanup and move control of version into params

Thanks to some tricks I learned from Nan Liu and Dan Bode, I was
able to figure out a way to move all of the new version-related stuff
back into the params class, and clean up some of the if/_real stuff.

Basic tests for centos6 + pg 9.2 are passing.
This commit is contained in:
Chris Price 2012-12-04 13:47:49 -08:00
parent 18167c7a3e
commit 228e5c5337
12 changed files with 77 additions and 89 deletions

View file

@ -7,5 +7,5 @@ summary 'PostgreSQL defined resource types'
license 'Apache'
project_page 'https://github.com/puppetlabs/puppet-postgresql/issues'
dependency 'puppetlabs/stdlib', '>= 2.0.0'
dependency 'puppetlabs/stdlib', '>= 3.2.0'
dependency 'puppetlabs/firewall', '>= 0.0.4'

View file

@ -17,8 +17,9 @@ class postgresql::devel(
$package_ensure = 'present'
) inherits postgresql::params {
package { 'postgresql_devel':
package { 'postgresql-devel':
ensure => $package_ensure,
name => $package_name,
tag => 'postgresql',
}
}

View file

@ -21,9 +21,10 @@ class postgresql (
$package_ensure = 'present'
) inherits postgresql::params {
package { 'postgresql_client':
package { 'postgresql-client':
ensure => $package_ensure,
name => $package_name,
tag => 'postgresql',
}
}

View file

@ -17,7 +17,6 @@ class postgresql::package_source::yum_postgresql_org(
gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}",
}
if defined(Package['postgresql-server']) {
Yumrepo['yum.postgresql.org'] -> Package['postgresql-server']
}
}
Yumrepo["yum.postgresql.org"] -> Package<|tag == 'postgresql'|>
}

View file

@ -1,51 +0,0 @@
# TODO: add real docs
# This class allows you to use a newer version of postgres, rather than your
# system's default version.
#
# Note that it is important that you use the '->', or a
# before/require metaparameter to make sure that the `package_source_info`
# class is evaluated before any of the other classes in the module.
#
# Also note that this class includes the ability to automatically manage
# the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass
# 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will
# still need to use the 'package_source_info' class to specify the postgres version
# number, though, in order for the other classes to be able to find the
# correct paths to the postgres dirs.
class postgresql::package_source_info(
$version,
$manage_repo = false,
$source = ''
) {
if ($manage_repo) {
case $::osfamily {
'RedHat': {
if ! $source {
$pkg_source = 'yum.postgresql.org'
} else {
$pkg_source = $source
}
case $pkg_source {
'yum.postgresql.org': {
class { "postgresql::package_source::yum_postgresql_org":
version => $version
}
}
default: {
fail("Unsupported package source '${pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
}
}
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
}
}
}
}

View file

@ -10,7 +10,28 @@
#
# Sample Usage:
#
class postgresql::params {
# TODO: add real docs
# This class allows you to use a newer version of postgres, rather than your
# system's default version.
#
# If you want to do that, note that it is important that you use the '->',
# or a before/require metaparameter to make sure that the `params`
# class is evaluated before any of the other classes in the module.
#
# Also note that this class includes the ability to automatically manage
# the yumrepo resource. If you'd prefer to manage the repo yourself, simply pass
# 'false' or omit the 'manage_repo' parameter--it defaults to 'false'. You will
# still need to use the 'params' class to specify the postgres version
# number, though, in order for the other classes to be able to find the
# correct paths to the postgres dirs.
class postgresql::params(
$version = $::postgres_default_version,
$manage_package_repo = false,
$package_source = undef,
) {
$user = 'postgres'
$group = 'postgres'
$ip_mask_deny_postgres_user = '0.0.0.0/0'
@ -21,6 +42,32 @@ class postgresql::params {
# TODO: figure out a way to make this not platform-specific
$manage_redhat_firewall = false
if ($manage_package_repo) {
case $::osfamily {
'RedHat': {
$rh_pkg_source = pick($package_source, 'yum.postgresql.org')
case $rh_pkg_source {
'yum.postgresql.org': {
class { "postgresql::package_source::yum_postgresql_org":
version => $version
}
}
default: {
fail("Unsupported package source '${rh_pkg_source}' for ${::osfamily} OS family. Currently the only supported source is 'yum.postgresql.org'")
}
}
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports osfamily RedHat and Debian")
}
}
}
# This is a bit hacky, but if the puppet nodes don't have pluginsync enabled,
# they will fail with a not-so-helpful error message. Here we are explicitly
# verifying that the custom fact exists (which implies that pluginsync is
@ -31,14 +78,6 @@ class postgresql::params {
fail "No value for postgres_default_version facter fact; it's possible that you don't have pluginsync enabled."
}
if defined(Class[Postgresql::Package_source_info]) {
$version = $postgresql::package_source_info::version
} else {
$version = $::postgres_default_version
}
case $::operatingsystem {
default: {
$service_provider = undef

View file

@ -26,12 +26,9 @@ class postgresql::server (
package { 'postgresql-server':
ensure => $package_ensure,
name => $package_name,
tag => 'postgresql',
}
if defined(Yumrepo['yum.postgresql.org']) {
Yumrepo['yum.postgresql.org'] -> Package['postgresql-server']
}
$config_class = {}
$config_class['postgresql::config'] = $config_hash

View file

@ -58,6 +58,7 @@ define postgresql::validate_db_connection(
package { 'postgresql-client':
ensure => present,
name => $client_package_name,
tag => 'postgresql',
}
# TODO: port to ruby

View file

@ -4,11 +4,11 @@ module PostgresTestConfig
# valuable for final testing. This constant allows you to toggle between
# strict testing and less strict testing--the latter being useful for
# development purposes.
HardCoreTesting = false
HardCoreTesting = true
# If this value is set to true, then each VM will be suspended after the tests
# against it are completed. This will slow things down a ton during
# iterative development, but will save a lot of system resources by not
# keeping all of the VMs running at the same time.
SuspendVMsAfterSuite = false
SuspendVMsAfterSuite = true
end

View file

@ -18,10 +18,10 @@
class postgresql_tests::non_default::test_db($db) {
class { "postgresql::package_source_info":
version => '9.2',
source => 'yum.postgresql.org',
manage_repo => true,
class { "postgresql::params":
version => '9.2',
manage_package_repo => true,
package_source => 'yum.postgresql.org',
} ->
class { "postgresql::server": } ->

View file

@ -1,10 +1,10 @@
class postgresql_tests::non_default::test_install {
class { "postgresql::package_source_info":
version => '9.2',
source => 'yum.postgresql.org',
manage_repo => true,
class { "postgresql::params":
version => '9.2',
manage_package_repo => true,
package_source => 'yum.postgresql.org',
} ->
class { "postgresql::server": }
}
}

View file

@ -3,20 +3,21 @@
# default version.
#
# Note that it is important that you use the '->', or a
# before/require metaparameter to make sure that the `package_source_info`
# before/require metaparameter to make sure that the `params`
# class is evaluated before any of the other classes in the module.
#
# Also note that this example includes automatic management of the yumrepo
# resource. If you'd prefer to manage the repo yourself, simply pass 'false'
# or omit the 'manage_repo' parameter--it defaults to 'false'. You will still
# need to use the 'package_source_info' class to specify the postgres version
# need to use the 'params' class to specify the postgres version
# number, though, in order for the other classes to be able to find the
# correct paths to the postgres dirs.
class { "postgresql::package_source_info":
version => '9.2',
source => 'yum.postgresql.org',
manage_repo => true,
class { "postgresql::params":
version => '9.2',
manage_package_repo => true,
package_source => 'yum.postgresql.org',
} ->
class { "postgresql::server": }
class { "postgresql::server": }