Add support for the oslo_policy/enforce_scope parameter

Depends-on: https://review.opendev.org/#/c/759008/
Change-Id: Ief74bb444f72dae125e73e611c8412b118ae0ee9
This commit is contained in:
Takashi Kajinami 2021-03-16 18:35:37 +09:00
parent d9552ad11f
commit 607d8a854d
3 changed files with 26 additions and 13 deletions

View File

@ -4,6 +4,10 @@
#
# === Parameters
#
# [*enforce_scope*]
# (Optional) Whether or not to enforce scope when evaluating policies.
# Defaults to $::os_service_default.
#
# [*policies*]
# (Optional) Set of policies to configure for nova
# Example :
@ -24,8 +28,9 @@
# Defaults to /etc/nova/policy.yaml
#
class nova::policy (
$policies = {},
$policy_path = '/etc/nova/policy.yaml',
$enforce_scope = $::os_service_default,
$policies = {},
$policy_path = '/etc/nova/policy.yaml',
) {
include nova::deps
@ -33,15 +38,18 @@ class nova::policy (
validate_legacy(Hash, 'validate_hash', $policies)
$policy_defaults = {
Openstacklib::Policy::Base {
file_path => $policy_path,
file_user => 'root',
file_group => $::nova::params::group,
file_format => 'yaml',
}
create_resources('openstacklib::policy::base', $policies, $policy_defaults)
create_resources('openstacklib::policy::base', $policies)
oslo::policy { 'nova_config': policy_file => $policy_path }
oslo::policy { 'nova_config':
enforce_scope => $enforce_scope,
policy_file => $policy_path
}
}

View File

@ -0,0 +1,5 @@
---
features:
- |
The new ``nova::policy::enforce_scope`` parameter has been added to
support the corresponding parameter in oslo.policy library.

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe 'nova::policy' do
shared_examples_for 'nova policies' do
shared_examples 'nova::policy' do
let :params do
{
:policy_path => '/etc/nova/policy.yaml',
:policies => {
:enforce_scope => false,
:policy_path => '/etc/nova/policy.yaml',
:policies => {
'context_is_admin' => {
'key' => 'context_is_admin',
'value' => 'foo:bar'
@ -24,21 +24,21 @@ describe 'nova::policy' do
:file_format => 'yaml',
})
is_expected.to contain_oslo__policy('nova_config').with(
:policy_file => '/etc/nova/policy.yaml',
:enforce_scope => false,
:policy_file => '/etc/nova/policy.yaml',
)
end
end
on_supported_os({
:supported_os => OSDefaults.get_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 'nova policies'
it_behaves_like 'nova::policy'
end
end
end