Skip to content

Commit 9ef9408

Browse files
committed
Merge remote branch 'upstream/master' into feature/jdbc
Conflicts: README.md
2 parents ba454d4 + 5e0a45e commit 9ef9408

File tree

12 files changed

+493
-92
lines changed

12 files changed

+493
-92
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2.0.1
2+
=======
3+
4+
Minor bugfix release.
5+
6+
2013-01-16 - Chris Price <[email protected]>
7+
* Fix revoke command in database.pp to support postgres 8.1 (43ded42)
8+
9+
2013-01-15 - Jordi Boggiano <[email protected]>
10+
* Add support for ubuntu 12.10 status (3504405)
11+
112
2.0.0
213
=======
314

Modulefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name 'puppetlabs-postgresql'
2-
version '2.0.0'
2+
version '2.0.1'
33
source 'git://github.com/puppetlabs/puppet-postgresql.git'
44
author 'Inkling/Puppet Labs'
55
description 'PostgreSQL defined resource types'

README.md

Lines changed: 237 additions & 84 deletions
Large diffs are not rendered by default.

lib/facter/postgres_default_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_debian_postgres_version
1414
# TODO: add more debian versions or better logic here
1515
when /^6\./
1616
"8.4"
17-
when /^wheezy/
17+
when /^wheezy/, /^7\./
1818
"9.1"
1919
else
2020
nil

manifests/database.pp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
define postgresql::database(
2323
$dbname = $title,
24-
$charset = 'UTF8')
24+
$charset = 'UTF8',
25+
$tablespace = undef)
2526
{
2627
include postgresql::params
2728

@@ -33,7 +34,14 @@
3334
$public_revoke_privilege = "ALL"
3435
}
3536

36-
$createdb_command = "${postgresql::params::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
37+
$createdb_command_tmp = "${postgresql::params::createdb_path} --template=template0 --encoding '${charset}' ${locale_option} '${dbname}'"
38+
39+
if($tablespace == undef) {
40+
$createdb_command = $createdb_command_tmp
41+
}
42+
else {
43+
$createdb_command = "${createdb_command_tmp} --tablespace='${tablespace}'"
44+
}
3745

3846
postgresql_psql { "Check for existence of db '$dbname'":
3947
command => "SELECT 1",

manifests/db.pp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# function in this module
1717
# [*charset*] - database charset. defaults to 'utf8'
1818
# [*grant*] - privilege to grant user. defaults to 'all'.
19+
# [*tablespace*] - database tablespace. default to use the template database's tablespace.
1920
#
2021
# Actions:
2122
#
@@ -35,13 +36,15 @@
3536
$user,
3637
$password,
3738
$charset = 'utf8',
38-
$grant = 'ALL'
39-
) {
39+
$grant = 'ALL',
40+
$tablespace = undef)
41+
{
4042

4143
postgresql::database { $name:
4244
# TODO: ensure is not yet supported
4345
#ensure => present,
4446
charset => $charset,
47+
tablespace => $tablespace,
4548
#provider => 'postgresql',
4649
require => Class['postgresql::server'],
4750
}

manifests/tablespace.pp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Define: postgresql::tablespace
2+
#
3+
# This module creates tablespace
4+
#
5+
# Parameters:
6+
# [*title*] - the name of a tablespace to be created. The name cannot begin with pg_, as such names are reserved for system tablespaces.
7+
# [*owner*] - the name of the user who will own the tablespace. If omitted, defaults to the user executing the command.
8+
# Only superusers can create tablespaces, but they can assign ownership of tablespaces to non-superusers.
9+
# [*location*] - The directory that will be used for the tablespace. The directory should be empty and must be owned by the PostgreSQL
10+
# system user. The directory must be specified by an absolute path name.
11+
#
12+
# Actions:
13+
#
14+
# Requires:
15+
#
16+
# class postgresql::server
17+
#
18+
# Sample Usage:
19+
#
20+
# postgresql::tablespace { 'dbspace':
21+
# location => '/data/dbs',
22+
# }
23+
#
24+
#
25+
define postgresql::tablespace(
26+
$location,
27+
$owner = undef,
28+
$spcname = $title)
29+
{
30+
include postgresql::params
31+
32+
if ($owner == undef) {
33+
$owner_section = ''
34+
}
35+
else {
36+
$owner_section = "OWNER ${owner}"
37+
}
38+
39+
$create_tablespace_command = "CREATE TABLESPACE ${spcname} ${owner_section} LOCATION '${location}'"
40+
41+
file { "${location}":
42+
ensure => directory,
43+
owner => 'postgres',
44+
group => 'postgres',
45+
mode => 700,
46+
}
47+
48+
postgresql_psql { "Create tablespace '${spcname}'":
49+
command => $create_tablespace_command,
50+
unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
51+
cwd => $postgresql::params::datadir,
52+
require => [Class['postgresql::server'], File["${location}"]],
53+
}
54+
}

spec/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ You will need the following in order to run them:
55
* Virtualbox
66
* vagrant
77
* 'sahara' gem
8+
* The source code for all of the dependent modules; you should clone a copy of each of these at the same level in your directory structure as your copy of puppet-postgresql. For best results you should check out the same tag that is specified as the dependency in the puppet-postgresql `Modulefile`. At the time of this writing, here are the github repos you'll need (but check the `Modulefile` to make sure you're up to date):
9+
* stdlib : https://github.com/puppetlabs/puppetlabs-stdlib
10+
* firewall : https://github.com/puppetlabs/puppetlabs-firewall
11+
* apt : https://github.com/puppetlabs/puppetlabs-apt
812
* A decent chunk of free disk space (~300MB per distro tested)
913
* Patience :)
1014

@@ -22,4 +26,4 @@ instead do something like:
2226
rspec ./spec/distros/ubuntu_lucid_64
2327

2428
For some options that might speed up the testing process a bit during development,
25-
please see `spec/support/postgres_test_config.rb`.
29+
please see `spec/support/postgres_test_config.rb`.

spec/support/postgres_test_utils.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ def sudo_and_log(vm, cmd)
1212
def sudo_psql_and_log(vm, psql_cmd, user = 'postgres')
1313
sudo_and_log(vm, "su #{user} -c 'psql #{psql_cmd}'")
1414
end
15-
end
15+
16+
def sudo_psql_and_expect_result(vm, psql_cmd, expected, user = 'postgres')
17+
result = sudo_and_log(vm, "su #{user} -c 'psql -t #{psql_cmd}'")
18+
19+
result.sub!(/stdin: is not a tty/, '')
20+
result.strip!
21+
22+
ok = result == expected
23+
@logger.debug("Expected: #{expected} => #{ok ? 'OK' : 'BAD'}")
24+
25+
if !ok
26+
raise "An unexpected result returned - result: '#{result}' / expected: '#{expected}'"
27+
end
28+
end
29+
end

spec/support/shared_examples/system_default_postgres.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,20 @@ def install_postgres
134134
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_pp}'; [ $? == 4 ]")
135135
end
136136
end
137+
138+
describe 'postgresql::tablespace' do
139+
it 'should idempotently create tablespaces and databases that are using them' do
140+
test_class = 'class {"postgresql_tests::system_default::test_tablespace": }'
141+
142+
# Run once to check for crashes
143+
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
144+
145+
# Run again to check for idempotence
146+
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
147+
148+
# Check that databases use correct tablespaces
149+
sudo_psql_and_expect_result(vm, '--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb1\'"\'"', 'tablespace1')
150+
sudo_psql_and_expect_result(vm, '--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"', 'tablespace2')
151+
end
152+
end
137153
end

0 commit comments

Comments
 (0)