Merge pull request #280 from 3dna/feature/postgis

postgis support
This commit is contained in:
Ashley Penney 2014-04-02 09:31:03 -04:00
commit 0adbcfb64f
6 changed files with 129 additions and 0 deletions

View file

@ -219,6 +219,7 @@ Classes:
* [postgresql::server](#class-postgresqlserver)
* [postgresql::server::plperl](#class-postgresqlserverplperl)
* [postgresql::server::contrib](#class-postgresqlservercontrib)
* [postgresql::server::postgis](#class-postgresqlserverpostgis)
Resources:
@ -336,6 +337,9 @@ The version of PostgreSQL to install/manage. This is a simple way of providing a
Defaults to your operating system default.
####`postgis_version`
The version of PostGIS to install if you install PostGIS. Defaults to the lowest available with the version of PostgreSQL to be installed.
####`needs_initdb`
This setting can be used to explicitly call the initdb operation after server package is installed and before the postgresql service is started. If not specified, the module will decide whether to call initdb or not depending on your OS distro.
@ -470,6 +474,8 @@ The name of the postgresql contrib package.
####`package_ensure`
The ensure parameter passed on to postgresql contrib package resource.
###Class: postgresql::server::postgis
Installs the postgresql postgis packages.
###Class: postgresql::lib::devel
Installs the packages containing the development libraries for PostgreSQL.

View file

@ -33,6 +33,7 @@ class postgresql::globals (
$group = undef,
$version = undef,
$postgis_version = undef,
$needs_initdb = undef,
@ -87,6 +88,15 @@ class postgresql::globals (
fail('No preferred version defined or automatically detected.')
}
$default_postgis_version = $globals_version ? {
'8.4' => '1.5',
'9.0' => '1.5',
'9.1' => '1.5',
'9.2' => '2.0',
'9.3' => '2.1',
}
$globals_postgis_version = pick($postgis_version, $default_postgis_version)
# Setup of the repo only makes sense globally, so we are doing this here.
if($manage_package_repo) {
class { 'postgresql::repo':

View file

@ -2,6 +2,7 @@
class postgresql::params inherits postgresql::globals {
$ensure = true
$version = $globals_version
$postgis_version = $globals_postgis_version
$listen_addresses = 'localhost'
$ip_mask_deny_postgres_user = '0.0.0.0/0'
$ip_mask_allow_all_users = '127.0.0.1/32'
@ -56,6 +57,14 @@ class postgresql::params inherits postgresql::globals {
$service_status = $service_status
$python_package_name = pick($python_package_name, 'python-psycopg2')
$postgis_package_name = pick(
$postgis_package_name,
versioncmp($postgis_version, '2') ? {
'-1' => "postgis${package_version}",
default => "postgis2_${package_version}",
}
)
}
'Archlinux': {
@ -110,6 +119,13 @@ class postgresql::params inherits postgresql::globals {
$client_package_name = pick($client_package_name, "postgresql-client-${version}")
$server_package_name = pick($server_package_name, "postgresql-${version}")
$contrib_package_name = pick($contrib_package_name, "postgresql-contrib-${version}")
$postgis_package_name = pick(
$postgis_package_name,
versioncmp($postgis_version, '2') ? {
'-1' => "postgresql-${version}-postgis",
default => "postgresql-${version}-postgis-${postgis_version}",
}
)
$devel_package_name = pick($devel_package_name, 'libpq-dev')
$java_package_name = pick($java_package_name, 'libpostgresql-jdbc-java')
$plperl_package_name = pick($plperl_package_name, "postgresql-plperl-${version}")

View file

@ -0,0 +1,27 @@
# Install the postgis postgresql packaging. See README.md for more details.
class postgresql::server::postgis (
$package_name = $postgresql::params::postgis_package_name,
$package_ensure = 'present'
) inherits postgresql::params {
validate_string($package_name)
package { 'postgresql-postgis':
ensure => $package_ensure,
name => $package_name,
tag => 'postgresql',
}
if($package_ensure == 'present' or $package_ensure == true) {
anchor { 'postgresql::server::postgis::start': }->
Class['postgresql::server::install']->
Package['postgresql-postgis']->
Class['postgresql::server::service']->
anchor { 'postgresql::server::postgis::end': }
} else {
anchor { 'postgresql::server::postgis::start': }->
Class['postgresql::server::service']->
Package['postgresql-postgis']->
Class['postgresql::server::install']->
anchor { 'postgresql::server::postgis::end': }
}
}

View file

@ -0,0 +1,28 @@
require 'spec_helper_acceptance'
describe 'postgresql::server::postgis:' do
after :all do
# Cleanup after tests have ran, remove both postgis and server as postgis
# pulls in the server based packages.
pp = <<-EOS.unindent
class { 'postgresql::server':
ensure => absent,
}
class { 'postgresql::server::postgis':
package_ensure => purged,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'test loading class with no parameters' do
pp = <<-EOS.unindent
class { 'postgresql::server': }
class { 'postgresql::server::postgis': }
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end

View file

@ -0,0 +1,42 @@
require 'spec_helper'
describe 'postgresql::server::postgis', :type => :class do
let :pre_condition do
"class { 'postgresql::server': }"
end
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('postgis'),
}
end
describe 'with parameters' do
let(:params) do
{
:package_name => 'mypackage',
:package_ensure => 'absent',
}
end
it 'should create package with correct params' do
should contain_package('postgresql-postgis').with({
:ensure => 'absent',
:name => 'mypackage',
:tag => 'postgresql',
})
end
end
describe 'with no parameters' do
it 'should create package with postgresql tag' do
should contain_package('postgresql-postgis').with({
:tag => 'postgresql',
})
end
end
end