From 09a2c6b46c5ba02f8290904dca195329f2ebeafb Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 18 Jan 2022 00:00:07 +0900 Subject: [PATCH] Add an independent class for [network_api:neutron] parameters ... and improve coverage of the supported parameters. Change-Id: I1c3095561875cfa82e484c69173571ad6ba34428 --- manifests/init.pp | 17 ++++-- manifests/network_api/neutron.pp | 35 +++++++++++ .../network_api-neutron-8b58605b37d1872f.yaml | 11 ++++ .../designate_network_api_neutron_spec.rb | 60 +++++++++++++++++++ 4 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 manifests/network_api/neutron.pp create mode 100644 releasenotes/notes/network_api-neutron-8b58605b37d1872f.yaml create mode 100644 spec/classes/designate_network_api_neutron_spec.rb diff --git a/manifests/init.pp b/manifests/init.pp index 83b261e1..3b580c43 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -106,9 +106,11 @@ # (optional) Whether to use durable queues in AMQP. # Defaults to $::os_service_default. # +# DEPRECATED PARAMETERS +# # [*neutron_endpoint_type*] # (optional) Endpoint type to use. -# Defaults to $::os_service_default. +# Defaults to undef # class designate( $package_ensure = present, @@ -132,7 +134,8 @@ class designate( $notification_topics = 'notifications', $purge_config = false, $amqp_durable_queues = $::os_service_default, - $neutron_endpoint_type = $::os_service_default, + # DEPRECATED PARAMETERS + $neutron_endpoint_type = undef ) inherits designate::params { if !is_service_default($kombu_ssl_ca_certs) and !$rabbit_use_ssl { @@ -151,6 +154,11 @@ class designate( include designate::deps + if $neutron_endpoint_type != undef { + warning('The neutron_endpoint_type parameter is deprecated. Use the designate::network_api::neutron class.') + } + include designate::network_api::neutron + package { 'designate-common': ensure => $package_ensure, name => $common_package_name, @@ -188,9 +196,8 @@ class designate( # default setting designate_config { - 'DEFAULT/root_helper' : value => $root_helper; - 'DEFAULT/state_path' : value => $state_path; - 'network_api:neutron/endpoint_type' : value => $neutron_endpoint_type; + 'DEFAULT/root_helper': value => $root_helper; + 'DEFAULT/state_path' : value => $state_path; } } diff --git a/manifests/network_api/neutron.pp b/manifests/network_api/neutron.pp new file mode 100644 index 00000000..d54227bf --- /dev/null +++ b/manifests/network_api/neutron.pp @@ -0,0 +1,35 @@ +# == Class: designate::network_api::neutron +# +# Configure the [network_api:neutron] parameters +# +# === Parameters +# +# [*endpoints*] +# (Optional) URL to use. Format: | +# Defaults to $::os_service_default. +# +# [*endpoint_type*] +# (Optional) Endpoiint type to use +# Defaults to $::os_service_default. +# +# [*timeout*] +# (Optional) Timeout value for connecting to neutorn in seconds. +# Defaults to $::os_service_default. +# +class designate::network_api::neutron ( + $endpoints = $::os_service_default, + $endpoint_type = $::os_service_default, + $timeout = $::os_service_default, +) { + include designate::deps + include designate::params + + $endpoint_type_real = pick($::designate::neutron_endpoint_type, $endpoint_type) + + designate_config { + 'network_api:neutron/endpoints': value => join(any2array($endpoints), ','); + 'network_api:neutron/endpoint_type': value => $endpoint_type_real; + 'network_api:neutron/timeout': value => $timeout; + } + +} diff --git a/releasenotes/notes/network_api-neutron-8b58605b37d1872f.yaml b/releasenotes/notes/network_api-neutron-8b58605b37d1872f.yaml new file mode 100644 index 00000000..81fb5ed7 --- /dev/null +++ b/releasenotes/notes/network_api-neutron-8b58605b37d1872f.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + The new ``designate::network_api::neutron`` class has been added. This + class manages parmaeters in the ``[network_api:neutron]`` section. + +deprecations: + - | + The ``designate::neutron_endpoint_type`` parameter has been deprecated. + Use the ``endpoint_type`` parameter of the new + ``designate::network_api::neutron`` class. diff --git a/spec/classes/designate_network_api_neutron_spec.rb b/spec/classes/designate_network_api_neutron_spec.rb new file mode 100644 index 00000000..44c9b5a9 --- /dev/null +++ b/spec/classes/designate_network_api_neutron_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe 'designate::network_api::neutron' do + shared_examples 'designate::network_api::neutron' do + + context 'with defaults' do + let :params do + {} + end + + it 'configures defaults' do + is_expected.to contain_designate_config('network_api:neutron/endpoints').with_value('') + is_expected.to contain_designate_config('network_api:neutron/endpoint_type').with_value('') + is_expected.to contain_designate_config('network_api:neutron/timeout').with_value('') + end + end + + context 'with parameters set' do + let :params do + { + :endpoints => 'regionOne|http://192.168.1.10:9696,regionTwo|http://192.168.2.10:9696', + :endpoint_type => 'internalURL', + :timeout => 30, + } + end + + it 'configures the defined values' do + is_expected.to contain_designate_config('network_api:neutron/endpoints').with_value(params[:endpoints]) + is_expected.to contain_designate_config('network_api:neutron/endpoint_type').with_value(params[:endpoint_type]) + is_expected.to contain_designate_config('network_api:neutron/timeout').with_value(params[:timeout]) + end + end + + context 'with endpoints in array' do + let :params do + { + :endpoints => ['regionOne|http://192.168.1.10:9696', 'regionTwo|http://192.168.2.10:9696'] + } + end + + it 'configures the endpoints in string' do + is_expected.to contain_designate_config('network_api:neutron/endpoints').with_value( + 'regionOne|http://192.168.1.10:9696,regionTwo|http://192.168.2.10:9696' + ) + end + 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_behaves_like 'designate::network_api::neutron' + end + end +end