Update oslo::policy define

* Fix docs for parameters
* Use only one call of create_resources
* Prepare unit tests

Change-Id: I7310371b5c7e62e5038f5c172b6cbca44e4b2590
This commit is contained in:
dmburmistrov 2016-04-04 15:13:36 +03:00
parent f019bba460
commit b4c9d6a972
2 changed files with 73 additions and 6 deletions

View File

@ -8,11 +8,12 @@
# === Parameters:
#
# [*policy_file*]
# (Optional) The JSON file that defines policies.
# (Optional) The JSON file that defines policies. (string value)
# Defaults to $::os_service_default.
#
# [*policy_default_rule*]
# (Optional) Default rule. Enforced when a requested rule is not found.
# (string value)
# Defaults to $::os_service_default.
#
# [*policy_dirs*]
@ -20,7 +21,7 @@
# They can be relative to any directory in the search path defined by
# the config_dir option, or absolute paths.
# The file defined by policy_file must exist for these directories to be searched.
# Missing or empty directories are ignored.
# Missing or empty directories are ignored. (list value)
# Defaults to $::os_service_default.
#
define oslo::policy(
@ -28,8 +29,17 @@ define oslo::policy(
$policy_default_rule = $::os_service_default,
$policy_dirs = $::os_service_default,
) {
create_resources($name, {'oslo_policy/policy_file' => { value => $policy_file }})
create_resources($name, {'oslo_policy/policy_default_rule' => { value => $policy_default_rule }})
create_resources($name, {'oslo_policy/policy_dirs' => { value => $policy_dirs }})
}
if !is_service_default($policy_dirs) {
$policy_dirs_orig = join(any2array($policy_dirs), ',')
} else {
$policy_dirs_orig = $policy_dirs
}
$policy_options = {
'oslo_policy/policy_file' => { value => $policy_file },
'oslo_policy/policy_default_rule' => { value => $policy_default_rule },
'oslo_policy/policy_dirs' => { value => $policy_dirs_orig },
}
create_resources($name, $policy_options)
}

View File

@ -0,0 +1,57 @@
require 'spec_helper'
describe 'oslo::policy' do
let (:title) { 'keystone_config' }
shared_examples 'shared examples' do
context 'with default parameters' do
it 'configure oslo_policy default params' do
is_expected.to contain_keystone_config('oslo_policy/policy_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_policy/policy_default_rule').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_policy/policy_dirs').with_value('<SERVICE DEFAULT>')
end
end
context 'with overridden parameters' do
let :params do
{
:policy_file => '/path/to/policy.file',
:policy_default_rule => 'some rule',
:policy_dirs => ['dir1', '/dir/2'],
}
end
it 'configures oslo_policy section' do
is_expected.to contain_keystone_config('oslo_policy/policy_file').with_value('/path/to/policy.file')
is_expected.to contain_keystone_config('oslo_policy/policy_default_rule').with_value('some rule')
is_expected.to contain_keystone_config('oslo_policy/policy_dirs').with_value('dir1,/dir/2')
end
end
context 'with string in list parameters' do
let :params do
{
:policy_dirs => 'dir1,/dir/2',
}
end
it 'configures oslo_policy section' do
is_expected.to contain_keystone_config('oslo_policy/policy_dirs').with_value('dir1,/dir/2')
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_behaves_like 'shared examples'
end
end
end