puppet-openstacklib/spec/defines/openstacklib_policy_spec.rb
Takashi Kajinami 2a53c66ed3 Re-implement openstacklib::policy
openstacklib::policy has never been used in any other modules because
it was implemented as a class not reusable for each service.
This change re-implements openstacklib::policy as a defined resource
type so that we can use this implementation from each puppet modules.

The openstacklib::policy resource type provides the purge_config
parameter. When this parameter is set to true, a policy file is cleared
during configuration process. This allows users to remove any existing
rules before applying their own (no) rules.

Change-Id: I9bb486c9191c50c11717dcb9c6af00d17c3aa8f5
2021-08-10 10:25:12 +09:00

97 lines
2.3 KiB
Ruby

require 'spec_helper'
describe 'openstacklib::policy' do
shared_examples 'openstacklib::policy' do
context 'with basic configuration' do
let :title do
'/etc/nova/policy.json'
end
let :params do
{
:policies => {
'foo' => {
'key' => 'context_is_admin',
'value' => 'foo:bar'
}
},
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'baa',
:file_format => 'json',
}
end
it { should contain_openstacklib__policy__base('foo').with(
:file_path => '/etc/nova/policy.json',
:key => 'context_is_admin',
:value => 'foo:bar'
)}
end
context 'with yaml configuration' do
let :title do
'/etc/nova/policy.yaml'
end
let :params do
{
:policies => {
'foo' => {
'key' => 'context_is_admin',
'value' => 'foo:bar'
}
},
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'baa',
:file_format => 'yaml',
}
end
it { should contain_openstacklib__policy__base('foo').with(
:file_path => '/etc/nova/policy.yaml',
:key => 'context_is_admin',
:value => 'foo:bar'
)}
end
context 'with empty policies and purge_config enabled' do
let :title do
'/etc/nova/policy.yaml'
end
let :params do
{
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'baa',
:file_format => 'yaml',
:purge_config => true,
}
end
it { should contain_openstacklib__policy__default('/etc/nova/policy.yaml').with(
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'baa',
:file_format => 'yaml',
:purge_config => true,
)}
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_behaves_like 'openstacklib::policy'
end
end
end