Added modules
This commit is contained in:
parent
c53c931217
commit
59ec520742
646 changed files with 35182 additions and 0 deletions
18
modules/postgresql/spec/acceptance/client_spec.rb
Normal file
18
modules/postgresql/spec/acceptance/client_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::client:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::client': package_ensure => purged }",
|
||||
:catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::client': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
47
modules/postgresql/spec/acceptance/common_patterns_spec.rb
Normal file
47
modules/postgresql/spec/acceptance/common_patterns_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'common patterns:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
describe 'postgresql.conf include pattern' do
|
||||
after :all do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': ensure => absent }
|
||||
|
||||
file { '/tmp/include.conf':
|
||||
ensure => absent
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it "should support an 'include' directive at the end of postgresql.conf" do
|
||||
pending('no support for include directive with centos 5/postgresql 8.1',
|
||||
:if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
$extras = "/etc/postgresql-include.conf"
|
||||
|
||||
file { $extras:
|
||||
content => 'max_connections = 123',
|
||||
seltype => 'postgresql_db_t',
|
||||
seluser => 'system_u',
|
||||
notify => Class['postgresql::server::service'],
|
||||
}
|
||||
|
||||
postgresql::server::config_entry { 'include':
|
||||
value => $extras,
|
||||
require => File[$extras],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="show max_connections" -t', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/123/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
modules/postgresql/spec/acceptance/contrib_spec.rb
Normal file
28
modules/postgresql/spec/acceptance/contrib_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::contrib:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran, remove both contrib and server as contrib
|
||||
# pulls in the server based packages.
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
}
|
||||
class { 'postgresql::server::contrib':
|
||||
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::contrib': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
17
modules/postgresql/spec/acceptance/lib/devel_spec.rb
Normal file
17
modules/postgresql/spec/acceptance/lib/devel_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::devel:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::devel': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::devel': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
20
modules/postgresql/spec/acceptance/lib/java_spec.rb
Normal file
20
modules/postgresql/spec/acceptance/lib/java_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::java:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::java': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('libpostgresql-java-jdbc not available natively for Ubuntu 10.04 and Debian 6',
|
||||
:if => (fact('osfamily') == 'Debian' and ['6', '10'].include?(fact('lsbmajdistrelease'))))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::java': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
19
modules/postgresql/spec/acceptance/lib/python_spec.rb
Normal file
19
modules/postgresql/spec/acceptance/lib/python_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::python:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::python': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('psycopg2 not available natively for centos 5', :if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::python': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-510-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-510-x64-virtualbox-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-510-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-59-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-59-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,12 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- dashboard
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-607-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-6-amd64
|
||||
box : debian-607-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-73-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-7-amd64
|
||||
box : debian-73-x64-virtualbox-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
10
modules/postgresql/spec/acceptance/nodesets/default.yml
Normal file
10
modules/postgresql/spec/acceptance/nodesets/default.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-10044-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-10.04-amd64
|
||||
box : ubuntu-server-10044-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
43
modules/postgresql/spec/acceptance/postgresql_psql_spec.rb
Normal file
43
modules/postgresql/spec/acceptance/postgresql_psql_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql_psql:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run some SQL when the unless query returns no rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select 1',
|
||||
unless => 'select 1 where 1=2',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should not run SQL when the unless query returns rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select * from pg_database limit 1',
|
||||
unless => 'select 1 where 1=1',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::config_entry:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should change setting and reflect it in show all' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::config_entry { 'check_function_bodies':
|
||||
value => 'off',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="show all" postgres') do |r|
|
||||
expect(r.stdout).to match(/check_function_bodies.+off/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,48 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::database_grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant access so a user can create objects in a database' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgres'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_grant_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
postgresql::server::database_grant { 'grant create test':
|
||||
privilege => 'CREATE',
|
||||
db => $db,
|
||||
role => $user,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
29
modules/postgresql/spec/acceptance/server/database_spec.rb
Normal file
29
modules/postgresql/spec/acceptance/server/database_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::database:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
138
modules/postgresql/spec/acceptance/server/db_spec.rb
Normal file
138
modules/postgresql/spec/acceptance/server/db_spec.rb
Normal file
|
@ -0,0 +1,138 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take a locale parameter' do
|
||||
pending('no support for locale parameter with centos 5', :if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
postgresql::server::db { 'test1':
|
||||
user => 'test1',
|
||||
password => postgresql_password('test1', 'test1'),
|
||||
encoding => 'UTF8',
|
||||
locale => 'en_NG.UTF-8',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('-c "show lc_ctype" test1') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
|
||||
psql('-c "show lc_collate" test1') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database test1" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take an istemplate parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'template2'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
istemplate => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" template2') do |r|
|
||||
expect(r.stdout).to match(/template2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database template2" postgres', 'postgres', [1,2]) do |r|
|
||||
expect(r.stdout).to eq('')
|
||||
expect(r.stderr).to match(/cannot drop a template database/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should update istemplate parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'template2'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
istemplate => false,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" template2') do |r|
|
||||
expect(r.stdout).to match(/template2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database template2" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take a template parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
template => 'template1',
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
49
modules/postgresql/spec/acceptance/server/grant_spec.rb
Normal file
49
modules/postgresql/spec/acceptance/server/grant_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant access so a user can create in a database' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgres'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_grant_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
postgresql::server::grant { 'grant create test':
|
||||
object_type => 'database',
|
||||
privilege => 'CREATE',
|
||||
db => $db,
|
||||
role => $user,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,72 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::pg_hba_rule:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should create a ruleset in pg_hba.conf' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
postgresql::server::pg_hba_rule { "allow application network to access app database":
|
||||
type => "host",
|
||||
database => "app",
|
||||
user => "app",
|
||||
address => "200.1.2.0/24",
|
||||
auth_method => md5,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
shell("grep '200.1.2.0/24' /etc/postgresql/*/*/pg_hba.conf || grep '200.1.2.0/24' /var/lib/pgsql/data/pg_hba.conf")
|
||||
end
|
||||
|
||||
it 'should create a ruleset in pg_hba.conf that denies db access to db test1' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { "test1":
|
||||
user => "test1",
|
||||
password => postgresql_password('test1', 'test1'),
|
||||
grant => "all",
|
||||
}
|
||||
|
||||
postgresql::server::pg_hba_rule { "allow anyone to have access to db test1":
|
||||
type => "local",
|
||||
database => "test1",
|
||||
user => "test1",
|
||||
auth_method => reject,
|
||||
order => '001',
|
||||
}
|
||||
|
||||
user { "test1":
|
||||
shell => "/bin/bash",
|
||||
managehome => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
shell('su - test1 -c \'psql -U test1 -c "\q" test1\'', :acceptable_exit_codes => [2])
|
||||
end
|
||||
|
||||
it 'should fail catalogue if postgresql::server::manage_pga_conf is disabled' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
manage_pg_hba_conf => false,
|
||||
}
|
||||
postgresql::server::pg_hba_rule { 'foo':
|
||||
type => "local",
|
||||
database => "test1",
|
||||
user => "test1",
|
||||
auth_method => reject,
|
||||
order => '001',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
end
|
25
modules/postgresql/spec/acceptance/server/plperl_spec.rb
Normal file
25
modules/postgresql/spec/acceptance/server/plperl_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'server plperl:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': ensure => absent }
|
||||
class { 'postgresql::server::plperl': package_ensure => purged }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('no support for plperl with default version on centos 5',
|
||||
:if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
class { 'postgresql::server::plperl': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
88
modules/postgresql/spec/acceptance/server/role_spec.rb
Normal file
88
modules/postgresql/spec/acceptance/server/role_spec.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::role:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a user who can log in' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user"
|
||||
$password = "postgresql_test_password"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should idempotently alter a user who can log in' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user"
|
||||
$password = "postgresql_test_password2"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should idempotently create a user with a cleartext password' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user2"
|
||||
$password = "postgresql_test_password2"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => $password,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user2') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
124
modules/postgresql/spec/acceptance/server/table_grant_spec.rb
Normal file
124
modules/postgresql/spec/acceptance/server/table_grant_spec.rb
Normal file
|
@ -0,0 +1,124 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::table_grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant all accesses to a user' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'table_grant'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_table_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
# Create a rule for the user
|
||||
postgresql::server::pg_hba_rule { "allow ${user}":
|
||||
type => 'local',
|
||||
database => $db,
|
||||
user => $user,
|
||||
auth_method => 'ident',
|
||||
order => 1,
|
||||
}
|
||||
|
||||
postgresql_psql { 'Create testing table':
|
||||
command => 'CREATE TABLE "test_table" (field integer NOT NULL)',
|
||||
db => $db,
|
||||
unless => "SELECT * FROM pg_tables WHERE tablename = 'test_table'",
|
||||
require => Postgresql::Server::Database[$db],
|
||||
}
|
||||
|
||||
postgresql::server::table_grant { 'grant insert test':
|
||||
privilege => 'ALL',
|
||||
table => 'test_table',
|
||||
db => $db,
|
||||
role => $user,
|
||||
require => Postgresql_psql['Create testing table'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
## Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should grant access so a user can insert in a table' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'table_grant'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_table_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
# Create a rule for the user
|
||||
postgresql::server::pg_hba_rule { "allow ${user}":
|
||||
type => 'local',
|
||||
database => $db,
|
||||
user => $user,
|
||||
auth_method => 'ident',
|
||||
order => 1,
|
||||
}
|
||||
|
||||
postgresql_psql { 'Create testing table':
|
||||
command => 'CREATE TABLE "test_table" (field integer NOT NULL)',
|
||||
db => $db,
|
||||
unless => "SELECT * FROM pg_tables WHERE tablename = 'test_table'",
|
||||
require => Postgresql::Server::Database[$db],
|
||||
}
|
||||
|
||||
postgresql::server::table_grant { 'grant insert test':
|
||||
privilege => 'INSERT',
|
||||
table => 'test_table',
|
||||
db => $db,
|
||||
role => $user,
|
||||
require => Postgresql_psql['Create testing table'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
## Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
67
modules/postgresql/spec/acceptance/server/tablespace_spec.rb
Normal file
67
modules/postgresql/spec/acceptance/server/tablespace_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::tablespace:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create tablespaces and databases that are using them' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
file { '/tmp/postgres/pg_tablespaces':
|
||||
ensure => 'directory',
|
||||
owner => 'postgres',
|
||||
group => 'postgres',
|
||||
mode => '0700',
|
||||
}
|
||||
|
||||
postgresql::server::tablespace { 'tablespace1':
|
||||
location => '/tmp/postgres/pg_tablespaces/space1',
|
||||
}
|
||||
postgresql::server::database { 'tablespacedb1':
|
||||
encoding => 'utf8',
|
||||
tablespace => 'tablespace1',
|
||||
}
|
||||
postgresql::server::db { 'tablespacedb2':
|
||||
user => 'dbuser2',
|
||||
password => postgresql_password('dbuser2', 'dbuser2'),
|
||||
tablespace => 'tablespace1',
|
||||
}
|
||||
|
||||
postgresql::server::role { 'spcuser':
|
||||
password_hash => postgresql_password('spcuser', 'spcuser'),
|
||||
}
|
||||
postgresql::server::tablespace { 'tablespace2':
|
||||
location => '/tmp/postgres/pg_tablespaces/space2',
|
||||
owner => 'spcuser',
|
||||
}
|
||||
postgresql::server::database { 'tablespacedb3':
|
||||
encoding => 'utf8',
|
||||
tablespace => 'tablespace2',
|
||||
}
|
||||
EOS
|
||||
|
||||
shell('mkdir -p /tmp/postgres')
|
||||
# Apply appropriate selinux labels
|
||||
if fact('osfamily') == 'RedHat'
|
||||
if shell('getenforce').stdout =~ /Enforcing/
|
||||
shell('chcon -Rv --type=postgresql_db_t /tmp/postgres')
|
||||
end
|
||||
end
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that databases use correct tablespaces
|
||||
psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb1\'"\'"') do |r|
|
||||
expect(r.stdout).to match(/tablespace1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
|
||||
psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"') do |r|
|
||||
expect(r.stdout).to match(/tablespace2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
188
modules/postgresql/spec/acceptance/server_spec.rb
Normal file
188
modules/postgresql/spec/acceptance/server_spec.rb
Normal file
|
@ -0,0 +1,188 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'server:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { should be_listening }
|
||||
end
|
||||
|
||||
describe 'setting postgres password' do
|
||||
it 'should install and successfully adjust the password' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
postgres_password => 'foobarbaz',
|
||||
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
||||
end
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
postgres_password => 'TPSR$$eports!',
|
||||
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
||||
end
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server without defaults:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
context 'test installing non-default version of postgresql' do
|
||||
after :all do
|
||||
psql('--command="drop database postgresql_test_db" postgres', 'postgres')
|
||||
pp = <<-EOS.unindent
|
||||
if $::osfamily == 'Debian' {
|
||||
class { 'apt': }
|
||||
# XXX Need to purge postgresql-common after uninstalling 9.3 because
|
||||
# it leaves the init script behind. Poor packaging.
|
||||
package { 'postgresql-common':
|
||||
ensure => purged,
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
}
|
||||
class { 'postgresql::globals':
|
||||
ensure => absent,
|
||||
manage_package_repo => true,
|
||||
version => '9.3',
|
||||
}
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq('')
|
||||
end
|
||||
|
||||
it 'perform installation and create a db' do
|
||||
pp = <<-EOS.unindent
|
||||
if $::osfamily == 'Debian' {
|
||||
class { 'apt': }
|
||||
}
|
||||
class { "postgresql::globals":
|
||||
version => "9.3",
|
||||
manage_package_repo => true,
|
||||
encoding => 'UTF8',
|
||||
locale => 'en_US.UTF-8',
|
||||
xlogdir => '/tmp/pg_xlogs',
|
||||
}
|
||||
class { "postgresql::server": }
|
||||
postgresql::server::db { "postgresql_test_db":
|
||||
user => "foo1",
|
||||
password => postgresql_password('foo1', 'foo1'),
|
||||
}
|
||||
postgresql::server::config_entry { 'port':
|
||||
value => '5432',
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq('')
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('test -d /tmp/pg_xlogs') do |r|
|
||||
expect(r.stdout).to eq('')
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
|
||||
psql('postgresql_test_db --command="select datname from pg_database limit 1"')
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { should be_listening }
|
||||
end
|
||||
end
|
||||
|
||||
unless ((fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5') ||
|
||||
fact('osfamily') == 'Debian')
|
||||
|
||||
context 'override locale and encoding' do
|
||||
after :each do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'perform installation with different locale and encoding' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
locale => 'en_NG',
|
||||
encoding => 'UTF8',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Remove db first, if it exists for some reason
|
||||
shell('su postgres -c "dropdb test1"', :acceptable_exit_codes => [0,1,2])
|
||||
shell('su postgres -c "createdb test1"')
|
||||
shell('su postgres -c \'psql -c "show lc_ctype" test1\'') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
|
||||
shell('su postgres -c \'psql -c "show lc_collate" test1\'') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server with firewall:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
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 => (fact('operatingsystem') == 'Fedora'))
|
||||
pp = <<-EOS.unindent
|
||||
class { 'firewall': }
|
||||
class { "postgresql::server":
|
||||
manage_firewall => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server without pg_hba.conf:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
context 'test installing postgresql without pg_hba.conf management on' do
|
||||
it 'perform installation and make sure it is idempotent' do
|
||||
pp = <<-EOS.unindent
|
||||
class { "postgresql::server":
|
||||
manage_pg_hba_conf => false,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
16
modules/postgresql/spec/acceptance/unsupported_spec.rb
Normal file
16
modules/postgresql/spec/acceptance/unsupported_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'should fail for client' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::client': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not provide defaults for osfamily/i)
|
||||
end
|
||||
it 'should fail for server' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not provide defaults for osfamily/i)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,79 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::validate_db_connection:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
# Setup postgresql server and a sample database for tests to use.
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'foo'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
after :all do
|
||||
# Remove postgresql server after all tests have ran.
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run puppet with no changes declared if socket connectivity works' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_name => 'foo',
|
||||
run_as => 'postgres',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should keep retrying if database is down' do
|
||||
# So first we shut the db down, then background a startup routine with a
|
||||
# sleep 10 in front of it. That way the tests should continue while
|
||||
# the pause and db startup happens in the background.
|
||||
shell("/etc/init.d/postgresql* stop")
|
||||
shell('nohup bash -c "sleep 10; /etc/init.d/postgresql* start" > /dev/null 2>&1 &')
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_name => 'foo',
|
||||
tries => 30,
|
||||
sleep => 1,
|
||||
run_as => 'postgres',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run puppet with no changes declared if db ip connectivity works' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_host => 'localhost',
|
||||
database_name => 'foo',
|
||||
database_username => 'foo',
|
||||
database_password => 'foo',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should fail catalogue if database connectivity fails' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foobarbaz':
|
||||
database_host => 'localhost',
|
||||
database_name => 'foobarbaz',
|
||||
database_username => 'foobarbaz',
|
||||
database_password => 'foobarbaz',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue