Skip to content

Commit d0419ad

Browse files
committed
Merge pull request puppetlabs#105 from kbrezina/feature/master/adding-include-to-pg-conf
Support for included configuration file
2 parents 5e0a45e + 236ce47 commit d0419ad

File tree

9 files changed

+97
-5
lines changed

9 files changed

+97
-5
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ postgresql
1212
8. [Disclaimer - Licensing information](#disclaimer)
1313
9. [Transfer Notice - Notice of authorship change](#transfer-notice)
1414
10. [Contributors - List of module contributors](#contributors)
15-
8. [Release Notes - Notes on the most recent updates to the module](#release-notes)
15+
11. [Release Notes - Notes on the most recent updates to the module](#release-notes)
1616

1717

1818
Overview
@@ -72,6 +72,9 @@ Once you've completed your configuration of `postgresql::server`, you can test o
7272

7373
If you get an error message from these commands, it means that your permissions are set in a way that restricts access from where you’re trying to connect. That might be a good thing or a bad thing, depending on your goals.
7474

75+
Advanced configuration setting parameters can be placed into `postgresql_puppet_extras.conf` (located in the same folder as `postgresql.conf`). You can manage that file as a normal puppet file resource, or however you see fit; which gives you complete control over the settings. Any value you specify in that file will override any existing value set in the templated version.
76+
For more details about server configuration parameters see http://www.postgresql.org/docs/9.2/static/runtime-config.html.
77+
7578
###Configuring the database
7679

7780
There are many ways to set up a postgres database using the `postgresql::db` class. For instance, to set up a database for PuppetDB (this assumes you’ve already got the `postgresql::server` set up to your liking in your manifest, as discussed above):
@@ -199,6 +202,10 @@ This class is used to manage the basic postgresql client packages (which include
199202

200203
This defined type can be used to create a database with no users and no permissions, which is a rare use case.
201204

205+
**postgresql::tablespace**
206+
207+
This defined type can be used to create a tablespace.
208+
202209
**postgresql_psql**
203210

204211
This defined type manages the command line tool for the postgresql module.

manifests/config/beforeservice.pp

+16-1
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,28 @@
6262

6363
# We must set a "listen_addresses" line in the postgresql.conf if we
6464
# want to allow any connections from remote hosts.
65-
file_line { 'postgresql.conf':
65+
file_line { 'postgresql.conf#listen_addresses':
6666
path => $postgresql_conf_path,
6767
match => '^listen_addresses\s*=.*$',
6868
line => "listen_addresses = '${listen_addresses}'",
6969
notify => Service['postgresqld'],
7070
}
7171

72+
# Here we are adding an 'include' line so that users have the option of
73+
# managing their own settings in a second conf file.
74+
file_line { 'postgresql.conf#include':
75+
path => $postgresql_conf_path,
76+
line => "include 'postgresql_puppet_extras.conf'",
77+
notify => Service['postgresqld'],
78+
}
79+
80+
# Since we're adding an "include" for this extras config file, we need
81+
# to make sure it exists.
82+
exec { "touch `dirname $postgresql_conf_path`/postgresql_puppet_extras.conf" :
83+
path => "/usr/bin:/bin",
84+
unless => "[ -f `dirname $postgresql_conf_path`/postgresql_puppet_extras.conf ]"
85+
}
86+
7287
# TODO: is this a reasonable place for this firewall stuff?
7388
# TODO: figure out a way to make this not platform-specific; debian and ubuntu have
7489
# an out-of-the-box firewall configuration that seems trickier to manage

manifests/server.pp

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
# [*package_name*] - name of package
99
# [*service_name*] - name of service
1010
#
11+
# Configuration:
12+
# Advanced configuration setting parameters can be placed into 'postgresql_puppet_extras.conf' (located in the same
13+
# folder as 'postgresql.conf'). You can manage that file as a normal puppet file resource, or however you see fit;
14+
# which gives you complete control over the settings. Any value you specify in that file will override any existing
15+
# value set in the templated version.
16+
#
1117
# Actions:
1218
#
1319
# Requires:
@@ -61,5 +67,4 @@
6167
onlyif => $service_status,
6268
refreshonly => true,
6369
}
64-
6570
}

spec/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ instead do something like:
2727

2828
For some options that might speed up the testing process a bit during development,
2929
please see `spec/support/postgres_test_config.rb`.
30+
31+
By default the sahara gem restores VMs to a snapshot state after each test,
32+
to make sure that the individual tests aren't polluting the ones that are run later.
33+
If you want to disable this during development, you can set HardCoreTesting to false
34+
in `spec/support/postgres_test_config.rb`.

spec/support/postgres_test_utils.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def sudo_and_log(vm, cmd)
99
result
1010
end
1111

12-
def sudo_psql_and_log(vm, psql_cmd, user = 'postgres')
13-
sudo_and_log(vm, "su #{user} -c 'psql #{psql_cmd}'")
12+
def sudo_psql_and_log(vm, psql_cmd, user = 'postgres', extras = '')
13+
sudo_and_log(vm, "su #{user} -c 'psql #{psql_cmd}' #{extras}")
1414
end
1515

1616
def sudo_psql_and_expect_result(vm, psql_cmd, expected, user = 'postgres')

spec/support/shared_examples/system_default_postgres.rb

+20
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,24 @@ def install_postgres
150150
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')
151151
end
152152
end
153+
154+
describe 'postgresql.conf include' do
155+
it "should support an 'include' directive at the end of postgresql.conf" do
156+
test_class = 'class {"postgresql_tests::system_default::test_pgconf_include": }'
157+
158+
# Run once to check for crashes
159+
sudo_and_log(vm, "puppet apply -e '#{test_class}'")
160+
161+
# Run again to check for idempotence
162+
sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{test_class}'")
163+
164+
sudo_and_log(vm, "service #{service_name} restart")
165+
166+
# Check that the user can create a table in the database
167+
sudo_psql_and_expect_result(vm, '--command="show max_connections" -t', '123', 'postgres')
168+
169+
cleanup_class = 'class {"postgresql_tests::system_default::test_pgconf_include_cleanup": }'
170+
sudo_and_log(vm, "puppet apply -e '#{cleanup_class}'")
171+
end
172+
end
153173
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class postgresql_tests::system_default::test_pgconf_include {
2+
3+
require postgresql::params
4+
5+
$pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
6+
7+
file { $pg_conf_include_file :
8+
content => 'max_connections = 123'
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class postgresql_tests::system_default::test_pgconf_include_cleanup {
2+
3+
require postgresql::params
4+
5+
$pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
6+
7+
file { $pg_conf_include_file :
8+
ensure => absent
9+
}
10+
11+
}

tests/postgresql_pgconf_extras.pp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class { 'postgresql::server':
2+
config_hash => {
3+
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
4+
'ip_mask_allow_all_users' => '0.0.0.0/0',
5+
'listen_addresses' => '*',
6+
'manage_redhat_firewall' => true,
7+
'postgres_password' => 'postgres',
8+
},
9+
}
10+
11+
include "postgresql::params"
12+
13+
$pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
14+
15+
file { $pg_conf_include_file:
16+
content => 'max_connections = 123',
17+
notify => Service['postgresqld'],
18+
}
19+

0 commit comments

Comments
 (0)