Merge "Simplify policies definition"

This commit is contained in:
Zuul
2024-01-02 16:56:21 +00:00
committed by Gerrit Code Review
2 changed files with 27 additions and 22 deletions

View File

@@ -8,7 +8,8 @@
# (required) Path to the policy.json file
#
# [*key*]
# (required) The key to replace the value for
# (optional) The key to replace the value for
# Defaults to $name
#
# [*value*]
# (optional) The value to set
@@ -38,7 +39,7 @@
#
define openstacklib::policy::base (
Stdlib::Absolutepath $file_path,
String[1] $key,
String[1] $key = $name,
String $value = '',
$file_mode = '0640',
$file_user = undef,

View File

@@ -2,15 +2,14 @@ require 'spec_helper'
describe 'openstacklib::policy::base' do
shared_examples 'openstacklib::policy::base' do
context 'with policy.json' do
let :title do
'nova-contest_is_admin'
'context_is_admin or owner'
end
context 'with policy.json' do
let :params do
{
:file_path => '/etc/nova/policy.json',
:key => 'context_is_admin or owner',
:value => 'foo:bar',
:file_mode => '0644',
:file_user => 'foo',
@@ -45,14 +44,9 @@ describe 'openstacklib::policy::base' do
end
context 'with policy.yaml' do
let :title do
'nova-contest_is_admin'
end
let :params do
{
:file_path => '/etc/nova/policy.yaml',
:key => 'context_is_admin or owner',
:value => 'foo:bar',
:file_mode => '0644',
:file_user => 'foo',
@@ -105,14 +99,9 @@ describe 'openstacklib::policy::base' do
end
context 'with purge_config enabled' do
let :title do
'nova-contest_is_admin'
end
let :params do
{
:file_path => '/etc/nova/policy.yaml',
:key => 'context_is_admin or owner',
:value => 'foo:bar',
:file_mode => '0644',
:file_user => 'foo',
@@ -132,14 +121,9 @@ describe 'openstacklib::policy::base' do
end
context 'with json file_path and yaml file format' 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',
:file_mode => '0644',
:file_user => 'foo',
@@ -150,6 +134,26 @@ describe 'openstacklib::policy::base' do
it { should raise_error(Puppet::Error) }
end
context 'with key overridden' do
let :params do
{
:file_path => '/etc/nova/policy.yaml',
:key => 'context_is_admin',
:value => 'foo:bar',
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'bar',
:file_format => 'yaml',
}
end
it { should contain_file_line('/etc/nova/policy.yaml-context_is_admin').with(
:path => '/etc/nova/policy.yaml',
:line => '\'context_is_admin\': \'foo:bar\'',
:match => '^[\'"]?context_is_admin(?!:)[\'"]?\s*:.+'
) }
end
end
on_supported_os({