Improve tests with rspec-puppet-facts
This change updates the tests to use rspec-puppet-facts when doing different OS testing. Additionally as part of this change, there are improvements to the openstacklib::policycrd testing which uncovered issues with the verify_contents catalog test. The verify_contents calls have been replaced with heredocs to better test when multiple services are excluded. Change-Id: I86bae2b16026e15b6e4445f3749419b8802bc94d
This commit is contained in:
parent
a5f39c6233
commit
525d77195e
spec
classes
defines
@ -1 +0,0 @@
|
||||
require 'spec_helper'
|
@ -2,24 +2,40 @@ require 'spec_helper'
|
||||
|
||||
describe 'openstacklib::policy' do
|
||||
|
||||
let :params do
|
||||
{
|
||||
:policies => {
|
||||
'foo' => {
|
||||
'file_path' => '/etc/nova/policy.json',
|
||||
'key' => 'context_is_admin',
|
||||
'value' => 'foo:bar'
|
||||
shared_examples_for 'openstacklib::policy' do
|
||||
context 'with basic configuration' do
|
||||
let :params do
|
||||
{
|
||||
:policies => {
|
||||
'foo' => {
|
||||
'file_path' => '/etc/nova/policy.json',
|
||||
'key' => 'context_is_admin',
|
||||
'value' => 'foo:bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it 'configures the proper policy' do
|
||||
is_expected.to contain_openstacklib__policy__base('foo').with(
|
||||
:file_path => '/etc/nova/policy.json',
|
||||
:key => 'context_is_admin',
|
||||
:value => 'foo:bar'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'configures the proper policy' do
|
||||
is_expected.to contain_openstacklib__policy__base('foo').with(
|
||||
:file_path => '/etc/nova/policy.json',
|
||||
:key => 'context_is_admin',
|
||||
:value => 'foo:bar'
|
||||
)
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_configures 'openstacklib::policy'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,37 +21,82 @@ require 'spec_helper'
|
||||
|
||||
describe 'openstacklib::policyrcd' do
|
||||
|
||||
let :params do
|
||||
{ :services => ['keystone']
|
||||
}
|
||||
end
|
||||
shared_examples_for 'openstacklib::policyrcd on Debian platforms' do
|
||||
context "with single service" do
|
||||
let :params do
|
||||
{ :services => ['keystone'] }
|
||||
end
|
||||
|
||||
let :test_facts do
|
||||
{ :operatingsystem => 'default',
|
||||
:operatingsystemrelease => 'default'
|
||||
}
|
||||
end
|
||||
let(:contents) {
|
||||
<<-eof
|
||||
#!/bin/bash
|
||||
|
||||
context 'on Debian platform' do
|
||||
if [ "$1" == "keystone" ]
|
||||
then
|
||||
exit 101
|
||||
fi
|
||||
|
||||
let :facts do
|
||||
@default_facts.merge(test_facts.merge(
|
||||
{ :osfamily => 'Debian' }
|
||||
))
|
||||
end
|
||||
|
||||
describe "with default value" do
|
||||
eof
|
||||
}
|
||||
|
||||
it 'creates policy-rc.d file' do
|
||||
verify_contents(catalogue, '/usr/sbin/policy-rc.d', [
|
||||
'#!/bin/bash',
|
||||
'',
|
||||
'if [ "$1" == "keystone" ]',
|
||||
'then',
|
||||
' exit 101',
|
||||
'fi'
|
||||
])
|
||||
is_expected.to contain_file('/usr/sbin/policy-rc.d').with_content(contents)
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple services" do
|
||||
let :params do
|
||||
{ :services => ['keystone', 'nova'] }
|
||||
end
|
||||
|
||||
let(:contents) {
|
||||
<<-eof
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" == "keystone" ]
|
||||
then
|
||||
exit 101
|
||||
fi
|
||||
|
||||
if [ "$1" == "nova" ]
|
||||
then
|
||||
exit 101
|
||||
fi
|
||||
|
||||
|
||||
eof
|
||||
}
|
||||
|
||||
it 'creates policy-rc.d file' do
|
||||
is_expected.to contain_file('/usr/sbin/policy-rc.d').with_content(contents)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples_for 'openstacklib::policyrcd on RedHat platforms' do
|
||||
describe "with single service" do
|
||||
let :params do
|
||||
{ :services => ['keystone'] }
|
||||
end
|
||||
|
||||
it 'does not create policy-rc.d file' do
|
||||
is_expected.to_not contain_file('/usr/sbin/policy-rc.d')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_configures "openstacklib::policyrcd on #{facts[:osfamily]} platforms"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -32,19 +32,16 @@ describe 'openstacklib::db::mysql::host_access' do
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => "Debian" }
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::db::mysql::host_access examples'
|
||||
it_configures 'openstacklib::db::mysql::host_access examples'
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::db::mysql::host_access examples'
|
||||
end
|
||||
end
|
||||
|
@ -145,19 +145,16 @@ describe 'openstacklib::db::mysql' do
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => "Debian" }
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::db::mysql examples'
|
||||
it_configures 'openstacklib::db::mysql examples'
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::db::mysql examples'
|
||||
end
|
||||
end
|
||||
|
@ -1,29 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'openstacklib::db::postgresql' do
|
||||
password_hash = 'AA1420F182E88B9E5F874F6FBE7459291E8F4601'
|
||||
title = 'nova'
|
||||
let (:title) { title }
|
||||
let (:title) { 'nova' }
|
||||
|
||||
let :required_params do
|
||||
{ :password_hash => password_hash }
|
||||
{ :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' }
|
||||
end
|
||||
|
||||
let (:pre_condition) do
|
||||
"include ::postgresql::server"
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '7.1',
|
||||
:operatingsystemmajrelease => '7',
|
||||
:concat_basedir => '/tmp',
|
||||
}
|
||||
end
|
||||
|
||||
shared_examples 'openstacklib::db::postgresql examples' do
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
required_params
|
||||
@ -31,7 +19,7 @@ describe 'openstacklib::db::postgresql' do
|
||||
|
||||
it { is_expected.to contain_postgresql__server__db(title).with(
|
||||
:user => title,
|
||||
:password => password_hash
|
||||
:password => params[:password_hash]
|
||||
)}
|
||||
end
|
||||
|
||||
@ -76,73 +64,18 @@ describe 'openstacklib::db::postgresql' do
|
||||
|
||||
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => 'jessie',
|
||||
:operatingsystemmajrelease => '8.2',
|
||||
:concat_basedir => '/tmp',
|
||||
}
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_configures 'openstacklib::db::postgresql examples'
|
||||
end
|
||||
|
||||
context 'with only required parameters' do
|
||||
let :params do
|
||||
required_params
|
||||
end
|
||||
|
||||
it { is_expected.to 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 { is_expected.to 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 { is_expected.to raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'when notifying other resources' do
|
||||
let :pre_condition do
|
||||
"include ::postgresql::server
|
||||
exec { 'nova-db-sync': }"
|
||||
end
|
||||
let :params do
|
||||
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
|
||||
end
|
||||
|
||||
it {is_expected.to 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
|
||||
"include ::postgresql::server
|
||||
service {'keystone':}"
|
||||
end
|
||||
let :title do
|
||||
'keystone'
|
||||
end
|
||||
let :params do
|
||||
{ :before => 'Service[keystone]'}.merge(required_params)
|
||||
end
|
||||
|
||||
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -83,19 +83,16 @@ describe 'openstacklib::messaging::rabbitmq' do
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => "Debian" }
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::messaging::rabbitmq examples'
|
||||
it_configures 'openstacklib::messaging::rabbitmq examples'
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::messaging::rabbitmq examples'
|
||||
end
|
||||
end
|
||||
|
@ -2,35 +2,52 @@ require 'spec_helper'
|
||||
|
||||
describe 'openstacklib::policy::base' do
|
||||
|
||||
let :title do
|
||||
'nova-contest_is_admin'
|
||||
|
||||
shared_examples_for 'openstacklib::policy' do
|
||||
context 'with some basic parameters' do
|
||||
let :title do
|
||||
'nova-contest_is_admin'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{:file_path => '/etc/nova/policy.json',
|
||||
:key => 'context_is_admin or owner',
|
||||
:value => 'foo:bar'}
|
||||
end
|
||||
|
||||
it 'configures (modifies) the proper policy' do
|
||||
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
|
||||
'lens' => 'Json.lns',
|
||||
'incl' => '/etc/nova/policy.json',
|
||||
'changes' => 'set dict/entry[*][.="context_is_admin or owner"]/string "foo:bar"',
|
||||
'require' => 'Augeas[/etc/nova/policy.json-context_is_admin or owner-foo:bar-add]'
|
||||
)
|
||||
end
|
||||
|
||||
it 'configures (adds) the proper policy' do
|
||||
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with(
|
||||
'lens' => 'Json.lns',
|
||||
'incl' => '/etc/nova/policy.json',
|
||||
'changes' => [
|
||||
'set dict/entry[last()+1] "context_is_admin or owner"',
|
||||
'set dict/entry[last()]/string "foo:bar"'
|
||||
],
|
||||
'onlyif' => 'match dict/entry[*][.="context_is_admin or owner"] size == 0'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
let :params do
|
||||
{:file_path => '/etc/nova/policy.json',
|
||||
:key => 'context_is_admin or owner',
|
||||
:value => 'foo:bar'}
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it 'configures (modifies) the proper policy' do
|
||||
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
|
||||
'lens' => 'Json.lns',
|
||||
'incl' => '/etc/nova/policy.json',
|
||||
'changes' => 'set dict/entry[*][.="context_is_admin or owner"]/string "foo:bar"',
|
||||
'require' => 'Augeas[/etc/nova/policy.json-context_is_admin or owner-foo:bar-add]'
|
||||
)
|
||||
end
|
||||
|
||||
it 'configures (adds) the proper policy' do
|
||||
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with(
|
||||
'lens' => 'Json.lns',
|
||||
'incl' => '/etc/nova/policy.json',
|
||||
'changes' => [
|
||||
'set dict/entry[last()+1] "context_is_admin or owner"',
|
||||
'set dict/entry[last()]/string "foo:bar"'
|
||||
],
|
||||
'onlyif' => 'match dict/entry[*][.="context_is_admin or owner"] size == 0'
|
||||
)
|
||||
it_configures 'openstacklib::policy'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -102,19 +102,16 @@ describe 'openstacklib::service_validation' do
|
||||
|
||||
end
|
||||
|
||||
context 'on a Debian osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => "Debian" }
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::service_validation examples'
|
||||
it_configures 'openstacklib::service_validation examples'
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a RedHat osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
|
||||
include_examples 'openstacklib::service_validation examples'
|
||||
end
|
||||
end
|
||||
|
@ -42,7 +42,7 @@ describe 'openstacklib::wsgi::apache' do
|
||||
end
|
||||
|
||||
shared_examples_for 'apache serving a service with mod_wsgi' do
|
||||
it { is_expected.to contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) }
|
||||
it { is_expected.to contain_service('httpd').with_name(platform_params[:httpd_service_name]) }
|
||||
it { is_expected.to contain_class('apache') }
|
||||
it { is_expected.to contain_class('apache::mod::wsgi') }
|
||||
|
||||
@ -85,7 +85,7 @@ describe 'openstacklib::wsgi::apache' do
|
||||
'require' => 'File[keystone_wsgi]',
|
||||
'setenvif' => ['X-Forwarded-Proto https HTTPS=1']
|
||||
)}
|
||||
it { is_expected.to contain_concat("#{platform_parameters[:httpd_ports_file]}") }
|
||||
it { is_expected.to contain_concat("#{platform_params[:httpd_ports_file]}") }
|
||||
end
|
||||
|
||||
describe 'when overriding parameters' do
|
||||
@ -130,40 +130,26 @@ describe 'openstacklib::wsgi::apache' do
|
||||
|
||||
end
|
||||
|
||||
context 'on RedHat platforms' do
|
||||
let :facts do
|
||||
global_facts.merge({
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystemrelease => '7.0'
|
||||
})
|
||||
end
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts(global_facts))
|
||||
end
|
||||
|
||||
let :platform_parameters do
|
||||
{
|
||||
:httpd_service_name => 'httpd',
|
||||
:httpd_ports_file => '/etc/httpd/conf/ports.conf',
|
||||
}
|
||||
let(:platform_params) do
|
||||
case facts[:osfamily]
|
||||
when 'Debian'
|
||||
{ :httpd_service_name => 'apache2',
|
||||
:httpd_ports_file => '/etc/apache2/ports.conf', }
|
||||
when 'RedHat'
|
||||
{ :httpd_service_name => 'httpd',
|
||||
:httpd_ports_file => '/etc/httpd/conf/ports.conf', }
|
||||
end
|
||||
end
|
||||
it_configures 'apache serving a service with mod_wsgi'
|
||||
end
|
||||
|
||||
it_configures 'apache serving a service with mod_wsgi'
|
||||
end
|
||||
|
||||
context 'on Debian platforms' do
|
||||
let :facts do
|
||||
global_facts.merge({
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '7.0'
|
||||
})
|
||||
end
|
||||
|
||||
let :platform_parameters do
|
||||
{
|
||||
:httpd_service_name => 'apache2',
|
||||
:httpd_ports_file => '/etc/apache2/ports.conf',
|
||||
}
|
||||
end
|
||||
|
||||
it_configures 'apache serving a service with mod_wsgi'
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user