2014-01-22 01:45:58 +01:00
require 'spec_helper_acceptance'
2013-08-27 22:43:47 +02:00
describe 'postgresql::server::tablespace:' 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 'should idempotently create tablespaces and databases that are using them' do
2013-09-18 23:25:51 +02:00
pp = <<-EOS.unindent
2013-08-27 22:43:47 +02:00
class { 'postgresql::server' : }
2014-02-20 22:45:13 +01:00
file { '/tmp/postgres/pg_tablespaces' :
2013-08-27 22:43:47 +02:00
ensure = > 'directory' ,
owner = > 'postgres' ,
group = > 'postgres' ,
mode = > '0700' ,
}
postgresql :: server :: tablespace { 'tablespace1' :
2014-02-20 22:45:13 +01:00
location = > '/tmp/postgres/pg_tablespaces/space1' ,
2013-08-27 22:43:47 +02:00
}
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' :
2014-02-20 22:45:13 +01:00
location = > '/tmp/postgres/pg_tablespaces/space2' ,
2013-08-27 22:43:47 +02:00
owner = > 'spcuser' ,
}
postgresql :: server :: database { 'tablespacedb3' :
encoding = > 'utf8' ,
tablespace = > 'tablespace2' ,
}
EOS
2014-02-20 22:45:13 +01:00
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
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
# 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 |
2014-01-22 01:45:58 +01:00
expect ( r . stdout ) . to match ( / tablespace1 / )
expect ( r . stderr ) . to eq ( '' )
2013-08-27 22:43:47 +02:00
end
psql ( '--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"' ) do | r |
2014-01-22 01:45:58 +01:00
expect ( r . stdout ) . to match ( / tablespace2 / )
expect ( r . stderr ) . to eq ( '' )
2013-08-27 22:43:47 +02:00
end
end
end