Skip to content

Commit

Permalink
Re-add support for managing yumrepo
Browse files Browse the repository at this point in the history
This commit creates a new class called `package_source_info`,
which has some initial framework for managing the postgresql.org
yumrepo.  It also serves as a container for the 'version'
variable that is needed by the 'platform' class in order to
use other versions of postgres besides the system default.
  • Loading branch information
Chris Price committed Dec 3, 2012
1 parent 663c779 commit fa24f24
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 17 deletions.
23 changes: 23 additions & 0 deletions manifests/package_source/yum_postgresql_org.pp
@@ -0,0 +1,23 @@
class postgresql::package_source::yum_postgresql_org(
$version
) {

$version_parts = split($version, '[.]')
$package_version = "${version_parts[0]}${version_parts[1]}"

file { "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}":
source => "puppet:///modules/postgresql_tests/RPM-GPG-KEY-PGDG-${package_version}"
} ->

yumrepo { "yum.postgresql.org":
descr => "PostgreSQL ${version} \$releasever - \$basearch",
baseurl => "http://yum.postgresql.org/${version}/redhat/rhel-\$releasever-\$basearch",
enabled => 1,
gpgcheck => 1,
gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}",
}

if defined(Package['postgresql-server']) {
Yumrepo['yum.postgresql.org'] -> Package['postgresql-server']
}
}
51 changes: 51 additions & 0 deletions manifests/package_source_info.pp
@@ -0,0 +1,51 @@
# 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")
}
}
}
}
8 changes: 6 additions & 2 deletions manifests/platform.pp
Expand Up @@ -14,8 +14,12 @@
#
class postgresql::platform {

#$version = $postgresql::version
$version = $::postgres_default_version
if defined(Class[Postgresql::Package_source_info]) {
$version = $postgresql::package_source_info::version
} else {
$version = $::postgres_default_version
}


case $::operatingsystem {
default: {
Expand Down
4 changes: 4 additions & 0 deletions manifests/server.pp
Expand Up @@ -53,6 +53,10 @@
ensure => $package_ensure,
name => $package_name_real,
}

if defined(Yumrepo['yum.postgresql.org']) {
Yumrepo['yum.postgresql.org'] -> Package['postgresql-server']
}

$config_class = {}
$config_class['postgresql::config'] = $config_hash
Expand Down
20 changes: 19 additions & 1 deletion spec/support/shared_examples/non_default_postgres.rb
Expand Up @@ -10,6 +10,24 @@ def install_postgres
sudo_and_log(vm, 'puppet apply -e "include postgresql_tests::non_default::test_install"')
end

it "doesn't have any tests yet'" do
describe 'postgresql::db' do
it 'should idempotently create a db that we can connect to' do

# A bare-minimum class to add a DB to postgres, which will be running due to ubuntu
test_class = 'class {"postgresql_tests::non_default::test_db": db => "postgresql_test_db" }'

begin
# Run once to check for crashes
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'; [ $? == 2 ]")

# Run again to check for idempotence
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")

# Check that the database name is present
sudo_psql_and_log(vm, 'postgresql_test_db --command="select datname from pg_database limit 1"')
ensure
sudo_psql_and_log(vm, '--command="drop database postgresql_test_db" postgres')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/support/shared_examples/system_default_postgres.rb
Expand Up @@ -7,7 +7,7 @@

# this method is required by the pg_vm shared context
def install_postgres
sudo_and_log(vm, 'puppet apply --debug -e "include postgresql::server"')
sudo_and_log(vm, 'puppet apply -e "include postgresql::server"')
end

describe 'postgresql::initdb' do
Expand Down
33 changes: 33 additions & 0 deletions spec/test_module/manifests/non_default/test_db.pp
@@ -0,0 +1,33 @@
# puppet-postgresql
# For all details and documentation:
# http://github.com/inkling/puppet-postgresql
#
# Copyright 2012- Inkling Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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::server": } ->

postgresql::db { $db:
user => $db,
password => $db,
}
}
18 changes: 5 additions & 13 deletions spec/test_module/manifests/non_default/test_install.pp
@@ -1,18 +1,10 @@
class postgresql_tests::non_default::test_install {

file { '/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-92':
source => 'puppet:///modules/postgresql_tests/RPM-GPG-KEY-PGDG-92'
class { "postgresql::package_source_info":
version => '9.2',
source => 'yum.postgresql.org',
manage_repo => true,
} ->

yumrepo { 'pgdg92':
descr => 'PostgreSQL 9.2 $releasever - $basearch',
baseurl => 'http://yum.postgresql.org/9.2/redhat/rhel-$releasever-$basearch',
enabled => 1,
gpgcheck => 1,
gpgkey => 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-92',
} ->

class { "postgresql::server":
package_name => 'postgresql92-server'
}
class { "postgresql::server": }
}
22 changes: 22 additions & 0 deletions tests/server-yum-postgresql-org.pp
@@ -0,0 +1,22 @@
# This manifest shows an example of how you can use a newer version of
# postgres from yum.postgresql.org, 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 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
# 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::server": }

0 comments on commit fa24f24

Please sign in to comment.