From e452c3d55cebebe843f659150b0a866152fda236 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Wed, 22 May 2019 10:04:37 -0400 Subject: [PATCH] Introduce tripleo::config tripleo::config is a class that will take care of param_config in THT. Example in THT: puppet_config: param_config: aodh_config: oslo_middleware: enable_proxy_headers_parsing: True tripleo::config will call the aodh_config provider for each parameter and its value, so here it'll call: create_resources('aodh_config', 'oslo_middleware/enable_proxy_headers_parsing' => { 'value' => True } ) Note: we add a filter capability where once can configure tripleo::config with providers parameter to filter which providers we want to call. Change-Id: Ia008917475edcd086fb5076fab320206d05ea557 --- manifests/config.pp | 44 ++++++++++++++++++++++++++++ spec/classes/tripleo_config_spec.rb | 45 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 manifests/config.pp create mode 100644 spec/classes/tripleo_config_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 000000000..9b8b12841 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,44 @@ +# == Class: tripleo::config +# +# Configure services with Puppet +# +# === Parameters: +# +# [*configs*] +# (optional) Configuration to inject. +# Should be an hash. +# Default to lookup('param_config', {}) +# +# [*providers*] +# (optional) Filter the providers we want +# to use for config. +# Should be an array. +# Default to lookup('param_providers', Array[String], 'deep', []) +# +class tripleo::config( + $configs = lookup('param_config', {}), + $providers = lookup('param_providers', Array[String], 'deep', []), +) { + + if ! empty($configs) { + # Allow composable services to load their own configurations. + # Each service can load its config options by using this form: + # + # puppet_config: + # param_config: + # 'aodh_config': + # DEFAULT: + # foo: fooValue + # bar: barValue + $configs.each |$provider, $sections| { + if empty($providers) or ($provider in $providers) { + $sections.each |$section, $params| { + $params.each |$param, $value| { + create_resources($provider, {"${section}/${param}" => {'value' => $value }}) + } + } + } + } + } + +} diff --git a/spec/classes/tripleo_config_spec.rb b/spec/classes/tripleo_config_spec.rb new file mode 100644 index 000000000..6b4d73fc6 --- /dev/null +++ b/spec/classes/tripleo_config_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe 'tripleo::config' do + + let :params do + { } + end + + shared_examples_for 'tripleo::config' do + context 'with glance_api service' do + before :each do + params.merge!( + :configs => { 'glance_api_config' => { 'DEFAULT' => { 'foo' => 'bar', 'foo2' => 'bar2' } } }, + ) + end + it 'configures arbitrary glance-api configurations' do + is_expected.to contain_glance_api_config('DEFAULT/foo').with_value('bar') + is_expected.to contain_glance_api_config('DEFAULT/foo2').with_value('bar2') + end + end + + context 'with glance_api service and provider filter' do + before :each do + params.merge!( + :configs => { 'glance_api_config' => { 'DEFAULT' => { 'foo' => 'bar' } }, 'nova_config' => { 'DEFAULT' => { 'foo' => 'bar' } } }, + :providers => ['glance_api_config'], + ) + end + it 'configures arbitrary glance-api configurations without nova_config' do + is_expected.to contain_glance_api_config('DEFAULT/foo').with_value('bar') + is_expected.to_not contain_nova_config('DEFAULT/foo').with_value('bar') + end + end + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + end + + it_behaves_like 'tripleo::config' + end + end +end