Cleanup spec testing

Change-Id: I3c13fc2f8bc3582fd72206b3c711ff5863943b09
This commit is contained in:
Tobias Urdin
2018-11-01 16:08:00 +01:00
parent 20ac1f925a
commit 4d08ab70cb
10 changed files with 267 additions and 261 deletions

View File

@@ -1,33 +1,30 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::openstackclient' do describe 'openstacklib::openstackclient' do
shared_examples_for 'openstacklib::openstackclient' do shared_examples_for 'openstacklib::openstackclient' do
context 'with default params' do context 'with default params' do
it 'installs openstackclient' do it { should contain_package(platform_params[:openstackclient_package_name]).with(
is_expected.to contain_package(platform_params[:openstackclient_package_name]).with( :ensure => 'present',
:ensure => 'present', :tag => 'openstack'
:tag => 'openstack' )}
)
end
end end
context 'with non default package name' do context 'with non default package name' do
let :params do let :params do
{ :package_name => 'my-openstackclient' } {
:package_name => 'my-openstackclient'
}
end end
it 'installs my-openstackclient' do it { should contain_package('my-openstackclient').with(
is_expected.to contain_package('my-openstackclient').with( :ensure => 'present',
:ensure => 'present', :tag => 'openstack'
:tag => 'openstack' )}
)
end
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do

View File

@@ -1,8 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::policy' do describe 'openstacklib::policy' do
shared_examples 'openstacklib::policy' do
shared_examples_for 'openstacklib::policy' do
context 'with basic configuration' do context 'with basic configuration' do
let :params do let :params do
{ {
@@ -16,25 +15,23 @@ describe 'openstacklib::policy' do
} }
end end
it 'configures the proper policy' do it { should contain_openstacklib__policy__base('foo').with(
is_expected.to contain_openstacklib__policy__base('foo').with( :file_path => '/etc/nova/policy.json',
:file_path => '/etc/nova/policy.json', :key => 'context_is_admin',
:key => 'context_is_admin', :value => 'foo:bar'
:value => 'foo:bar' )}
)
end
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::policy' it_behaves_like 'openstacklib::policy'
end end
end end

View File

@@ -20,11 +20,12 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::policyrcd' do describe 'openstacklib::policyrcd' do
shared_examples 'openstacklib::policyrcd on Debian platforms' do
shared_examples_for 'openstacklib::policyrcd on Debian platforms' do context 'with single service' do
context "with single service" do
let :params do let :params do
{ :services => ['keystone'] } {
:services => ['keystone']
}
end end
let(:contents) { let(:contents) {
@@ -40,14 +41,14 @@ fi
eof eof
} }
it 'creates policy-rc.d file' do it { should contain_file('/usr/sbin/policy-rc.d').with_content(contents) }
is_expected.to contain_file('/usr/sbin/policy-rc.d').with_content(contents)
end
end end
context "with multiple services" do context 'with multiple services' do
let :params do let :params do
{ :services => ['keystone', 'nova'] } {
:services => ['keystone', 'nova']
}
end end
let(:contents) { let(:contents) {
@@ -68,35 +69,31 @@ fi
eof eof
} }
it 'creates policy-rc.d file' do it { should contain_file('/usr/sbin/policy-rc.d').with_content(contents) }
is_expected.to contain_file('/usr/sbin/policy-rc.d').with_content(contents)
end
end end
end end
shared_examples_for 'openstacklib::policyrcd on RedHat platforms' do shared_examples 'openstacklib::policyrcd on RedHat platforms' do
describe "with single service" do context 'with single service' do
let :params do let :params do
{ :services => ['keystone'] } {
:services => ['keystone']
}
end end
it 'does not create policy-rc.d file' do it { should_not contain_file('/usr/sbin/policy-rc.d') }
is_expected.to_not contain_file('/usr/sbin/policy-rc.d')
end
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures "openstacklib::policyrcd on #{facts[:osfamily]} platforms" it_behaves_like "openstacklib::policyrcd on #{facts[:osfamily]} platforms"
end end
end end
end end

View File

@@ -1,7 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::db::mysql::host_access' do describe 'openstacklib::db::mysql::host_access' do
let :pre_condition do let :pre_condition do
"include mysql::server\n" + "include mysql::server\n" +
"openstacklib::db::mysql { 'nova':\n" + "openstacklib::db::mysql { 'nova':\n" +
@@ -9,22 +8,24 @@ describe 'openstacklib::db::mysql::host_access' do
end end
shared_examples 'openstacklib::db::mysql::host_access examples' do shared_examples 'openstacklib::db::mysql::host_access examples' do
context 'with required parameters' do context 'with required parameters' do
let (:title) { 'nova_10.0.0.1' } let (:title) { 'nova_10.0.0.1' }
let :params do let :params do
{ :user => 'foobar', {
:user => 'foobar',
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601', :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601',
:database => 'nova', :database => 'nova',
:privileges => 'ALL' } :privileges => 'ALL'
}
end end
it { is_expected.to contain_mysql_user("#{params[:user]}@10.0.0.1").with( it { should contain_mysql_user("#{params[:user]}@10.0.0.1").with(
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:tls_options => ['NONE'] :tls_options => ['NONE']
)} )}
it { is_expected.to contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with( it { should contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with(
:user => "#{params[:user]}@10.0.0.1", :user => "#{params[:user]}@10.0.0.1",
:privileges => 'ALL', :privileges => 'ALL',
:table => "#{params[:database]}.*" :table => "#{params[:database]}.*"
@@ -33,8 +34,10 @@ describe 'openstacklib::db::mysql::host_access' do
context 'with skipping user creation' do context 'with skipping user creation' do
let (:title) { 'nova_10.0.0.1' } let (:title) { 'nova_10.0.0.1' }
let :params do let :params do
{ :user => 'foobar', {
:user => 'foobar',
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601', :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601',
:database => 'nova', :database => 'nova',
:privileges => 'ALL', :privileges => 'ALL',
@@ -42,9 +45,9 @@ describe 'openstacklib::db::mysql::host_access' do
} }
end end
it { is_expected.to_not contain_mysql_user("#{params[:user]}@10.0.0.1") } it { should_not contain_mysql_user("#{params[:user]}@10.0.0.1") }
it { is_expected.to contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with( it { should contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with(
:user => "#{params[:user]}@10.0.0.1", :user => "#{params[:user]}@10.0.0.1",
:privileges => 'ALL', :privileges => 'ALL',
:table => "#{params[:database]}.*" :table => "#{params[:database]}.*"
@@ -53,8 +56,10 @@ describe 'openstacklib::db::mysql::host_access' do
context 'with skipping grant creation' do context 'with skipping grant creation' do
let (:title) { 'nova_10.0.0.1' } let (:title) { 'nova_10.0.0.1' }
let :params do let :params do
{ :user => 'foobar', {
:user => 'foobar',
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601', :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601',
:database => 'nova', :database => 'nova',
:privileges => 'ALL', :privileges => 'ALL',
@@ -62,17 +67,19 @@ describe 'openstacklib::db::mysql::host_access' do
} }
end end
it { is_expected.to contain_mysql_user("#{params[:user]}@10.0.0.1").with( it { should contain_mysql_user("#{params[:user]}@10.0.0.1").with(
:password_hash => params[:password_hash] :password_hash => params[:password_hash]
)} )}
it { is_expected.to_not contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*") } it { should_not contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*") }
end end
context 'with skipping user and grant creation' do context 'with skipping user and grant creation' do
let (:title) { 'nova_10.0.0.1' } let (:title) { 'nova_10.0.0.1' }
let :params do let :params do
{ :user => 'foobar', {
:user => 'foobar',
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601', :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601',
:database => 'nova', :database => 'nova',
:privileges => 'ALL', :privileges => 'ALL',
@@ -81,21 +88,20 @@ describe 'openstacklib::db::mysql::host_access' do
} }
end end
it { is_expected.to_not contain_mysql_user("#{params[:user]}@10.0.0.1") } it { should_not contain_mysql_user("#{params[:user]}@10.0.0.1") }
it { should_not contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*") }
it { is_expected.to_not contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*") }
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::db::mysql::host_access examples' it_behaves_like 'openstacklib::db::mysql::host_access examples'
end end
end end

View File

@@ -1,7 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::db::mysql' do describe 'openstacklib::db::mysql' do
let :pre_condition do let :pre_condition do
'include mysql::server' 'include mysql::server'
end end
@@ -9,21 +8,23 @@ describe 'openstacklib::db::mysql' do
let (:title) { 'nova' } let (:title) { 'nova' }
let :required_params do let :required_params do
{ :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' } {
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601'
}
end end
shared_examples 'openstacklib::db::mysql examples' do shared_examples 'openstacklib::db::mysql examples' do
context 'with only required parameters' do context 'with only required parameters' do
let :params do let :params do
required_params required_params
end end
it { is_expected.to contain_mysql_database(title).with( it { should contain_mysql_database(title).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:database => title, :database => title,
:privileges => 'ALL', :privileges => 'ALL',
@@ -33,93 +34,100 @@ describe 'openstacklib::db::mysql' do
context 'with overriding dbname parameter' do context 'with overriding dbname parameter' do
let :params do let :params do
{ :dbname => 'foobar' }.merge(required_params) required_params.merge!( :dbname => 'foobar' )
end end
it { is_expected.to contain_mysql_database(params[:dbname]).with( it { should contain_mysql_database(params[:dbname]).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
it { should contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
:user => title, :user => title,
:database => params[:dbname], :database => params[:dbname],
:privileges => 'ALL', :privileges => 'ALL',
:create_user => true, :create_user => true,
:create_grant => true, :create_grant => true,
:tls_options => ['NONE'], :tls_options => ['NONE'],
)} )}
end end
context 'with overriding user parameter' do context 'with overriding user parameter' do
let :params do let :params do
{ :user => 'foobar' }.merge(required_params) required_params.merge!( :user => 'foobar' )
end end
it { is_expected.to contain_mysql_database(title).with( it { should contain_mysql_database(title).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => params[:user], :user => params[:user],
:database => title, :database => title,
:privileges => 'ALL', :privileges => 'ALL',
:create_user => true, :create_user => true,
:create_grant => true, :create_grant => true,
:tls_options => ['NONE'], :tls_options => ['NONE'],
)} )}
end end
context 'when overriding charset parameter' do context 'when overriding charset parameter' do
let :params do let :params do
{ :charset => 'latin1' }.merge(required_params) required_params.merge!( :charset => 'latin1' )
end end
it { is_expected.to contain_mysql_database(title).with_charset(params[:charset]) } it { should contain_mysql_database(title).with_charset(params[:charset]) }
end end
context 'when omitting the required parameter password_hash' do context 'when omitting the required parameter password_hash' do
let :params do let :params do
required_params.delete(:password_hash) {}
end end
it { expect { is_expected.to raise_error(Puppet::Error) } }
it { should raise_error(Puppet::Error) }
end end
context 'when notifying other resources' do context 'when notifying other resources' do
let :pre_condition do let :pre_condition do
'exec {"nova-db-sync":}' 'exec {"nova-db-sync":}'
end end
let :params do let :params do
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params) required_params.merge!( :notify => 'Exec[nova-db-sync]' )
end end
it { is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") } it { should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") }
end end
context 'when required for other openstack services' do context 'when required for other openstack services' do
let :pre_condition do let :pre_condition do
'service {"keystone":}' 'service {"keystone":}'
end end
let :title do let :title do
'keystone' 'keystone'
end end
let :params do let :params do
{ :before => 'Service[keystone]'}.merge(required_params) required_params.merge!( :before => 'Service[keystone]' )
end end
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") } it { should contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") }
end end
context "overriding allowed_hosts parameter with array value" do context "overriding allowed_hosts parameter with array value" do
let :params do let :params do
{ :allowed_hosts => ['127.0.0.1','%'] }.merge(required_params) required_params.merge!( :allowed_hosts => ['127.0.0.1', '%'] )
end end
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with( it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:database => title :database => title
)} )}
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_%").with(
it { should contain_openstacklib__db__mysql__host_access("#{title}_%").with(
:user => title, :user => title,
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:database => title :database => title
@@ -128,10 +136,10 @@ describe 'openstacklib::db::mysql' do
context "overriding allowed_hosts parameter with string value" do context "overriding allowed_hosts parameter with string value" do
let :params do let :params do
{ :allowed_hosts => '192.168.1.1' }.merge(required_params) required_params.merge!( :allowed_hosts => '192.168.1.1' )
end end
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with( it { should contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with(
:user => title, :user => title,
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:database => title :database => title
@@ -140,10 +148,10 @@ describe 'openstacklib::db::mysql' do
context "overriding allowed_hosts parameter equals to host param " do context "overriding allowed_hosts parameter equals to host param " do
let :params do let :params do
{ :allowed_hosts => '127.0.0.1' }.merge(required_params) required_params.merge!( :allowed_hosts => '127.0.0.1' )
end end
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with( it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:database => title :database => title
@@ -152,14 +160,15 @@ describe 'openstacklib::db::mysql' do
context 'with skipping user creation' do context 'with skipping user creation' do
let :params do let :params do
{ :create_user => false }.merge(required_params) required_params.merge!( :create_user => false )
end end
it { is_expected.to contain_mysql_database(title).with( it { should contain_mysql_database(title).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:database => title, :database => title,
:privileges => 'ALL', :privileges => 'ALL',
@@ -170,14 +179,15 @@ describe 'openstacklib::db::mysql' do
context 'with skipping grant creation' do context 'with skipping grant creation' do
let :params do let :params do
{ :create_grant => false }.merge(required_params) required_params.merge!( :create_grant => false )
end end
it { is_expected.to contain_mysql_database(title).with( it { should contain_mysql_database(title).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:database => title, :database => title,
:privileges => 'ALL', :privileges => 'ALL',
@@ -188,42 +198,41 @@ describe 'openstacklib::db::mysql' do
context 'with skipping user and grant creation' do context 'with skipping user and grant creation' do
let :params do let :params do
{ :create_user => false, required_params.merge!( :create_user => false,
:create_grant => false }.merge(required_params) :create_grant => false )
end end
it { is_expected.to contain_mysql_database(title).with( it { should contain_mysql_database(title).with(
:charset => 'utf8', :charset => 'utf8',
:collate => 'utf8_general_ci' :collate => 'utf8_general_ci'
)} )}
it { is_expected.to_not contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1") }
it { should_not contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1") }
end end
context "overriding tls_options" do context 'overriding tls_options' do
let :params do let :params do
{ :tls_options => ['SSL'] }.merge(required_params) required_params.merge!( :tls_options => ['SSL'] )
end end
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with( it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title, :user => title,
:password_hash => params[:password_hash], :password_hash => params[:password_hash],
:database => title, :database => title,
:tls_options => ['SSL'], :tls_options => ['SSL'],
)} )}
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::db::mysql examples' it_behaves_like 'openstacklib::db::mysql examples'
end end
end end
end end

View File

@@ -4,7 +4,9 @@ describe 'openstacklib::db::postgresql' do
let (:title) { 'nova' } let (:title) { 'nova' }
let :required_params do let :required_params do
{ :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' } {
:password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601'
}
end end
let (:pre_condition) do let (:pre_condition) do
@@ -17,7 +19,7 @@ describe 'openstacklib::db::postgresql' do
required_params required_params
end end
it { is_expected.to contain_postgresql__server__db(title).with( it { should contain_postgresql__server__db(title).with(
:user => title, :user => title,
:password => params[:password_hash] :password => params[:password_hash]
)} )}
@@ -25,17 +27,18 @@ describe 'openstacklib::db::postgresql' do
context 'when overriding encoding' do context 'when overriding encoding' do
let :params do let :params do
{ :encoding => 'latin1' }.merge(required_params) required_params.merge!( :encoding => 'latin1' )
end end
it { is_expected.to contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
it { should contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
end end
context 'when omitting the required parameter password_hash' do context 'when omitting the required parameter password_hash' do
let :params do let :params do
required_params.delete(:password_hash) {}
end end
it { expect { is_expected.to raise_error(Puppet::Error) } } it { should raise_error(Puppet::Error) }
end end
context 'when notifying other resources' do context 'when notifying other resources' do
@@ -43,11 +46,12 @@ describe 'openstacklib::db::postgresql' do
"include ::postgresql::server "include ::postgresql::server
exec { 'nova-db-sync': }" exec { 'nova-db-sync': }"
end end
let :params do let :params do
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params) required_params.merge!( :notify => 'Exec[nova-db-sync]' )
end end
it {is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") } it { should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
end end
context 'when required for other openstack services' do context 'when required for other openstack services' do
@@ -55,27 +59,28 @@ describe 'openstacklib::db::postgresql' do
"include ::postgresql::server "include ::postgresql::server
service {'keystone':}" service {'keystone':}"
end end
let :title do let :title do
'keystone' 'keystone'
end end
let :params do let :params do
{ :before => 'Service[keystone]'}.merge(required_params) required_params.merge!( :before => 'Service[keystone]' )
end end
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") } it { should contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::db::postgresql examples' it_behaves_like 'openstacklib::db::postgresql examples'
end end
end end
end end

View File

@@ -18,28 +18,28 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::messaging::rabbitmq' do describe 'openstacklib::messaging::rabbitmq' do
let (:title) { 'nova' } let (:title) { 'nova' }
shared_examples 'openstacklib::messaging::rabbitmq examples' do shared_examples 'openstacklib::messaging::rabbitmq examples' do
let :params do let :params do
{} {}
end end
context 'with default parameters' do context 'with default parameters' do
it { is_expected.to contain_rabbitmq_user('guest').with( it { should contain_rabbitmq_user('guest').with(
:admin => false, :admin => false,
:password => 'guest', :password => 'guest',
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
it { is_expected.to contain_rabbitmq_user_permissions('guest@/').with(
it { should contain_rabbitmq_user_permissions('guest@/').with(
:configure_permission => '.*', :configure_permission => '.*',
:write_permission => '.*', :write_permission => '.*',
:read_permission => '.*', :read_permission => '.*',
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
it { is_expected.to contain_rabbitmq_vhost('/').with(
it { should contain_rabbitmq_vhost('/').with(
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
end end
@@ -57,18 +57,20 @@ describe 'openstacklib::messaging::rabbitmq' do
) )
end end
it { is_expected.to contain_rabbitmq_user('nova').with( it { should contain_rabbitmq_user('nova').with(
:admin => true, :admin => true,
:password => 'secrete', :password => 'secrete',
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
it { is_expected.to contain_rabbitmq_user_permissions('nova@/nova').with(
it { should contain_rabbitmq_user_permissions('nova@/nova').with(
:configure_permission => '.nova', :configure_permission => '.nova',
:write_permission => '.nova', :write_permission => '.nova',
:read_permission => '.nova', :read_permission => '.nova',
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
it { is_expected.to contain_rabbitmq_vhost('/nova').with(
it { should contain_rabbitmq_vhost('/nova').with(
:provider => 'rabbitmqctl', :provider => 'rabbitmqctl',
)} )}
end end
@@ -78,20 +80,19 @@ describe 'openstacklib::messaging::rabbitmq' do
params.merge!( :manage_vhost => false ) params.merge!( :manage_vhost => false )
end end
it { is_expected.not_to contain_rabbitmq_vhost('/') } it { should_not contain_rabbitmq_vhost('/') }
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::messaging::rabbitmq examples' it_behaves_like 'openstacklib::messaging::rabbitmq examples'
end end
end end

View File

@@ -1,9 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::policy::base' do describe 'openstacklib::policy::base' do
shared_examples 'openstacklib::policy::base' do
shared_examples_for 'openstacklib::policy::base' do
context 'with some basic parameters' do context 'with some basic parameters' do
let :title do let :title do
'nova-contest_is_admin' 'nova-contest_is_admin'
@@ -20,46 +18,39 @@ describe 'openstacklib::policy::base' do
} }
end end
it { it { should contain_file('/etc/nova/policy.json').with(
is_expected.to contain_file('/etc/nova/policy.json').with( :mode => '0644',
:mode => '0644', :owner => 'foo',
:owner => 'foo', :group => 'bar'
:group => 'bar') )}
}
it 'configures (modifies) the proper policy' do it { should contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with( :lens => 'Json.lns',
'lens' => 'Json.lns', :incl => '/etc/nova/policy.json',
'incl' => '/etc/nova/policy.json', :changes => 'set dict/entry[*][.="context_is_admin or owner"]/string "foo:bar"',
'changes' => 'set dict/entry[*][.="context_is_admin or owner"]/string "foo:bar"', )}
)
end
it 'configures (adds) the proper policy' do it { should contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with(
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with( :lens => 'Json.lns',
'lens' => 'Json.lns', :incl => '/etc/nova/policy.json',
'incl' => '/etc/nova/policy.json', :changes => [
'changes' => [ 'set dict/entry[last()+1] "context_is_admin or owner"',
'set dict/entry[last()+1] "context_is_admin or owner"', 'set dict/entry[last()]/string "foo:bar"'
'set dict/entry[last()]/string "foo:bar"' ],
], :onlyif => 'match dict/entry[*][.="context_is_admin or owner"] size == 0'
'onlyif' => 'match dict/entry[*][.="context_is_admin or owner"] size == 0' )}
)
end
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::policy::base' it_behaves_like 'openstacklib::policy::base'
end end
end end
end end

View File

@@ -18,21 +18,21 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::service_validation' do describe 'openstacklib::service_validation' do
let (:title) { 'nova-api' } let (:title) { 'nova-api' }
let :required_params do let :required_params do
{ :command => 'nova list' } {
:command => 'nova list'
}
end end
shared_examples 'openstacklib::service_validation examples' do shared_examples 'openstacklib::service_validation examples' do
context 'with only required parameters' do context 'with only required parameters' do
let :params do let :params do
required_params required_params
end end
it { is_expected.to contain_exec("execute #{title} validation").with( it { should contain_exec("execute #{title} validation").with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin', :path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell', :provider => 'shell',
:command => 'nova list', :command => 'nova list',
@@ -50,7 +50,7 @@ describe 'openstacklib::service_validation' do
required_params.merge!({ :unless => 'pwd' }) required_params.merge!({ :unless => 'pwd' })
end end
it { is_expected.to contain_exec("execute #{title} validation").with( it { should contain_exec("execute #{title} validation").with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin', :path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell', :provider => 'shell',
:command => 'nova list', :command => 'nova list',
@@ -67,7 +67,7 @@ describe 'openstacklib::service_validation' do
required_params.merge!({ :onlyif => 'pwd' }) required_params.merge!({ :onlyif => 'pwd' })
end end
it { is_expected.to contain_exec("execute #{title} validation").with( it { should contain_exec("execute #{title} validation").with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin', :path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell', :provider => 'shell',
:command => 'nova list', :command => 'nova list',
@@ -84,31 +84,29 @@ describe 'openstacklib::service_validation' do
required_params.merge!({ :environment => ['OS_PASSWORD=secret'] }) required_params.merge!({ :environment => ['OS_PASSWORD=secret'] })
end end
it { is_expected.to contain_exec("execute #{title} validation").with( it { should contain_exec("execute #{title} validation").with(
:environment => ['OS_PASSWORD=secret'], :environment => ['OS_PASSWORD=secret'],
)} )}
end end
context 'when omitting a required parameter command' do context 'when omitting a required parameter command' do
let :params do let :params do
required_params.delete(:command) {}
end end
it { expect { is_expected.to raise_error(Puppet::Error) } } it { should raise_error(Puppet::Error) }
end end
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'openstacklib::service_validation examples' it_behaves_like 'openstacklib::service_validation examples'
end end
end end
end end

View File

@@ -18,7 +18,6 @@
require 'spec_helper' require 'spec_helper'
describe 'openstacklib::wsgi::apache' do describe 'openstacklib::wsgi::apache' do
let (:title) { 'keystone_wsgi' } let (:title) { 'keystone_wsgi' }
let :global_facts do let :global_facts do
@@ -43,63 +42,65 @@ describe 'openstacklib::wsgi::apache' do
} }
end end
shared_examples_for 'apache serving a service with mod_wsgi' do shared_examples 'openstacklib::wsgi::apache' do
it { is_expected.to contain_service('httpd').with_name(platform_params[:httpd_service_name]) } it {
it { is_expected.to contain_class('apache') } should contain_service('httpd').with_name(platform_params[:httpd_service_name])
it { is_expected.to contain_class('apache::mod::wsgi') } should contain_class('apache')
should contain_class('apache::mod::wsgi')
}
describe 'with default parameters' do context 'with default parameters' do
it { should contain_file('/var/www/cgi-bin/keystone').with(
it { is_expected.to contain_file('/var/www/cgi-bin/keystone').with( :ensure => 'directory',
'ensure' => 'directory', :owner => 'keystone',
'owner' => 'keystone', :group => 'keystone',
'group' => 'keystone', :mode => '0755',
'mode' => '0755',
)} )}
it { is_expected.to contain_file('keystone_wsgi').with( it { should contain_file('keystone_wsgi').with(
'ensure' => 'file', :ensure => 'file',
'links' => 'follow', :links => 'follow',
'path' => '/var/www/cgi-bin/keystone/main', :path => '/var/www/cgi-bin/keystone/main',
'source' => '/usr/share/keystone/keystone.wsgi', :source => '/usr/share/keystone/keystone.wsgi',
'owner' => 'keystone', :owner => 'keystone',
'group' => 'keystone', :group => 'keystone',
'mode' => '0644', :mode => '0644',
)} )}
it { is_expected.to contain_apache__vhost('keystone_wsgi').with( it { should contain_apache__vhost('keystone_wsgi').with(
'servername' => 'some.host.tld', :servername => 'some.host.tld',
'ip' => nil, :ip => nil,
'port' => '5000', :port => '5000',
'docroot' => '/var/www/cgi-bin/keystone', :docroot => '/var/www/cgi-bin/keystone',
'docroot_owner' => 'keystone', :docroot_owner => 'keystone',
'docroot_group' => 'keystone', :docroot_group => 'keystone',
'ssl' => 'true', :ssl => 'true',
'wsgi_daemon_process' => 'keystone_wsgi', :wsgi_daemon_process => 'keystone_wsgi',
'wsgi_process_group' => 'keystone_wsgi', :wsgi_process_group => 'keystone_wsgi',
'wsgi_script_aliases' => { '/' => "/var/www/cgi-bin/keystone/main" }, :wsgi_script_aliases => { '/' => "/var/www/cgi-bin/keystone/main" },
'wsgi_daemon_process_options' => { :wsgi_daemon_process_options => {
'user' => 'keystone', 'user' => 'keystone',
'group' => 'keystone', 'group' => 'keystone',
'processes' => global_facts[:os_workers], 'processes' => global_facts[:os_workers],
'threads' => 1, 'threads' => 1,
'display-name' => 'keystone_wsgi', 'display-name' => 'keystone_wsgi',
}, },
'wsgi_application_group' => '%{GLOBAL}', :wsgi_application_group => '%{GLOBAL}',
'headers' => nil, :headers => nil,
'setenvif' => ['X-Forwarded-Proto https HTTPS=1'], :setenvif => ['X-Forwarded-Proto https HTTPS=1'],
'access_log_file' => false, :access_log_file => false,
'access_log_pipe' => false, :access_log_pipe => false,
'access_log_syslog' => false, :access_log_syslog => false,
'access_log_format' => false, :access_log_format => false,
'error_log_file' => nil, :error_log_file => nil,
'error_log_pipe' => nil, :error_log_pipe => nil,
'error_log_syslog' => nil :error_log_syslog => nil
)} )}
it { is_expected.to contain_concat("#{platform_params[:httpd_ports_file]}") }
it { should contain_concat("#{platform_params[:httpd_ports_file]}") }
end end
describe 'when overriding parameters' do context 'when overriding parameters' do
let :params do let :params do
{ {
:wsgi_script_dir => '/var/www/cgi-bin/keystone', :wsgi_script_dir => '/var/www/cgi-bin/keystone',
@@ -126,41 +127,40 @@ describe 'openstacklib::wsgi::apache' do
} }
end end
it { is_expected.to contain_apache__vhost('keystone_wsgi').with( it { should contain_apache__vhost('keystone_wsgi').with(
'servername' => 'dummy.host', :servername => 'dummy.host',
'ip' => '10.42.51.1', :ip => '10.42.51.1',
'port' => '4142', :port => '4142',
'docroot' => "/var/www/cgi-bin/keystone", :docroot => "/var/www/cgi-bin/keystone",
'ssl' => 'false', :ssl => 'false',
'wsgi_daemon_process' => 'keystone_wsgi', :wsgi_daemon_process => 'keystone_wsgi',
'wsgi_daemon_process_options' => { :wsgi_daemon_process_options => {
'user' => 'keystone', 'user' => 'keystone',
'group' => 'keystone', 'group' => 'keystone',
'processes' => '37', 'processes' => '37',
'threads' => '1', 'threads' => '1',
'display-name' => 'keystone_wsgi', 'display-name' => 'keystone_wsgi',
}, },
'wsgi_process_group' => 'keystone_wsgi', :wsgi_process_group => 'keystone_wsgi',
'wsgi_script_aliases' => { :wsgi_script_aliases => {
'/' => '/var/www/cgi-bin/keystone/main', '/' => '/var/www/cgi-bin/keystone/main',
'/admin' => '/var/www/cgi-bin/keystone/admin', '/admin' => '/var/www/cgi-bin/keystone/admin',
}, },
'wsgi_application_group' => '%{GLOBAL}', :wsgi_application_group => '%{GLOBAL}',
'wsgi_pass_authorization' => 'On', :wsgi_pass_authorization => 'On',
'wsgi_chunked_request' => 'On', :wsgi_chunked_request => 'On',
'headers' => 'set X-Frame-Options "DENY"', :headers => 'set X-Frame-Options "DENY"',
'custom_fragment' => 'LimitRequestFieldSize 81900', :custom_fragment => 'LimitRequestFieldSize 81900',
'allow_encoded_slashes' => 'on', :allow_encoded_slashes => 'on',
'access_log_file' => '/var/log/httpd/access_log', :access_log_file => '/var/log/httpd/access_log',
'access_log_syslog' => 'syslog:local0', :access_log_syslog => 'syslog:local0',
'access_log_format' => 'some format', :access_log_format => 'some format',
'error_log_file' => '/var/log/httpd/error_log', :error_log_file => '/var/log/httpd/error_log',
'error_log_syslog' => 'syslog:local0' :error_log_syslog => 'syslog:local0'
)} )}
end end
describe 'when wsgi_daemon_process_options are overridden' do context 'when wsgi_daemon_process_options are overridden' do
let :params do let :params do
{ {
:bind_port => 5000, :bind_port => 5000,
@@ -177,8 +177,9 @@ describe 'openstacklib::wsgi::apache' do
}, },
} }
end end
it { is_expected.to contain_apache__vhost('keystone_wsgi').with(
'wsgi_daemon_process_options' => { it { should contain_apache__vhost('keystone_wsgi').with(
:wsgi_daemon_process_options => {
'user' => 'someotheruser', 'user' => 'someotheruser',
'group' => 'someothergroup', 'group' => 'someothergroup',
'processes' => global_facts[:os_workers], 'processes' => global_facts[:os_workers],
@@ -191,7 +192,7 @@ describe 'openstacklib::wsgi::apache' do
end end
on_supported_os({ on_supported_os({
:supported_os => OSDefaults.get_supported_os :supported_os => OSDefaults.get_supported_os
}).each do |os,facts| }).each do |os,facts|
context "on #{os}" do context "on #{os}" do
let (:facts) do let (:facts) do
@@ -201,15 +202,19 @@ describe 'openstacklib::wsgi::apache' do
let(:platform_params) do let(:platform_params) do
case facts[:osfamily] case facts[:osfamily]
when 'Debian' when 'Debian'
{ :httpd_service_name => 'apache2', {
:httpd_ports_file => '/etc/apache2/ports.conf', } :httpd_service_name => 'apache2',
:httpd_ports_file => '/etc/apache2/ports.conf'
}
when 'RedHat' when 'RedHat'
{ :httpd_service_name => 'httpd', {
:httpd_ports_file => '/etc/httpd/conf/ports.conf', } :httpd_service_name => 'httpd',
:httpd_ports_file => '/etc/httpd/conf/ports.conf'
}
end end
end end
it_configures 'apache serving a service with mod_wsgi'
it_behaves_like 'openstacklib::wsgi::apache'
end end
end end
end end