From 270d33d5436b0e9f13f88b308a17e299e00f21bc Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 23 Feb 2022 18:51:03 +0900 Subject: [PATCH] Accept array or hash for enable_provider_drivers The [api_settings] enable_provider_drivers parameter is DictOpt and accepts a string value which represents a dictionary. This change allows using array or hash for this parameter so that users can use a more "native" type to define its value. Change-Id: Icfa01a6cba5f4eda68d51ec2740f24fbc049f6e2 --- manifests/api.pp | 8 ++++- ...ert-provider_drivers-922ba756396e154c.yaml | 6 ++++ spec/classes/octavia_api_spec.rb | 34 +++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/convert-provider_drivers-922ba756396e154c.yaml diff --git a/manifests/api.pp b/manifests/api.pp index 492f6c83..8ca506dc 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -180,6 +180,12 @@ class octavia::api ( include octavia::db::sync } + if $provider_drivers =~ Hash { + $provider_drivers_real = join(join_keys_to_values($provider_drivers, ':'), ',') + } else { + $provider_drivers_real = join(any2array($provider_drivers), ',') + } + octavia_config { 'api_settings/bind_host': value => $host; 'api_settings/bind_port': value => $port; @@ -189,7 +195,7 @@ class octavia::api ( 'api_settings/api_v2_enabled': value => $api_v2_enabled; 'api_settings/allow_tls_terminated_listeners': value => $allow_tls_terminated_listeners; 'api_settings/default_provider_driver': value => $default_provider_driver; - 'api_settings/enabled_provider_drivers': value => $provider_drivers; + 'api_settings/enabled_provider_drivers': value => $provider_drivers_real; 'api_settings/pagination_max_limit': value => $pagination_max_limit; 'api_settings/healthcheck_enabled': value => $healthcheck_enabled; 'api_settings/healthcheck_refresh_interval': value => $healthcheck_refresh_interval; diff --git a/releasenotes/notes/convert-provider_drivers-922ba756396e154c.yaml b/releasenotes/notes/convert-provider_drivers-922ba756396e154c.yaml new file mode 100644 index 00000000..bb81dbf5 --- /dev/null +++ b/releasenotes/notes/convert-provider_drivers-922ba756396e154c.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The ``octavia::api::provider_drivers`` parameter now supports array or hash + value, and the given value is conveted to correctly formatted string when + being put into octavia.conf. diff --git a/spec/classes/octavia_api_spec.rb b/spec/classes/octavia_api_spec.rb index bb1346a0..a74485bd 100644 --- a/spec/classes/octavia_api_spec.rb +++ b/spec/classes/octavia_api_spec.rb @@ -12,7 +12,7 @@ describe 'octavia::api' do :api_v2_enabled => true, :allow_tls_terminated_listeners => false, :default_provider_driver => 'ovn', - :provider_drivers => { 'amphora' => 'Octavia Amphora Driver', 'ovn' => 'Octavia OVN driver' }, + :provider_drivers => 'amphora:Octavia Amphora Driver,ovn:Octavia OVN driver', :pagination_max_limit => '1000', :healthcheck_enabled => true, :healthcheck_refresh_interval => 5, @@ -74,7 +74,7 @@ describe 'octavia::api' do end end - it 'configures bind_host and bind_port' do + it 'configures parameters' do is_expected.to contain_octavia_config('api_settings/bind_host').with_value( params[:host] ) is_expected.to contain_octavia_config('api_settings/bind_port').with_value( params[:port] ) is_expected.to contain_octavia_config('api_settings/api_handler').with_value( params[:api_handler] ) @@ -179,6 +179,36 @@ describe 'octavia::api' do .with_value('TLSv1') end end + + context 'with provider_drivers in array' do + before do + params.merge!({ + :provider_drivers => [ + 'amphora:Octavia Amphora driver', + 'ovn:Octavia OVN driver' + ] + }) + end + it 'configures parameters' do + is_expected.to contain_octavia_config('api_settings/enabled_provider_drivers')\ + .with_value('amphora:Octavia Amphora driver,ovn:Octavia OVN driver') + end + end + + context 'with provider_drivers in hash' do + before do + params.merge!({ + :provider_drivers => { + 'amphora' => 'Octavia Amphora driver', + 'ovn' => 'Octavia OVN driver' + } + }) + end + it 'configures parameters' do + is_expected.to contain_octavia_config('api_settings/enabled_provider_drivers')\ + .with_value('amphora:Octavia Amphora driver,ovn:Octavia OVN driver') + end + end end shared_examples 'octavia-api wsgi' do