Various cleanups

Signed-off-by: Ken Barber <ken@bob.sh>
This commit is contained in:
Ken Barber 2013-09-18 22:25:51 +01:00
parent 1fbc9c6ece
commit c8d3ecde14
35 changed files with 76 additions and 322 deletions

View file

@ -1 +0,0 @@
include postgresql::client

View file

@ -1,19 +0,0 @@
# This manifest shows an example of how you can use a newer version of
# postgres from yum.postgresql.org or apt.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 `params`
# class is evaluated before any of the other classes in the module.
#
# Also note that this example includes automatic management of the yumrepo or
# apt 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 'postgresql' 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':
version => '9.2',
manage_package_repo => true,
}->
class { 'postgresql::server': }

View file

@ -1,22 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'manage_redhat_firewall' => true,
'postgres_password' => 'postgres',
},
}
postgresql::database{ ['test1', 'test2', 'test3']:
# TODO: ensure not yet supported
#ensure => present,
charset => 'utf8',
require => Class['postgresql::server'],
}
postgresql::database{ 'test4':
# TODO: ensure not yet supported
#ensure => present,
charset => 'latin1',
require => Class['postgresql::server'],
}

View file

@ -1,30 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'manage_redhat_firewall' => true,
#'ip_mask_deny_postgres_user' => '0.0.0.0/32',
#'postgres_password' => 'puppet',
},
}
postgresql::db{ 'test1':
user => 'test1',
password => 'test1',
grant => 'all',
}
postgresql::db{ 'test2':
user => 'test2',
password => postgresql_password('test2', 'test2'),
grant => 'all',
}
postgresql::db{ 'test3':
user => 'test3',
# The password here is a copy/paste of the output of the 'postgresql_password'
# function from this module, with a u/p of 'test3', 'test3'.
password => 'md5e12234d4575a12bfd61d61294f32b086',
grant => 'all',
}

View file

@ -1,14 +0,0 @@
# TODO: in mysql module, the grant resource name might look like this: 'user@host/dbname';
# I think that the API for the resource type should split these up, because it's
# easier / safer to recombine them for mysql than it is to parse them for other
# databases. Also, in the mysql module, the hostname portion of that string
# affects the user's ability to connect from remote hosts. In postgres this is
# managed via pg_hba.conf; not sure if we want to try to reconcile that difference
# in the modules or not.
postgresql::database_grant{'test1':
# TODO: mysql supports an array of privileges here. We should do that if we
# port this to ruby.
privilege => 'ALL',
db => 'test1',
role => 'dan',
}

View file

@ -1,18 +0,0 @@
# Basic remote access
postgresql::pg_hba_rule{ 'allow access to db foo from 2.2.2.0/24 for user foo':
type => 'host',
database => 'foo',
user => 'foo',
address => '2.2.2.0/24',
auth_method => 'md5',
}
# LDAP Integration
postgresql::pg_hba_rule{ 'allow ldap access to db foo from 10.1.1.0/24 for all':
type => 'host',
database => 'foo',
user => 'all',
address => '10.1.1.0/24',
auth_method => 'ldap',
auth_option => 'ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"',
}

View file

@ -1,19 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'manage_redhat_firewall' => true,
'postgres_password' => 'postgres',
},
}
include 'postgresql::params'
$pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
file { $pg_conf_include_file:
content => 'max_connections = 123',
notify => Service['postgresqld'],
}

View file

@ -1,73 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'manage_redhat_firewall' => true,
'postgres_password' => 'postgres',
},
}
file { '/tmp':
ensure => 'directory',
}
file { '/tmp/pg_tablespaces':
ensure => 'directory',
owner => 'postgres',
group => 'postgres',
mode => '0700',
require => File['/tmp'],
}
postgresql::tablespace{ 'tablespace1':
location => '/tmp/pg_tablespaces/space1',
require => [Class['postgresql::server'], File['/tmp/pg_tablespaces']],
}
postgresql::database{ 'tablespacedb1':
# TODO: ensure not yet supported
#ensure => present,
charset => 'utf8',
require => Class['postgresql::server'],
}
postgresql::database{ 'tablespacedb2':
# TODO: ensure not yet supported
#ensure => present,
charset => 'utf8',
tablespace => 'tablespace1',
require => Postgresql::Tablespace['tablespace1'],
}
postgresql::db{ 'tablespacedb3':
# TODO: ensure not yet supported
#ensure => present,
user => 'dbuser1',
password => 'dbuser1',
require => Class['postgresql::server'],
}
postgresql::db{ 'tablespacedb4':
# TODO: ensure not yet supported
#ensure => present,
user => 'dbuser2',
password => 'dbuser2',
tablespace => 'tablespace1',
require => Postgresql::Tablespace['tablespace1'],
}
postgresql::database_user{ 'spcuser':
# TODO: ensure is not yet supported
#ensure => present,
password_hash => postgresql_password('spcuser', 'spcuser'),
require => Class['postgresql::server'],
}
postgresql::tablespace{ 'tablespace2':
location => '/tmp/pg_tablespaces/space2',
owner => 'spcuser',
require => [Postgresql::Database_user['spcuser'], File['/tmp/pg_tablespaces']],
}
postgresql::database{ 'tablespacedb5':
# TODO: ensure not yet supported
#ensure => present,
charset => 'utf8',
tablespace => 'tablespace2',
require => Postgresql::Tablespace['tablespace2'],
}

View file

@ -1,28 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'manage_redhat_firewall' => true,
'postgres_password' => 'postgres',
},
}
# TODO: in mysql module, the username includes, e.g., '@%' or '@localhost', which
# affects the user's ability to connect from remote hosts. In postgres this is
# managed via pg_hba.conf; not sure if we want to try to reconcile that difference
# in the modules or not.
postgresql::database_user{ 'redmine':
# TODO: ensure is not yet supported
#ensure => present,
password_hash => postgresql_password('redmine', 'redmine'),
require => Class['postgresql::server'],
}
postgresql::database_user{ 'dan':
# TODO: ensure is not yet supported
#ensure => present,
password_hash => postgresql_password('dan', 'blah'),
require => Class['postgresql::server'],
}

View file

@ -1,10 +0,0 @@
class { 'postgresql::server':
config_hash => {
'ip_mask_deny_postgres_user' => '0.0.0.0/32',
'ip_mask_allow_all_users' => '0.0.0.0/0',
'listen_addresses' => '*',
'ipv4acls' => ['hostssl all johndoe 192.168.0.0/24 cert'],
'manage_redhat_firewall' => true,
'postgres_password' => 'postgres',
},
}

View file

@ -1,6 +1,8 @@
# Class for setting cross-class global overrides. See README.md for more
# details.
class postgresql::globals (
$ensure = undef,
$client_package_name = undef,
$server_package_name = undef,
$contrib_package_name = undef,

View file

@ -1,5 +1,6 @@
# PRIVATE CLASS: do not use directly
class postgresql::params inherits postgresql::globals {
$ensure = true
$version = $globals_version
$listen_addresses = 'localhost'
$ip_mask_deny_postgres_user = '0.0.0.0/0'

View file

@ -1,6 +1,6 @@
# PRIVATE CLASS: do not use directly
class postgresql::repo (
$ensure = 'present',
$ensure = $postgresql::params::ensure,
$version = undef
) inherits postgresql::params {
case $::osfamily {

View file

@ -13,7 +13,6 @@ class postgresql::repo::apt_postgresql_org inherits postgresql::repo {
location => 'http://apt.postgresql.org/pub/repos/apt/',
release => "${::lsbdistcodename}-pgdg",
repos => 'main',
required_packages => 'pgdg-keyring',
key => 'ACCC4CF8',
key_source => 'http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc',
include_src => false,

View file

@ -1,6 +1,6 @@
# This installs a PostgreSQL server. See README.md for more details.
class postgresql::server (
$ensure = true,
$ensure = $postgresql::params::ensure,
$postgres_password = undef,
$package_name = $postgresql::params::server_package_name,

View file

@ -2,6 +2,14 @@ require 'rspec-system/spec_helper'
require 'rspec-system-puppet/helpers'
require 'tempfile'
class String
# Provide ability to remove indentation from strings, for the purpose of
# left justifying heredoc blocks.
def unindent
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
end
end
module LocalHelpers
include RSpecSystem::Util

View file

@ -9,7 +9,7 @@ describe 'postgresql::client:' do
end
it 'test loading class with no parameters' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::client': }
EOS

View file

@ -3,7 +3,7 @@ require 'spec_helper_system'
describe 'common patterns:' do
describe 'postgresql.conf include pattern' do
after :all do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': ensure => absent }
file { '/tmp/include.conf':
@ -19,7 +19,7 @@ describe 'common patterns:' do
pending('no support for include directive with centos 5/postgresql 8.1',
:if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5'))
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
$extras = "/etc/postgresql-include.conf"

View file

@ -4,7 +4,7 @@ describe 'postgresql::contrib:' do
after :all do
# Cleanup after tests have ran, remove both contrib and server as contrib
# pulls in the server based packages.
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server':
ensure => absent,
}
@ -19,13 +19,13 @@ describe 'postgresql::contrib:' do
end
it 'test loading class with no parameters' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
class { 'postgresql::contrib': }
EOS
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.exit_code.should == 2
r.refresh
r.exit_code.should == 0
end

View file

@ -9,7 +9,7 @@ describe 'postgresql::lib::devel:' do
end
it 'test loading class with no parameters' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::lib::devel': }
EOS

View file

@ -12,7 +12,7 @@ describe 'postgresql::lib::java:' do
pending('libpostgresql-java-jdbc not available natively for Ubuntu 10.04 and Debian 6',
:if => (node.facts['osfamily'] == 'Debian' and ['6', '10'].include?(node.facts['lsbmajdistrelease'])))
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::lib::java': }
EOS

View file

@ -11,7 +11,7 @@ describe 'postgresql::lib::python:' do
it 'test loading class with no parameters' do
pending('psycopg2 not available natively for centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5'))
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::lib::python': }
EOS

View file

@ -9,7 +9,7 @@ describe 'postgresql_psql:' do
end
it 'should run some SQL when the unless query returns no rows' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql_psql { 'foobar':
@ -29,7 +29,7 @@ describe 'postgresql_psql:' do
end
it 'should not run SQL when the unless query returns rows' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql_psql { 'foobar':

View file

@ -9,7 +9,7 @@ describe 'postgresql::server::config_entry:' do
end
it 'should change setting and reflect it in show all' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql::server::config_entry { 'check_function_bodies':

View file

@ -10,7 +10,7 @@ describe 'postgresql::server::database_grant:' do
it 'should grant access so a user can create objects in a database' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'postgres'
$user = 'psql_grant_tester'
$password = 'psql_grant_pw'

View file

@ -10,7 +10,7 @@ describe 'postgresql::server::database:' do
it 'should idempotently create a db that we can connect to' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'postgresql_test_db'
class { 'postgresql::server': }

View file

@ -10,7 +10,7 @@ describe 'postgresql::server::db' do
it 'should idempotently create a db that we can connect to' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'postgresql_test_db'
class { 'postgresql::server': }
@ -39,7 +39,7 @@ describe 'postgresql::server::db' do
it 'should take a locale parameter' do
pending('no support for locale parameter with centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5'))
begin
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
if($::operatingsystem == 'Debian') {
# Need to make sure the correct locale is installed first
@ -79,7 +79,7 @@ describe 'postgresql::server::db' do
it 'should take an istemplate parameter' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'template2'
class { 'postgresql::server': }
@ -112,7 +112,7 @@ describe 'postgresql::server::db' do
it 'should update istemplate parameter' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'template2'
class { 'postgresql::server': }

View file

@ -10,7 +10,7 @@ describe 'postgresql::server::grant:' do
it 'should grant access so a user can create in a database' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'postgres'
$user = 'psql_grant_tester'
$password = 'psql_grant_pw'

View file

@ -9,7 +9,7 @@ describe 'postgresql::server::pg_hba_rule:' do
end
it 'should create a ruleset in pg_hba.conf' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql::server::pg_hba_rule { "allow application network to access app database":
type => "host",
@ -34,7 +34,7 @@ describe 'postgresql::server::pg_hba_rule:' do
end
it 'should create a ruleset in pg_hba.conf that denies db access to db test1' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql::server::db { "test1":

View file

@ -3,7 +3,7 @@ require 'spec_helper_system'
describe 'server plperl:' do
after :all do
# Cleanup after tests have ran
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': ensure => absent }
class { 'postgresql::server::plperl': package_ensure => purged }
EOS
@ -15,7 +15,7 @@ describe 'server plperl:' do
it 'test loading class with no parameters' do
pending('no support for plperl with default version on centos 5',
:if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5'))
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
class { 'postgresql::server::plperl': }
EOS

View file

@ -9,7 +9,7 @@ describe 'postgresql::server::role:' do
end
it 'should idempotently create a user who can log in' do
pp = <<-EOS
pp = <<-EOS.unindent
$user = "postgresql_test_user"
$password = "postgresql_test_password"
@ -40,7 +40,7 @@ describe 'postgresql::server::role:' do
end
it 'should idempotently alter a user who can log in' do
pp = <<-EOS
pp = <<-EOS.unindent
$user = "postgresql_test_user"
$password = "postgresql_test_password2"
@ -71,7 +71,7 @@ describe 'postgresql::server::role:' do
end
it 'should idempotently create a user with a cleartext password' do
pp = <<-EOS
pp = <<-EOS.unindent
$user = "postgresql_test_user2"
$password = "postgresql_test_password2"

View file

@ -10,7 +10,7 @@ describe 'postgresql::server::table_grant:' do
it 'should grant access so a user can insert in a table' do
begin
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'table_grant'
$user = 'psql_table_tester'
$password = 'psql_table_pw'
@ -51,13 +51,13 @@ describe 'postgresql::server::table_grant:' do
end
## Check that the user can create a table in the database
#psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
# r.stdout.should =~ /CREATE TABLE/
# r.stderr.should be_empty
# r.exit_code.should == 0
#end
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
r.stdout.should =~ /CREATE TABLE/
r.stderr.should be_empty
r.exit_code.should == 0
end
ensure
#psql('--command="drop table foo" postgres', 'psql_grant_tester')
psql('--command="drop table foo" postgres', 'psql_grant_tester')
end
end
end

View file

@ -9,7 +9,7 @@ describe 'postgresql::server::tablespace:' do
end
it 'should idempotently create tablespaces and databases that are using them' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
file { '/tmp/pg_tablespaces':

View file

@ -9,24 +9,22 @@ describe 'server:' do
end
it 'test loading class with no parameters' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server': }
EOS
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
end
puppet_apply(pp) do |r|
r.exit_code.should be_zero
r.exit_code.should == 2
r.refresh
r.exit_code.should == 0
end
end
describe 'setting postgres password' do
it 'should install and successfully adjust the password' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server':
postgres_password => 'foobarbaz',
postgres_password => 'foobarbaz',
ip_mask_deny_postgres_user => '0.0.0.0/32',
}
EOS
@ -34,14 +32,13 @@ describe 'server:' do
puppet_apply(pp) do |r|
[0,2].should include(r.exit_code)
r.stdout.should =~ /\[set_postgres_postgrespw\]\/returns: executed successfully/
end
puppet_apply(pp) do |r|
r.refresh
r.exit_code.should == 0
end
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server':
postgres_password => 'TPSR$$eports!',
postgres_password => 'TPSR$$eports!',
ip_mask_deny_postgres_user => '0.0.0.0/32',
}
EOS
@ -49,8 +46,7 @@ describe 'server:' do
puppet_apply(pp) do |r|
[0,2].should include(r.exit_code)
r.stdout.should =~ /\[set_postgres_postgrespw\]\/returns: executed successfully/
end
puppet_apply(pp) do |r|
r.refresh
r.exit_code.should == 0
end
@ -60,7 +56,7 @@ end
describe 'server without defaults:' do
before :all do
puppet_apply(<<-EOS)
puppet_apply(<<-EOS.unindent)
if($::operatingsystem =~ /Debian|Ubuntu/) {
# Need to make sure the correct utf8 locale is ready for our
# non-standard tests
@ -79,22 +75,15 @@ describe 'server without defaults:' do
after :each do
# Cleanup
psql('--command="drop database postgresql_test_db" postgres')
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::globals':
version => "9.2",
service_name => $::osfamily ? {
"RedHat" => "postgresql-9.2",
"Debian" => "postgresql",
},
ensure => absent,
manage_package_repo => true,
version => '9.3',
}
class { 'postgresql::server':
ensure => absent,
}
# Repo removal doesn't work on its own, so we do it here
class { 'postgresql::repo':
ensure => absent,
version => '9.2',
}
EOS
puppet_apply(pp) do |r|
r.exit_code.should_not == 1
@ -102,9 +91,9 @@ describe 'server without defaults:' do
end
it 'perform installation and create a db' do
pp = <<-EOS
pp = <<-EOS.unindent
class { "postgresql::globals":
version => "9.2",
version => "9.3",
manage_package_repo => true,
encoding => 'UTF8',
locale => 'en_US.UTF-8',
@ -117,19 +106,14 @@ describe 'server without defaults:' do
EOS
puppet_apply(pp) do |r|
# Currently puppetlabs/apt shows deprecated messages
#r.stderr.should be_empty
[2,6].should include(r.exit_code)
r.exit_code.should == 2
r.refresh
# Currently puppetlabs/apt shows deprecated messages
#r.stderr.should be_empty
# It also returns a 4
[0,4].should include(r.exit_code)
r.exit_code.should == 0
end
psql('postgresql_test_db --command="select datname from pg_database limit 1"')
psql('postgresql_test_db --command="select datname from pg_database limit 1"') do |r|
r.exit_code.should == 0
end
end
end
@ -144,7 +128,7 @@ describe 'server without defaults:' do
end
it 'perform installation with different locale and encoding' do
pp = <<-EOS
pp = <<-EOS.unindent
class { 'postgresql::server':
locale => 'en_NG',
encoding => 'UTF8',
@ -152,15 +136,9 @@ describe 'server without defaults:' do
EOS
puppet_apply(pp) do |r|
# Currently puppetlabs/apt shows deprecated messages
# It also returns a 6
[2,6].should include(r.exit_code)
r.exit_code.should == 2
r.refresh
# Currently puppetlabs/apt shows deprecated messages
# It also returns a 2
[0,4].should include(r.exit_code)
r.exit_code.should == 0
end
# Remove db first, if it exists for some reason
@ -189,7 +167,7 @@ describe 'server with firewall:' do
context 'test installing postgresql with firewall management on' do
it 'perform installation and make sure it is idempotent' do
pending('no support for firewall with fedora', :if => (node.facts['operatingsystem'] == 'Fedora'))
pp = <<-EOS
pp = <<-EOS.unindent
class { 'firewall': }
class { "postgresql::server":
manage_firewall => true,

View file

@ -3,7 +3,7 @@ require 'spec_helper_system'
describe 'postgresql::validate_db_connection:' do
before :all do
# Setup postgresql server and a sample database for tests to use.
pp = <<-EOS
pp = <<-EOS.unindent
$db = 'foo'
class { 'postgresql::server': }
@ -26,7 +26,7 @@ describe 'postgresql::validate_db_connection:' do
end
it 'should run puppet with no changes declared if db ip connectivity works' do
pp = <<-EOS
pp = <<-EOS.unindent
postgresql::validate_db_connection { 'foo':
database_host => 'localhost',
database_name => 'foo',
@ -41,7 +41,7 @@ describe 'postgresql::validate_db_connection:' do
end
it 'should fail catalogue if database connectivity fails' do
pp = <<-EOS
pp = <<-EOS.unindent
postgresql::validate_db_connection { 'foobarbaz':
database_host => 'localhost',
database_name => 'foobarbaz',