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

View file

@ -7,15 +7,13 @@ RSpec.configure do |c|
c.include PuppetlabsSpec::Files
c.before :each do
# Ensure that we don't accidentally cache facts and environment
# between test cases.
Facter::Util::Loader.any_instance.stubs(:load_all)
Facter.clear
Facter.clear_messages
# Store any environment variables away to be restored later
@old_env = {}
ENV.each_key {|k| @old_env[k] = ENV[k]}
if ENV['STRICT_VARIABLES'] == 'yes'
Puppet.settings[:strict_variables]=true
end
end
c.after :each do

View file

@ -29,18 +29,26 @@ def shellescape(str)
return str
end
def psql(psql_cmd, user = 'postgres', exit_codes = [0], &block)
def psql(psql_cmd, user = 'postgres', exit_codes = [0,1], &block)
psql = "psql #{psql_cmd}"
shell("su #{shellescape(user)} -c #{shellescape(psql)}", :acceptable_exit_codes => exit_codes, &block)
end
unless ENV['RS_PROVISION'] == 'no'
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
if hosts.first.is_pe?
install_pe
else
install_puppet
end
hosts.each do |host|
if host.is_pe?
install_pe
else
install_puppet
on host, "mkdir -p #{host['distmoduledir']}"
shell("mkdir -p #{host['distmoduledir']}")
if ! host.is_pe?
# Augeas is only used in one place, for Redhat.
if fact('osfamily') == 'RedHat'
install_package host, 'ruby-devel'
install_package host, 'augeas-devel'
install_package host, 'ruby-augeas'
end
end
end
end
@ -66,6 +74,10 @@ RSpec.configure do |c|
on host, '/usr/sbin/locale-gen'
on host, '/usr/sbin/update-locale'
end
if fact('osfamily') == 'RedHat'
shell('yum -y install policycoreutils-python')
shell('semanage port -a -t postgresql_port_t -p tcp 5433')
end
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-firewall'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }

View file

@ -7,6 +7,7 @@ describe 'postgresql::globals', :type => :class do
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:lsbdistid => 'Debian',
:lsbdistcodename => 'squeeze',
}
end

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'postgresql::lib::perl', :type => :class do
describe 'on a redhat based os' do
let :facts do {
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '6.4',
}
end
it { should contain_package('perl-DBD-Pg').with(
:name => 'perl-DBD-Pg',
:ensure => 'present'
)}
end
describe 'on a debian based os' do
let :facts do {
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
}
end
it { should contain_package('perl-DBD-Pg').with(
:name => 'libdbd-pg-perl',
:ensure => 'present'
)}
end
end

View file

@ -7,6 +7,7 @@ describe 'postgresql::repo', :type => :class do
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:lsbdistid => 'Debian',
:lsbdistcodename => 'squeeze',
}
end

View file

@ -12,6 +12,8 @@ describe 'postgresql::server::contrib', :type => :class do
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end

View file

@ -11,6 +11,9 @@ describe 'postgresql::server::initdb', :type => :class do
:operatingsystem => 'CentOS',
:operatingsystemrelease => '6.0',
:concat_basedir => tmpfilename('server'),
:kernel => 'Linux',
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
it { should contain_file('/var/lib/pgsql/data').with_ensure('directory') }
@ -20,7 +23,11 @@ describe 'postgresql::server::initdb', :type => :class do
{
:osfamily => 'RedHat',
:operatingsystem => 'Amazon',
:operatingsystemrelease => '1.0',
:concat_basedir => tmpfilename('server'),
:kernel => 'Linux',
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
it { should contain_file('/var/lib/pgsql9/data').with_ensure('directory') }

View file

@ -8,6 +8,8 @@ describe 'postgresql::server::plperl', :type => :class do
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('plperl'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end

View file

@ -0,0 +1,44 @@
require 'spec_helper'
describe 'postgresql::server::postgis', :type => :class do
let :pre_condition do
"class { 'postgresql::server': }"
end
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('postgis'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
describe 'with parameters' do
let(:params) do
{
:package_name => 'mypackage',
:package_ensure => 'absent',
}
end
it 'should create package with correct params' do
should contain_package('postgresql-postgis').with({
:ensure => 'absent',
:name => 'mypackage',
:tag => 'postgresql',
})
end
end
describe 'with no parameters' do
it 'should create package with postgresql tag' do
should contain_package('postgresql-postgis').with({
:tag => 'postgresql',
})
end
end
end

View file

@ -8,6 +8,8 @@ describe 'postgresql::server', :type => :class do
:operatingsystemrelease => '6.0',
:concat_basedir => tmpfilename('server'),
:kernel => 'Linux',
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -19,6 +21,24 @@ describe 'postgresql::server', :type => :class do
end
end
describe 'service_ensure => running' do
let(:params) {{ :service_ensure => 'running' }}
it { should contain_class("postgresql::params") }
it { should contain_class("postgresql::server") }
it 'should validate connection' do
should contain_postgresql__validate_db_connection('validate_service_is_running')
end
end
describe 'service_ensure => stopped' do
let(:params) {{ :service_ensure => 'stopped' }}
it { should contain_class("postgresql::params") }
it { should contain_class("postgresql::server") }
it 'shouldnt validate connection' do
should_not contain_postgresql__validate_db_connection('validate_service_is_running')
end
end
describe 'manage_firewall => true' do
let(:params) do
{
@ -49,7 +69,7 @@ describe 'postgresql::server', :type => :class do
it 'stop the service' do
should contain_service('postgresqld').with({
:ensure => false,
:ensure => 'stopped',
})
end
@ -81,7 +101,7 @@ describe 'postgresql::server', :type => :class do
it 'should still enable the service' do
should contain_service('postgresqld').with({
:ensure => true,
:ensure => 'running',
})
end
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::config_entry', :type => :define do
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '6.4',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -16,6 +20,10 @@ describe 'postgresql::server::config_entry', :type => :define do
end
context "syntax check" do
let :pre_condition do
"class {'postgresql::server':}"
end
let(:params) { { :ensure => 'present'} }
it { should contain_postgresql__server__config_entry('config_entry') }
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::database_grant', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -21,6 +25,10 @@ describe 'postgresql::server::database_grant', :type => :define do
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__database_grant('test') }
it { should contain_postgresql__server__grant('database:test') }
end

View file

@ -6,11 +6,20 @@ describe 'postgresql::server::database', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
let :title do
'test'
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__database('test') }
it { should contain_postgresql_psql("Check for existence of db 'test'") }
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::db', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -13,16 +17,42 @@ describe 'postgresql::server::db', :type => :define do
'test'
end
let :params do
{
:user => 'test',
:password => 'test',
:owner => 'tester',
}
context 'without dbname param' do
let :params do
{
:user => 'test',
:password => 'test',
:owner => 'tester',
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__db('test') }
it { should contain_postgresql__server__database('test').with_owner('tester') }
it { should contain_postgresql__server__role('test') }
it { should contain_postgresql__server__database_grant('GRANT test - ALL - test') }
end
it { should contain_postgresql__server__db('test') }
it { should contain_postgresql__server__database('test').with_owner('tester') }
it { should contain_postgresql__server__role('test') }
it { should contain_postgresql__server__database_grant('GRANT test - ALL - test') }
context 'dbname' do
let :params do
{
:dbname => 'testtest',
:user => 'test',
:password => 'test',
:owner => 'tester',
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__database('testtest') }
end
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::grant', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -20,5 +24,9 @@ describe 'postgresql::server::grant', :type => :define do
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__grant('test') }
end

View file

@ -6,7 +6,10 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('pg_hba'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
let :title do
@ -17,6 +20,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
end
context 'test template 1' do
let :pre_condition do
<<-EOS
class { 'postgresql::server': }
EOS
end
let :params do
{
:type => 'host',
@ -28,12 +37,19 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
}
end
it do
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
content.should =~ /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
should contain_concat__fragment('pg_hba_rule_test').with({
:content => /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
})
end
end
context 'test template 2' do
let :pre_condition do
<<-EOS
class { 'postgresql::server': }
EOS
end
let :params do
{
:type => 'local',
@ -44,12 +60,19 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
}
end
it do
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
content.should =~ /local\s+all\s+all\s+ident/
should contain_concat__fragment('pg_hba_rule_test').with({
:content => /local\s+all\s+all\s+ident/
})
end
end
context 'test template 3' do
let :pre_condition do
<<-EOS
class { 'postgresql::server': }
EOS
end
let :params do
{
:type => 'host',
@ -62,13 +85,20 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
}
end
it do
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
content.should =~ /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
should contain_concat__fragment('pg_hba_rule_test').with({
:content => /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
})
end
end
context 'validation' do
context 'validate type test 1' do
let :pre_condition do
<<-EOS
class { 'postgresql::server': }
EOS
end
let :params do
{
:type => 'invalid',
@ -86,6 +116,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
end
context 'validate auth_method' do
let :pre_condition do
<<-EOS
class { 'postgresql::server': }
EOS
end
let :params do
{
:type => 'local',
@ -152,8 +188,9 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
end
it do
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
content.should =~ /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/
should contain_concat__fragment('pg_hba_rule_test').with({
:content => /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/
})
end
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::role', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('contrib'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -19,5 +23,9 @@ describe 'postgresql::server::role', :type => :define do
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__role('test') }
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::table_grant', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('table_grant'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -22,6 +26,10 @@ describe 'postgresql::server::table_grant', :type => :define do
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__table_grant('test') }
it { should contain_postgresql__server__grant('table:test') }
end

View file

@ -6,6 +6,10 @@ describe 'postgresql::server::tablespace', :type => :define do
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:kernel => 'Linux',
:concat_basedir => tmpfilename('tablespace'),
:id => 'root',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
@ -19,5 +23,9 @@ describe 'postgresql::server::tablespace', :type => :define do
}
end
let :pre_condition do
"class {'postgresql::server':}"
end
it { should contain_postgresql__server__tablespace('test') }
end

View file

@ -9,7 +9,7 @@ describe provider_class do
conf_class = Puppet::Type.type(:postgresql_conf)
provider = conf_class.provider(:parsed)
conffile = tmpfilename('postgresql.conf')
provider.any_instance.stubs(:target).returns conffile
provider.any_instance.stub(:target).and_return conffile
provider
}

View file

@ -4,8 +4,8 @@ require 'spec_helper'
describe Puppet::Type.type(:postgresql_conf) do
before do
@provider_class = described_class.provide(:simple) { mk_resource_methods }
@provider_class.stubs(:suitable?).returns true
described_class.stubs(:defaultprovider).returns @provider_class
@provider_class.stub(:suitable?).and_return true
described_class.stub(:defaultprovider).and_return @provider_class
end
describe "namevar validation" do