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:
@@ -1 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
@@ -2,24 +2,40 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe 'openstacklib::policy' do
|
describe 'openstacklib::policy' do
|
||||||
|
|
||||||
let :params do
|
shared_examples_for 'openstacklib::policy' do
|
||||||
{
|
context 'with basic configuration' do
|
||||||
:policies => {
|
let :params do
|
||||||
'foo' => {
|
{
|
||||||
'file_path' => '/etc/nova/policy.json',
|
:policies => {
|
||||||
'key' => 'context_is_admin',
|
'foo' => {
|
||||||
'value' => 'foo:bar'
|
'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
|
end
|
||||||
|
|
||||||
it 'configures the proper policy' do
|
on_supported_os({
|
||||||
is_expected.to contain_openstacklib__policy__base('foo').with(
|
:supported_os => OSDefaults.get_supported_os
|
||||||
:file_path => '/etc/nova/policy.json',
|
}).each do |os,facts|
|
||||||
:key => 'context_is_admin',
|
context "on #{os}" do
|
||||||
:value => 'foo:bar'
|
let (:facts) do
|
||||||
)
|
facts.merge!(OSDefaults.get_facts())
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'openstacklib::policy'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@@ -21,37 +21,82 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe 'openstacklib::policyrcd' do
|
describe 'openstacklib::policyrcd' do
|
||||||
|
|
||||||
let :params do
|
shared_examples_for 'openstacklib::policyrcd on Debian platforms' do
|
||||||
{ :services => ['keystone']
|
context "with single service" do
|
||||||
}
|
let :params do
|
||||||
end
|
{ :services => ['keystone'] }
|
||||||
|
end
|
||||||
|
|
||||||
let :test_facts do
|
let(:contents) {
|
||||||
{ :operatingsystem => 'default',
|
<<-eof
|
||||||
:operatingsystemrelease => 'default'
|
#!/bin/bash
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
it 'creates policy-rc.d file' do
|
||||||
verify_contents(catalogue, '/usr/sbin/policy-rc.d', [
|
is_expected.to contain_file('/usr/sbin/policy-rc.d').with_content(contents)
|
||||||
'#!/bin/bash',
|
end
|
||||||
'',
|
end
|
||||||
'if [ "$1" == "keystone" ]',
|
|
||||||
'then',
|
context "with multiple services" do
|
||||||
' exit 101',
|
let :params do
|
||||||
'fi'
|
{ :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
|
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
|
end
|
||||||
|
@@ -32,19 +32,16 @@ describe 'openstacklib::db::mysql::host_access' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a Debian osfamily' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
{ :osfamily => "Debian" }
|
}).each do |os,facts|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'on a RedHat osfamily' do
|
|
||||||
let :facts do
|
|
||||||
{ :osfamily => 'RedHat' }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'openstacklib::db::mysql::host_access examples'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@@ -145,19 +145,16 @@ describe 'openstacklib::db::mysql' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a Debian osfamily' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
{ :osfamily => "Debian" }
|
}).each do |os,facts|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'on a RedHat osfamily' do
|
|
||||||
let :facts do
|
|
||||||
{ :osfamily => 'RedHat' }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'openstacklib::db::mysql examples'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@@ -1,29 +1,17 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'openstacklib::db::postgresql' do
|
describe 'openstacklib::db::postgresql' do
|
||||||
password_hash = 'AA1420F182E88B9E5F874F6FBE7459291E8F4601'
|
let (:title) { 'nova' }
|
||||||
title = 'nova'
|
|
||||||
let (:title) { title }
|
|
||||||
|
|
||||||
let :required_params do
|
let :required_params do
|
||||||
{ :password_hash => password_hash }
|
{ :password_hash => 'AA1420F182E88B9E5F874F6FBE7459291E8F4601' }
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:pre_condition) do
|
let (:pre_condition) do
|
||||||
"include ::postgresql::server"
|
"include ::postgresql::server"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a RedHat osfamily' do
|
shared_examples 'openstacklib::db::postgresql examples' do
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:osfamily => 'RedHat',
|
|
||||||
:operatingsystem => 'RedHat',
|
|
||||||
:operatingsystemrelease => '7.1',
|
|
||||||
:operatingsystemmajrelease => '7',
|
|
||||||
:concat_basedir => '/tmp',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with only required parameters' do
|
context 'with only required parameters' do
|
||||||
let :params do
|
let :params do
|
||||||
required_params
|
required_params
|
||||||
@@ -31,7 +19,7 @@ describe 'openstacklib::db::postgresql' do
|
|||||||
|
|
||||||
it { is_expected.to contain_postgresql__server__db(title).with(
|
it { is_expected.to contain_postgresql__server__db(title).with(
|
||||||
:user => title,
|
:user => title,
|
||||||
:password => password_hash
|
:password => params[:password_hash]
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,73 +64,18 @@ describe 'openstacklib::db::postgresql' do
|
|||||||
|
|
||||||
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a Debian osfamily' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
{
|
}).each do |os,facts|
|
||||||
:osfamily => 'Debian',
|
context "on #{os}" do
|
||||||
:operatingsystem => 'Debian',
|
let (:facts) do
|
||||||
:operatingsystemrelease => 'jessie',
|
facts.merge!(OSDefaults.get_facts())
|
||||||
:operatingsystemmajrelease => '8.2',
|
end
|
||||||
:concat_basedir => '/tmp',
|
|
||||||
}
|
it_configures 'openstacklib::db::postgresql examples'
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@@ -83,19 +83,16 @@ describe 'openstacklib::messaging::rabbitmq' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a Debian osfamily' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
{ :osfamily => "Debian" }
|
}).each do |os,facts|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'on a RedHat osfamily' do
|
|
||||||
let :facts do
|
|
||||||
{ :osfamily => 'RedHat' }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'openstacklib::messaging::rabbitmq examples'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@@ -2,35 +2,52 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe 'openstacklib::policy::base' do
|
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
|
end
|
||||||
|
|
||||||
let :params do
|
on_supported_os({
|
||||||
{:file_path => '/etc/nova/policy.json',
|
:supported_os => OSDefaults.get_supported_os
|
||||||
:key => 'context_is_admin or owner',
|
}).each do |os,facts|
|
||||||
:value => 'foo:bar'}
|
context "on #{os}" do
|
||||||
end
|
let (:facts) do
|
||||||
|
facts.merge!(OSDefaults.get_facts())
|
||||||
|
end
|
||||||
|
|
||||||
it 'configures (modifies) the proper policy' do
|
it_configures 'openstacklib::policy'
|
||||||
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
|
end
|
||||||
'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
|
end
|
||||||
|
@@ -102,19 +102,16 @@ describe 'openstacklib::service_validation' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on a Debian osfamily' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
{ :osfamily => "Debian" }
|
}).each do |os,facts|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'on a RedHat osfamily' do
|
|
||||||
let :facts do
|
|
||||||
{ :osfamily => 'RedHat' }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'openstacklib::service_validation examples'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@@ -42,7 +42,7 @@ describe 'openstacklib::wsgi::apache' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'apache serving a service with mod_wsgi' do
|
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') }
|
||||||
it { is_expected.to contain_class('apache::mod::wsgi') }
|
it { is_expected.to contain_class('apache::mod::wsgi') }
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ describe 'openstacklib::wsgi::apache' do
|
|||||||
'require' => 'File[keystone_wsgi]',
|
'require' => 'File[keystone_wsgi]',
|
||||||
'setenvif' => ['X-Forwarded-Proto https HTTPS=1']
|
'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
|
end
|
||||||
|
|
||||||
describe 'when overriding parameters' do
|
describe 'when overriding parameters' do
|
||||||
@@ -130,40 +130,26 @@ describe 'openstacklib::wsgi::apache' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on RedHat platforms' do
|
on_supported_os({
|
||||||
let :facts do
|
:supported_os => OSDefaults.get_supported_os
|
||||||
global_facts.merge({
|
}).each do |os,facts|
|
||||||
:osfamily => 'RedHat',
|
context "on #{os}" do
|
||||||
:operatingsystemrelease => '7.0'
|
let (:facts) do
|
||||||
})
|
facts.merge!(OSDefaults.get_facts(global_facts))
|
||||||
end
|
end
|
||||||
|
|
||||||
let :platform_parameters do
|
let(:platform_params) do
|
||||||
{
|
case facts[:osfamily]
|
||||||
:httpd_service_name => 'httpd',
|
when 'Debian'
|
||||||
:httpd_ports_file => '/etc/httpd/conf/ports.conf',
|
{ :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
|
end
|
||||||
|
|
||||||
it_configures 'apache serving a service with mod_wsgi'
|
|
||||||
end
|
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
|
end
|
||||||
|
Reference in New Issue
Block a user