Added puppetlabs-firewall (required by puppetlabs-postgresql), updated the other modules.

This commit is contained in:
Ciaby 2014-07-11 14:51:15 -05:00
parent 5f4b7a3b72
commit dee66abcdd
137 changed files with 11118 additions and 419 deletions

View file

@ -0,0 +1,17 @@
require 'spec_helper_acceptance'
describe 'postgresql::lib::perl:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
after :all do
# Cleanup after tests have ran
apply_manifest("class { 'postgresql::lib::perl': package_ensure => purged }", :catch_failures => true)
end
it 'test loading class with no parameters' do
pp = <<-EOS.unindent
class { 'postgresql::lib::perl': }
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end

View file

@ -0,0 +1,9 @@
HOSTS:
ubuntu-server-1404-x64:
roles:
- master
platform: ubuntu-14.04-64
box: puppetlabs/ubuntu-14.04-64-nocm
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -23,4 +23,22 @@ describe 'postgresql::server::config_entry:', :unless => UNSUPPORTED_PLATFORMS.i
expect(r.stderr).to eq('')
end
end
it 'should correctly set a quotes-required string' do
pp = <<-EOS.unindent
class { 'postgresql::server': }
postgresql::server::config_entry { 'log_directory':
value => '/tmp/testfile',
}
EOS
apply_manifest(pp, :catch_failures => true)
psql('--command="show all" postgres') do |r|
r.stdout.should =~ /log_directory.+\/tmp\/testfile/
r.stderr.should be_empty
r.exit_code.should == 0
end
end
end

View file

@ -27,3 +27,28 @@ describe 'postgresql::server::database:', :unless => UNSUPPORTED_PLATFORMS.inclu
end
end
end
describe 'postgresql::server::database: alternate port', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'should idempotently create a db on a non-default port that we can connect to' do
begin
pp = <<-EOS.unindent
$db = 'postgresql_test_db'
class { 'postgresql::server':
port => 5433,
}
postgresql::server::database { $db: }
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
psql('--command="select datname from pg_database" --port=5433 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" --port=5433 postgres')
end
end
end

View file

@ -135,4 +135,30 @@ describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fac
psql('--command="drop database postgresql_test_db" postgres')
end
end
it 'should take a dbname parameter' do
begin
pp = <<-EOS.unindent
$db = 'postgresql_test_db'
$dbname = 'postgresql_testtest_db'
class { 'postgresql::server': }
postgresql::server::db { $db:
dbname => $dbname,
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_testtest_db') do |r|
expect(r.stdout).to match(/postgresql_testtest_db/)
expect(r.stderr).to eq('')
end
ensure
psql('--command="drop database postgresql_testtest_db" postgres')
end
end
end

View file

@ -85,4 +85,32 @@ describe 'postgresql::server::role:', :unless => UNSUPPORTED_PLATFORMS.include?(
expect(r.stderr).to eq('')
end
end
it 'should idempotently create a user with noinherit' do
pp = <<-EOS.unindent
$user = "postgresql_test_noinherit"
$password = "postgresql_test_noinherit"
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,
inherit => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
# Check that the user has noinherit set
psql('--command="select rolname from pg_roles where not rolinherit" postgres', 'postgresql_test_noinherit') do |r|
expect(r.stdout).to match(/postgresql_test_noinherit/)
expect(r.stderr).to eq('')
end
end
end

View file

@ -1,9 +1,38 @@
require 'spec_helper_acceptance'
# Hack around the fact that so far only Ubuntu 14.04 seems to have moved this
# file. Can revisit if everyone else gets clever.
case fact('operatingsystem')
when 'Ubuntu'
case fact('operatingsystemrelease')
when '14.04'
pghba_file = '/etc/postgresql/9.3/main/pg_hba.conf'
when '12.04'
pghba_file = '/etc/postgresql/9.1/main/pg_hba.conf'
end
when 'Debian'
case fact('operatingsystemmajrelease')
when '7'
pghba_file = '/etc/postgresql/9.1/main/pg_hba.conf'
when '6'
pghba_file = '/etc/postgresql/8.4/main/pg_hba.conf'
end
else
pghba_file = '/var/lib/pgsql/data/pg_hba.conf'
end
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)
pp = <<-EOS.unindent
class { 'postgresql::server': ensure => absent } ->
class { 'postgresql::client': package_ensure => absent }
EOS
apply_manifest(pp, :catch_failures => true)
if fact('osfamily') == 'RedHat'
shell('rpm -qa | grep postgres | xargs rpm -e')
end
end
it 'test loading class with no parameters' do
@ -19,6 +48,13 @@ describe 'server:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))
it { should be_listening }
end
describe file(pghba_file) do
it { should be_file }
it { should be_owned_by 'postgres' }
it { should be_grouped_into 'postgres' }
it { should be_mode 640 }
end
describe 'setting postgres password' do
it 'should install and successfully adjust the password' do
pp = <<-EOS.unindent
@ -64,15 +100,20 @@ describe 'server without defaults:', :unless => UNSUPPORTED_PLATFORMS.include?(f
}
}
class { 'postgresql::globals':
ensure => absent,
manage_package_repo => true,
version => '9.3',
}
class { 'postgresql::server':
ensure => absent,
} ->
class { 'postgresql::client':
package_ensure => absent,
}
EOS
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq('')
apply_manifest(pp, :catch_failures => true)
if fact('osfamily') == 'RedHat'
shell('rpm -qa | grep postgres | xargs rpm -e')
end
end
it 'perform installation and create a db' do
@ -92,12 +133,11 @@ describe 'server without defaults:', :unless => UNSUPPORTED_PLATFORMS.include?(f
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('')
# Yum cache for yum.postgresql.org is outdated
shell('yum clean all') if fact('osfamily') == 'RedHat'
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
shell('test -d /tmp/pg_xlogs') do |r|
@ -113,11 +153,38 @@ describe 'server without defaults:', :unless => UNSUPPORTED_PLATFORMS.include?(f
end
end
context 'test deprecating non-default version of postgresql to postgresql::server' do
after :all do
pp = <<-EOS.unindent
class { 'postgresql::globals':
version => '9.3',
}
class { 'postgresql::server':
ensure => absent,
} ->
class { 'postgresql::client':
package_ensure => absent,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'raises a warning' do
pp = <<-EOS.unindent
class { 'postgresql::server':
ensure => absent,
version => '9.3',
}
EOS
expect(apply_manifest(pp, :catch_failures => false).stderr).to match(/Passing "version" to postgresql::server is deprecated/i)
end
end
unless ((fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5') ||
fact('osfamily') == 'Debian')
context 'override locale and encoding' do
after :each do
before :each do
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
end
@ -162,6 +229,9 @@ describe 'server with firewall:', :unless => UNSUPPORTED_PLATFORMS.include?(fact
}
EOS
if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '5'
shell('iptables -F')
end
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
@ -186,3 +256,48 @@ describe 'server without pg_hba.conf:', :unless => UNSUPPORTED_PLATFORMS.include
end
end
end
describe 'server on alternate port:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
after :all do
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
end
it 'sets up selinux' do
pp = <<-EOS
if $::osfamily == 'RedHat' and $::selinux == 'true' {
$semanage_package = $::operatingsystemmajrelease ? {
'5' => 'policycoreutils',
default => 'policycoreutils-python',
}
package { $semanage_package: ensure => installed }
exec { 'set_postgres':
command => 'semanage port -a -t postgresql_port_t -p tcp 5433',
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
subscribe => Package[$semanage_package],
refreshonly => true,
}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
context 'test installing postgresql with alternate port' do
it 'perform installation and make sure it is idempotent' do
pp = <<-EOS.unindent
class { "postgresql::server":
port => 5433,
}
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe port(5433) do
it { should be_listening }
end
end
end

View file

@ -5,12 +5,12 @@ describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.incl
pp = <<-EOS
class { 'postgresql::client': }
EOS
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not provide defaults for osfamily/i)
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/No preferred version defined or automatically detected/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)
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/No preferred version defined or automatically detected/i)
end
end

View file

@ -32,12 +32,22 @@ describe 'postgresql::validate_db_connection:', :unless => UNSUPPORTED_PLATFORMS
apply_manifest(pp, :catch_failures => true)
end
it 'stops postgresql' do
# First we stop postgresql.
pp = <<-EOS
class { 'postgresql::server':
service_ensure => 'stopped',
}
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 &')
if fact('operatingsystem') == 'RedHat' && fact('operatingsystemrelease') =~ /^7/
shell('nohup bash -c "sleep 10; systemctl start `basename /usr/lib/systemd/system/postgres*`" > /dev/null 2>&1 &')
else
shell('nohup bash -c "sleep 10; /etc/init.d/postgresql* start" > /dev/null 2>&1 &')
end
pp = <<-EOS.unindent
postgresql::validate_db_connection { 'foo':
@ -47,7 +57,6 @@ describe 'postgresql::validate_db_connection:', :unless => UNSUPPORTED_PLATFORMS
run_as => 'postgres',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
@ -76,4 +85,13 @@ describe 'postgresql::validate_db_connection:', :unless => UNSUPPORTED_PLATFORMS
apply_manifest(pp, :expect_failures => true)
end
it 'starts postgresql' do
pp = <<-EOS
class { 'postgresql::server':
service_ensure => 'running',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end