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 # === Parameters
# #
# [*enforce_scope*]
# (Optional) Whether or not to enforce scope when evaluating policies.
# Defaults to $::os_service_default.
#
# [*policies*] # [*policies*]
# (Optional) Set of policies to configure for nova # (Optional) Set of policies to configure for nova
# Example : # Example :
@@ -24,6 +28,7 @@
# Defaults to /etc/nova/policy.yaml # Defaults to /etc/nova/policy.yaml
# #
class nova::policy ( class nova::policy (
$enforce_scope = $::os_service_default,
$policies = {}, $policies = {},
$policy_path = '/etc/nova/policy.yaml', $policy_path = '/etc/nova/policy.yaml',
) { ) {
@@ -33,15 +38,18 @@ class nova::policy (
validate_legacy(Hash, 'validate_hash', $policies) validate_legacy(Hash, 'validate_hash', $policies)
$policy_defaults = { Openstacklib::Policy::Base {
file_path => $policy_path, file_path => $policy_path,
file_user => 'root', file_user => 'root',
file_group => $::nova::params::group, file_group => $::nova::params::group,
file_format => 'yaml', 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,10 +1,10 @@
require 'spec_helper' require 'spec_helper'
describe 'nova::policy' do describe 'nova::policy' do
shared_examples 'nova::policy' do
shared_examples_for 'nova policies' do
let :params do let :params do
{ {
:enforce_scope => false,
:policy_path => '/etc/nova/policy.yaml', :policy_path => '/etc/nova/policy.yaml',
:policies => { :policies => {
'context_is_admin' => { 'context_is_admin' => {
@@ -24,6 +24,7 @@ describe 'nova::policy' do
:file_format => 'yaml', :file_format => 'yaml',
}) })
is_expected.to contain_oslo__policy('nova_config').with( is_expected.to contain_oslo__policy('nova_config').with(
:enforce_scope => false,
:policy_file => '/etc/nova/policy.yaml', :policy_file => '/etc/nova/policy.yaml',
) )
end end
@@ -37,8 +38,7 @@ describe 'nova::policy' do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end end
it_configures 'nova policies' it_behaves_like 'nova::policy'
end end
end end
end end