Implement generic placement::config::placement_config

This change introduce the generic config class functionalities
for which there is no specific implementation.
Similar approach is seen in puppet-nova

Closes-bug: #1829250

Change-Id: I78727c1f71706d82860c52fa5d64cb200dcb394c
This commit is contained in:
Piotr Kopec 2019-05-15 15:44:15 +02:00
parent 83b2269ae9
commit 9ec9616e07
3 changed files with 49 additions and 12 deletions

View File

@ -48,6 +48,22 @@
# and not the Identity service API IP and port.
# Defaults to 'http://127.0.0.1:5000/v3'
#
# [*placement_config*]
# (optional) Allow configuration of arbitrary Placement configurations.
# The value is an hash of placement_config resources. Example:
# { 'DEFAULT/foo' => { value => 'fooValue'},
# 'DEFAULT/bar' => { value => 'barValue'}
# }
# In yaml format, Example:
# placement_config:
# DEFAULT/foo:
# value: fooValue
# DEFAULT/bar:
# value: barValue
#
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
class placement::config(
$password = false,
$auth_type = 'password',
@ -58,20 +74,27 @@ class placement::config(
$project_name = 'services',
$user_domain_name = 'Default',
$username = 'placement',
$placement_config = {},
) {
include ::placement::deps
placement_config {
'placement/auth_type': value => $auth_type;
'placement/auth_url': value => $auth_url;
'placement/password': value => $password, secret => true;
'placement/project_domain_name': value => $project_domain_name;
'placement/project_name': value => $project_name;
'placement/user_domain_name': value => $user_domain_name;
'placement/username': value => $username;
'placement/region_name': value => $region_name;
'placement/valid_interfaces': value => $valid_interfaces;
$default_parameters = {
'placement/auth_type' => { value => $auth_type},
'placement/auth_url' => { value => $auth_url},
'placement/password' => { value => $password, secret => true},
'placement/project_domain_name' => { value => $project_domain_name},
'placement/project_name' => { value => $project_name},
'placement/user_domain_name' => { value => $user_domain_name},
'placement/username' => { value => $username},
'placement/region_name' => { value => $region_name},
'placement/valid_interfaces' => { value => $valid_interfaces},
}
validate_legacy(Hash, 'validate_hash', $default_parameters)
validate_legacy(Hash, 'validate_hash', $placement_config)
$placement_parameters = merge($default_parameters, $placement_config)
create_resources('placement_config', $placement_parameters)
}

View File

@ -0,0 +1,4 @@
---
features:
- |
Allow configuration of arbitrary Placement configurations.

View File

@ -10,17 +10,24 @@ describe 'placement::config' do
:username => 'placement',
:user_domain_name => 'Default',
:auth_url => 'http://127.0.0.1:5000/v3',
}
}
end
let :params do
{
:password => 's3cr3t'
:password => 's3cr3t',
:placement_config => {
'DEFAULT/foo' => { 'value' => 'fooValue' },
'DEFAULT/bar' => { 'value' => 'barValue' },
'DEFAULT/baz' => { 'ensure' => 'absent' }
}
}
end
shared_examples 'placement::config' do
context 'with required parameters' do
it { should contain_class('placement::deps') }
it {
should contain_placement_config('placement/password').with_value(params[:password]).with_secret(true)
should contain_placement_config('placement/auth_type').with_value(default_params[:auth_type])
@ -31,6 +38,9 @@ describe 'placement::config' do
should contain_placement_config('placement/username').with_value(default_params[:username])
should contain_placement_config('placement/user_domain_name').with_value(default_params[:user_domain_name])
should contain_placement_config('placement/auth_url').with_value(default_params[:auth_url])
should contain_placement_config('DEFAULT/foo').with_value('fooValue')
should contain_placement_config('DEFAULT/bar').with_value('barValue')
should contain_placement_config('DEFAULT/baz').with_ensure('absent')
}
end