2014-01-22 01:45:58 +01:00
|
|
|
require 'spec_helper_acceptance'
|
2013-08-27 22:43:47 +02:00
|
|
|
|
|
|
|
describe 'server:' do
|
|
|
|
after :all do
|
|
|
|
# Cleanup after tests have ran
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'test loading class with no parameters' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
class { 'postgresql::server': }
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
2013-09-19 17:30:15 +02:00
|
|
|
describe port(5432) do
|
|
|
|
it { should be_listening }
|
|
|
|
end
|
|
|
|
|
2013-08-27 22:43:47 +02:00
|
|
|
describe 'setting postgres password' do
|
|
|
|
it 'should install and successfully adjust the password' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
class { 'postgresql::server':
|
2013-09-18 23:25:51 +02:00
|
|
|
postgres_password => 'foobarbaz',
|
2013-08-27 22:43:47 +02:00
|
|
|
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
|
|
|
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
class { 'postgresql::server':
|
2013-09-18 23:25:51 +02:00
|
|
|
postgres_password => 'TPSR$$eports!',
|
2013-08-27 22:43:47 +02:00
|
|
|
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
|
|
|
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'server without defaults:' do
|
|
|
|
before :all do
|
2014-01-22 01:45:58 +01:00
|
|
|
pp = <<-EOS
|
2013-08-27 22:43:47 +02:00
|
|
|
if($::operatingsystem =~ /Debian|Ubuntu/) {
|
|
|
|
# Need to make sure the correct utf8 locale is ready for our
|
|
|
|
# non-standard tests
|
|
|
|
file { '/etc/locale.gen':
|
|
|
|
content => "en_US ISO-8859-1\nen_NG UTF-8\nen_US UTF-8\n",
|
|
|
|
}~>
|
|
|
|
exec { '/usr/sbin/locale-gen':
|
|
|
|
logoutput => true,
|
|
|
|
refreshonly => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOS
|
2014-01-22 01:45:58 +01:00
|
|
|
|
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'test installing non-default version of postgresql' do
|
2013-09-20 02:17:43 +02:00
|
|
|
after :all do
|
2014-01-22 01:45:58 +01:00
|
|
|
psql('--command="drop database postgresql_test_db" postgres', 'postgres')
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
class { 'postgresql::globals':
|
2013-09-18 23:25:51 +02:00
|
|
|
ensure => absent,
|
|
|
|
manage_package_repo => true,
|
|
|
|
version => '9.3',
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
class { 'postgresql::server':
|
2013-09-18 16:06:35 +02:00
|
|
|
ensure => absent,
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
EOS
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'perform installation and create a db' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
class { "postgresql::globals":
|
2013-09-18 23:25:51 +02:00
|
|
|
version => "9.3",
|
2013-08-27 22:43:47 +02:00
|
|
|
manage_package_repo => true,
|
|
|
|
encoding => 'UTF8',
|
|
|
|
locale => 'en_US.UTF-8',
|
2013-12-13 22:41:25 +01:00
|
|
|
xlogdir => '/tmp/pg_xlogs',
|
2013-08-27 22:43:47 +02:00
|
|
|
}
|
|
|
|
class { "postgresql::server": }
|
|
|
|
postgresql::server::db { "postgresql_test_db":
|
|
|
|
user => "foo1",
|
|
|
|
password => postgresql_password('foo1', 'foo1'),
|
|
|
|
}
|
2013-09-20 02:17:43 +02:00
|
|
|
postgresql::server::config_entry { 'port':
|
|
|
|
value => '5432',
|
|
|
|
}
|
2013-08-27 22:43:47 +02:00
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
shell('test -d /tmp/pg_xlogs') do |r|
|
|
|
|
expect(r.stdout).to eq('')
|
|
|
|
expect(r.stderr).to eq('')
|
2013-12-13 22:41:25 +01:00
|
|
|
end
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
psql('postgresql_test_db --command="select datname from pg_database limit 1"')
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
2013-09-20 02:17:43 +02:00
|
|
|
|
|
|
|
describe port(5432) do
|
|
|
|
it { should be_listening }
|
|
|
|
end
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
unless ((fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5') ||
|
|
|
|
fact('osfamily') == 'Debian')
|
2013-08-27 22:43:47 +02:00
|
|
|
|
2013-09-18 16:06:35 +02:00
|
|
|
context 'override locale and encoding' do
|
|
|
|
after :each do
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
2013-09-18 16:06:35 +02:00
|
|
|
it 'perform installation with different locale and encoding' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-09-18 16:06:35 +02:00
|
|
|
class { 'postgresql::server':
|
|
|
|
locale => 'en_NG',
|
|
|
|
encoding => 'UTF8',
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-09-18 16:06:35 +02:00
|
|
|
|
|
|
|
# Remove db first, if it exists for some reason
|
2014-01-22 01:45:58 +01:00
|
|
|
shell('su postgres -c "dropdb test1"', :acceptable_exit_codes => [0,1,2])
|
2013-09-18 16:06:35 +02:00
|
|
|
shell('su postgres -c "createdb test1"')
|
|
|
|
shell('su postgres -c \'psql -c "show lc_ctype" test1\'') do |r|
|
2014-01-22 01:45:58 +01:00
|
|
|
expect(r.stdout).to match(/en_NG/)
|
2013-09-18 16:06:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
shell('su postgres -c \'psql -c "show lc_collate" test1\'') do |r|
|
2014-01-22 01:45:58 +01:00
|
|
|
expect(r.stdout).to match(/en_NG/)
|
2013-09-18 16:06:35 +02:00
|
|
|
end
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'server with firewall:' do
|
|
|
|
after :all do
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'test installing postgresql with firewall management on' do
|
|
|
|
it 'perform installation and make sure it is idempotent' do
|
2014-01-22 01:45:58 +01:00
|
|
|
pending('no support for firewall with fedora', :if => (fact('operatingsystem') == 'Fedora'))
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-09-12 15:46:11 +02:00
|
|
|
class { 'firewall': }
|
2013-08-27 22:43:47 +02:00
|
|
|
class { "postgresql::server":
|
|
|
|
manage_firewall => true,
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-02 14:43:21 +02:00
|
|
|
|
|
|
|
describe 'server without pg_hba.conf:' do
|
|
|
|
after :all do
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
2013-10-02 14:43:21 +02:00
|
|
|
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
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-10-02 14:43:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|