Merge pull request #693 from frconil/master

Fixes MODULES_2059 - adds extension argument
This commit is contained in:
Bryan Jen 2015-09-09 15:21:09 -07:00
commit 0ffbcc0a5c
3 changed files with 54 additions and 13 deletions

View file

@ -679,7 +679,10 @@ OS user for running `psql`. Defaults to the default user for the module, usually
Hash of environment variable used when connecting to a remote server. Defaults to connecting to the local Postgres instance.
###Resource: postgresql::server::extension
Manages a postgresql extension.
This defined type manages a postgresql extension for a given database.
####`extension`
The extension to activate. If left blank, will use the name of the resource.
####`database`
The database on which to activate the extension.

View file

@ -1,6 +1,7 @@
# Activate an extension on a postgresql database
define postgresql::server::extension (
$database,
$extension = $name,
$ensure = 'present',
$package_name = undef,
$package_ensure = undef,
@ -12,16 +13,16 @@ define postgresql::server::extension (
case $ensure {
'present': {
$command = "CREATE EXTENSION \"${name}\""
$command = "CREATE EXTENSION \"${extension}\""
$unless_comp = '='
$package_require = undef
$package_before = Postgresql_psql["Add ${title} extension to ${database}"]
$package_before = Postgresql_psql["Add ${extension} extension to ${database}"]
}
'absent': {
$command = "DROP EXTENSION \"${name}\""
$command = "DROP EXTENSION \"${extension}\""
$unless_comp = '!='
$package_require = Postgresql_psql["Add ${title} extension to ${database}"]
$package_require = Postgresql_psql["Add ${extension} extension to ${database}"]
$package_before = undef
}
@ -30,7 +31,8 @@ define postgresql::server::extension (
}
}
postgresql_psql {"Add ${title} extension to ${database}":
postgresql_psql {"Add ${extension} extension to ${database}":
psql_user => $user,
psql_group => $group,
@ -39,7 +41,7 @@ define postgresql::server::extension (
db => $database,
command => $command,
unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = '${name}') as t WHERE t.count ${unless_comp} 1",
unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = '${extension}') as t WHERE t.count ${unless_comp} 1",
require => Postgresql::Server::Database[$database],
}
@ -49,12 +51,11 @@ define postgresql::server::extension (
default => $package_ensure,
}
package { "Postgresql extension ${title}":
ensure_packages($package_name, {
ensure => $_package_ensure,
name => $package_name,
tag => 'postgresql',
require => $package_require,
before => $package_before,
}
})
}
}

View file

@ -41,7 +41,7 @@ describe 'postgresql::server::extension', :type => :define do
}) }
it {
is_expected.to contain_package('Postgresql extension postgis').with({
is_expected.to contain_package('postgis').with({
:ensure => 'present',
:name => 'postgis',
}).that_comes_before('Postgresql_psql[Add postgis extension to template_postgis]')
@ -63,7 +63,7 @@ describe 'postgresql::server::extension', :type => :define do
}
it {
is_expected.to contain_package('Postgresql extension postgis').with({
is_expected.to contain_package('postgis').with({
:ensure => 'absent',
:name => 'postgis',
})
@ -83,7 +83,7 @@ describe 'postgresql::server::extension', :type => :define do
}
it {
is_expected.to contain_package('Postgresql extension postgis').with({
is_expected.to contain_package('postgis').with({
:ensure => 'present',
:name => 'postgis',
}).that_requires('Postgresql_psql[Add postgis extension to template_postgis]')
@ -91,3 +91,40 @@ describe 'postgresql::server::extension', :type => :define do
end
end
end
describe 'postgresql::server::extension', :type => :define do
let :pre_condition do
"class { 'postgresql::server': }
postgresql::server::database { 'template_postgis2':
template => 'template1',
}"
end
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('postgis'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
let (:title) { 'postgis_db2' }
let (:params) { {
:database => 'template_postgis2',
:extension => 'postgis',
} }
context "with mandatory arguments only" do
it {
is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis2').with({
:db => 'template_postgis2',
:command => 'CREATE EXTENSION "postgis"',
:unless => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count = 1",
}).that_requires('Postgresql::Server::Database[template_postgis2]')
}
end
end