2014-07-07 14:03:47 -07:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'openstacklib::db::mysql' do
|
|
|
|
|
|
|
|
let :pre_condition do
|
|
|
|
'include mysql::server'
|
|
|
|
end
|
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
let (:title) { 'nova' }
|
|
|
|
|
2014-07-07 14:03:47 -07:00
|
|
|
let :required_params do
|
2014-09-29 16:27:29 -04:00
|
|
|
{ :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' }
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
shared_examples 'openstacklib::db::mysql examples' do
|
2014-07-07 14:03:47 -07:00
|
|
|
|
|
|
|
context 'with only required parameters' do
|
|
|
|
let :params do
|
|
|
|
required_params
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_mysql_database(title).with(
|
2014-07-07 14:03:47 -07:00
|
|
|
:charset => 'utf8',
|
|
|
|
:collate => 'utf8_unicode_ci'
|
|
|
|
)}
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
|
2014-09-29 16:47:24 -04:00
|
|
|
:user => title,
|
|
|
|
:database => title,
|
|
|
|
:privileges => 'ALL'
|
2014-07-07 14:03:47 -07:00
|
|
|
)}
|
2014-09-29 16:47:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with overriding dbname parameter' do
|
|
|
|
let :params do
|
|
|
|
{ :dbname => 'foobar' }.merge(required_params)
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_mysql_database(params[:dbname]).with(
|
2014-09-29 16:47:24 -04:00
|
|
|
:charset => 'utf8',
|
|
|
|
:collate => 'utf8_unicode_ci'
|
|
|
|
)}
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
|
2014-09-29 16:47:24 -04:00
|
|
|
:user => title,
|
|
|
|
:database => params[:dbname],
|
|
|
|
:privileges => 'ALL'
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with overriding user parameter' do
|
|
|
|
let :params do
|
|
|
|
{ :user => 'foobar' }.merge(required_params)
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_mysql_database(title).with(
|
2014-09-29 16:47:24 -04:00
|
|
|
:charset => 'utf8',
|
|
|
|
:collate => 'utf8_unicode_ci'
|
|
|
|
)}
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
|
2014-09-29 16:47:24 -04:00
|
|
|
:user => params[:user],
|
|
|
|
:database => title,
|
|
|
|
:privileges => 'ALL'
|
2014-07-07 14:03:47 -07:00
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
2014-09-29 16:47:24 -04:00
|
|
|
context 'when overriding charset parameter' do
|
2014-07-07 14:03:47 -07:00
|
|
|
let :params do
|
|
|
|
{ :charset => 'latin1' }.merge(required_params)
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_mysql_database(title).with_charset(params[:charset]) }
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when omitting the required parameter password_hash' do
|
|
|
|
let :params do
|
|
|
|
required_params.delete(:password_hash)
|
|
|
|
end
|
2015-03-31 12:13:33 +02:00
|
|
|
it { expect { is_expected.to raise_error(Puppet::Error) } }
|
2014-07-07 14:03:47 -07:00
|
|
|
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
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") }
|
2014-07-07 14:03:47 -07:00
|
|
|
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
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") }
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2014-09-29 16:47:24 -04:00
|
|
|
context "overriding allowed_hosts parameter with array value" do
|
2014-07-07 14:03:47 -07:00
|
|
|
let :params do
|
|
|
|
{ :allowed_hosts => ['127.0.0.1','%'] }.merge(required_params)
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
|
2014-07-07 14:03:47 -07:00
|
|
|
:user => title,
|
2014-09-29 16:27:29 -04:00
|
|
|
:password_hash => params[:password_hash],
|
2014-07-07 14:03:47 -07:00
|
|
|
:database => title
|
|
|
|
)}
|
2015-03-31 12:13:33 +02:00
|
|
|
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_%").with(
|
2014-07-07 14:03:47 -07:00
|
|
|
:user => title,
|
2014-09-29 16:27:29 -04:00
|
|
|
:password_hash => params[:password_hash],
|
2014-07-07 14:03:47 -07:00
|
|
|
:database => title
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
2014-09-29 16:47:24 -04:00
|
|
|
context "overriding allowed_hosts parameter with string value" do
|
2014-07-07 14:03:47 -07:00
|
|
|
let :params do
|
2014-09-29 16:27:29 -04:00
|
|
|
{ :allowed_hosts => '192.168.1.1' }.merge(required_params)
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with(
|
2014-07-07 14:03:47 -07:00
|
|
|
:user => title,
|
2014-09-29 16:27:29 -04:00
|
|
|
:password_hash => params[:password_hash],
|
2014-07-07 14:03:47 -07:00
|
|
|
:database => title
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
2014-09-29 16:47:24 -04:00
|
|
|
context "overriding allowed_hosts parameter equals to host param " do
|
2014-07-07 14:03:47 -07:00
|
|
|
let :params do
|
2014-09-29 16:27:29 -04:00
|
|
|
{ :allowed_hosts => '127.0.0.1' }.merge(required_params)
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2015-03-31 12:13:33 +02:00
|
|
|
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
|
2014-07-07 14:03:47 -07:00
|
|
|
:user => title,
|
2014-09-29 16:27:29 -04:00
|
|
|
:password_hash => params[:password_hash],
|
2014-07-07 14:03:47 -07:00
|
|
|
:database => title
|
|
|
|
)}
|
|
|
|
end
|
2014-09-29 16:27:29 -04:00
|
|
|
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
context 'on a Debian osfamily' do
|
2014-07-07 14:03:47 -07:00
|
|
|
let :facts do
|
2014-09-29 16:27:29 -04:00
|
|
|
{ :osfamily => "Debian" }
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
include_examples 'openstacklib::db::mysql examples'
|
|
|
|
end
|
2014-07-07 14:03:47 -07:00
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
context 'on a RedHat osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'RedHat' }
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
|
2014-09-29 16:27:29 -04:00
|
|
|
include_examples 'openstacklib::db::mysql examples'
|
2014-07-07 14:03:47 -07:00
|
|
|
end
|
|
|
|
end
|