
The openstacklib::db::postgresql resource is a library resource that can be used by nova, cinder, ceilometer, etc., rather than replicating equivalent functionality across all of these modules. This resource is very simple, but its addition will make maintenance and adding features much more straightforward and consistent than implementing individually across modules. openstacklib::db::postgresql uses the puppetlabs postgresql::server::db resource to configure the database and user. openstacklib::db::postgresql accepts a password_hash as a parameter and passes it to the postgresql::server::db resource as the password parameter. While this seems to conflict, the postgresql::server::db resource is actually using the password parameter as a password hash. Change-Id: I1446f37e7fba3305cff3eb3dd7ea4e7d5577eb4e Implements: blueprint commmon-openstack-database-resource
134 lines
3.3 KiB
Ruby
134 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe 'openstacklib::db::postgresql' do
|
|
password_hash = 'AA1420F182E88B9E5F874F6FBE7459291E8F4601'
|
|
title = 'nova'
|
|
let (:title) { title }
|
|
|
|
let :required_params do
|
|
{ :password_hash => password_hash }
|
|
end
|
|
|
|
context 'on a RedHat osfamily' do
|
|
let :facts do
|
|
{
|
|
:postgres_default_version => '8.4',
|
|
:osfamily => 'RedHat'
|
|
}
|
|
end
|
|
|
|
context 'with only required parameters' do
|
|
let :params do
|
|
required_params
|
|
end
|
|
|
|
it { should contain_postgresql__server__db(title).with(
|
|
:user => title,
|
|
:password => password_hash
|
|
)}
|
|
end
|
|
|
|
context 'when overriding encoding' do
|
|
let :params do
|
|
{ :encoding => 'latin1' }.merge(required_params)
|
|
end
|
|
it { should contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
|
|
end
|
|
|
|
context 'when omitting the required parameter password_hash' do
|
|
let :params do
|
|
required_params.delete(:password_hash)
|
|
end
|
|
|
|
it { expect { should raise_error(Puppet::Error) } }
|
|
end
|
|
|
|
context 'when notifying other resources' do
|
|
let :pre_condition do
|
|
'exec { "nova-db-sync": }'
|
|
end
|
|
let :params do
|
|
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
|
|
end
|
|
|
|
it {should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
|
|
end
|
|
|
|
context 'when required for other openstack services' do
|
|
let :pre_condition do
|
|
'service {"keystone":}'
|
|
end
|
|
let :title do
|
|
'keystone'
|
|
end
|
|
let :params do
|
|
{ :before => 'Service[keystone]'}.merge(required_params)
|
|
end
|
|
|
|
it { should contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
|
end
|
|
|
|
end
|
|
|
|
context 'on a Debian osfamily' do
|
|
let :facts do
|
|
{
|
|
:osfamily => 'Debian'
|
|
}
|
|
end
|
|
|
|
context 'with only required parameters' do
|
|
let :params do
|
|
required_params
|
|
end
|
|
|
|
it { should contain_postgresql__server__db(title).with(
|
|
:user => title,
|
|
:password => password_hash
|
|
)}
|
|
end
|
|
|
|
context 'when overriding encoding' do
|
|
let :params do
|
|
{ :encoding => 'latin1' }.merge(required_params)
|
|
end
|
|
it { should contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
|
|
end
|
|
|
|
context 'when omitting the required parameter password_hash' do
|
|
let :params do
|
|
required_params.delete(:password_hash)
|
|
end
|
|
|
|
it { expect { should raise_error(Puppet::Error) } }
|
|
end
|
|
|
|
context 'when notifying other resources' do
|
|
let :pre_condition do
|
|
'exec { "nova-db-sync": }'
|
|
end
|
|
let :params do
|
|
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
|
|
end
|
|
|
|
it {should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
|
|
end
|
|
|
|
context 'when required for other openstack services' do
|
|
let :pre_condition do
|
|
'service {"keystone":}'
|
|
end
|
|
let :title do
|
|
'keystone'
|
|
end
|
|
let :params do
|
|
{ :before => 'Service[keystone]'}.merge(required_params)
|
|
end
|
|
|
|
it { should contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
|
end
|
|
|
|
end
|
|
|
|
end
|