Add support for Manila policy.json

Change-Id: Idcd042913e33c65641aa0a1874811fe9f2efb793
This commit is contained in:
Emilien Macchi 2018-01-11 16:59:11 -08:00
parent 7fdfbf6127
commit f668a735b5
6 changed files with 104 additions and 0 deletions

View File

@ -86,6 +86,7 @@ class manila::api (
include ::manila::deps include ::manila::deps
include ::manila::params include ::manila::params
include ::manila::policy
require ::keystone::python require ::keystone::python
if $service_port { if $service_port {

View File

@ -9,6 +9,7 @@ class manila::params {
$client_package = 'python-manilaclient' $client_package = 'python-manilaclient'
$db_sync_command = 'manila-manage db sync' $db_sync_command = 'manila-manage db sync'
$lio_package_name = 'targetcli' $lio_package_name = 'targetcli'
$group = 'manila'
case $::osfamily { case $::osfamily {
'Debian': { 'Debian': {

46
manifests/policy.pp Normal file
View File

@ -0,0 +1,46 @@
# == Class: manila::policy
#
# Configure the manila policies
#
# === Parameters
#
# [*policies*]
# (optional) Set of policies to configure for manila
# Example :
# {
# 'manila-context_is_admin' => {
# 'key' => 'context_is_admin',
# 'value' => 'true'
# },
# 'manila-default' => {
# 'key' => 'default',
# 'value' => 'rule:admin_or_owner'
# }
# }
# Defaults to empty hash.
#
# [*policy_path*]
# (optional) Path to the manila policy.json file
# Defaults to /etc/manila/policy.json
#
class manila::policy (
$policies = {},
$policy_path = '/etc/manila/policy.json',
) {
include ::manila::deps
include ::manila::params
validate_hash($policies)
Openstacklib::Policy::Base {
file_path => $policy_path,
file_user => 'root',
file_group => $::manila::params::group,
}
create_resources('openstacklib::policy::base', $policies)
oslo::policy { 'manila_config': policy_file => $policy_path }
}

View File

@ -0,0 +1,5 @@
---
features:
- |
Support for policy.json configuration has been implemented in the same
way as other modules with manila::policy class.

View File

@ -20,6 +20,7 @@ describe 'manila::api' do
req_params req_params
end end
it { is_expected.to contain_class('manila::policy') }
it { is_expected.to contain_service('manila-api').with( it { is_expected.to contain_service('manila-api').with(
'hasstatus' => true, 'hasstatus' => true,
'ensure' => 'running', 'ensure' => 'running',
@ -44,6 +45,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'default_share_type' => 'default'}) req_params.merge({'default_share_type' => 'default'})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should configure the default share type' do it 'should configure the default share type' do
is_expected.to contain_manila_config('DEFAULT/default_share_type').with( is_expected.to contain_manila_config('DEFAULT/default_share_type').with(
:value => 'default' :value => 'default'
@ -55,6 +57,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'service_workers' => '4'}) req_params.merge({'service_workers' => '4'})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should configure the share workers' do it 'should configure the share workers' do
is_expected.to contain_manila_config('DEFAULT/osapi_share_workers').with( is_expected.to contain_manila_config('DEFAULT/osapi_share_workers').with(
:value => '4' :value => '4'
@ -66,6 +69,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'bind_host' => '192.168.1.3'}) req_params.merge({'bind_host' => '192.168.1.3'})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should configure manila api correctly' do it 'should configure manila api correctly' do
is_expected.to contain_manila_config('DEFAULT/osapi_share_listen').with( is_expected.to contain_manila_config('DEFAULT/osapi_share_listen').with(
:value => '192.168.1.3' :value => '192.168.1.3'
@ -77,6 +81,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'enable_proxy_headers_parsing' => true}) req_params.merge({'enable_proxy_headers_parsing' => true})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should configure manila api correctly' do it 'should configure manila api correctly' do
is_expected.to contain_manila_config('oslo_middleware/enable_proxy_headers_parsing').with( is_expected.to contain_manila_config('oslo_middleware/enable_proxy_headers_parsing').with(
:value => true :value => true
@ -88,6 +93,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'enabled' => false}) req_params.merge({'enabled' => false})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should stop the service' do it 'should stop the service' do
is_expected.to contain_service('manila-api').with_ensure('stopped') is_expected.to contain_service('manila-api').with_ensure('stopped')
end end
@ -100,6 +106,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'sync_db' => false}) req_params.merge({'sync_db' => false})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should not include manila::db::sync' do it 'should not include manila::db::sync' do
is_expected.to_not contain_class('manila::db::sync') is_expected.to_not contain_class('manila::db::sync')
end end
@ -109,6 +116,7 @@ describe 'manila::api' do
let :params do let :params do
req_params.merge({'manage_service' => false}) req_params.merge({'manage_service' => false})
end end
it { is_expected.to contain_class('manila::policy') }
it 'should not change the state of the service' do it 'should not change the state of the service' do
is_expected.to contain_service('manila-api').without_ensure is_expected.to contain_service('manila-api').without_ensure
end end
@ -119,6 +127,7 @@ describe 'manila::api' do
req_params.merge({ :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' }) req_params.merge({ :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' })
end end
it { is_expected.to contain_class('manila::policy') }
it { is_expected.to contain_manila_api_paste_ini('filter:ratelimit/limits').with( it { is_expected.to contain_manila_api_paste_ini('filter:ratelimit/limits').with(
:value => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' :value => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)'
)} )}

View File

@ -0,0 +1,42 @@
require 'spec_helper'
describe 'manila::policy' do
shared_examples_for 'manila policies' do
let :params do
{
:policy_path => '/etc/manila/policy.json',
:policies => {
'context_is_admin' => {
'key' => 'context_is_admin',
'value' => 'foo:bar'
}
}
}
end
it 'set up the policies' do
is_expected.to contain_openstacklib__policy__base('context_is_admin').with({
:key => 'context_is_admin',
:value => 'foo:bar',
:file_user => 'root',
:file_group => 'manila',
})
is_expected.to contain_oslo__policy('manila_config').with(
:policy_file => '/etc/manila/policy.json',
)
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_configures 'manila policies'
end
end
end