From 8118ce9a4bd3c9ba942a69fd348f9d6ec133b3d0 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 19 Aug 2021 21:09:13 +0900 Subject: [PATCH] Split out _client configurations This change introduces the independent classes to manage parameters in the _client sections. These classes provides support for endpoint_type and region_name. Change-Id: If0e06e6c1364f45cfa3a42428cd8e043a5a1b369 --- manifests/cinder_client.pp | 36 ++++++++++ manifests/glance_client.pp | 36 ++++++++++ manifests/init.pp | 71 ++++++++++++------- manifests/neutron_client.pp | 36 ++++++++++ manifests/nova_client.pp | 36 ++++++++++ .../client-classes-e167f5676c4888d1.yaml | 14 ++++ spec/classes/watcher_cinder_client_spec.rb | 46 ++++++++++++ spec/classes/watcher_glance_client_spec.rb | 46 ++++++++++++ spec/classes/watcher_neutron_client_spec.rb | 46 ++++++++++++ spec/classes/watcher_nova_client_spec.rb | 46 ++++++++++++ 10 files changed, 386 insertions(+), 27 deletions(-) create mode 100644 manifests/cinder_client.pp create mode 100644 manifests/glance_client.pp create mode 100644 manifests/neutron_client.pp create mode 100644 manifests/nova_client.pp create mode 100644 releasenotes/notes/client-classes-e167f5676c4888d1.yaml create mode 100644 spec/classes/watcher_cinder_client_spec.rb create mode 100644 spec/classes/watcher_glance_client_spec.rb create mode 100644 spec/classes/watcher_neutron_client_spec.rb create mode 100644 spec/classes/watcher_nova_client_spec.rb diff --git a/manifests/cinder_client.pp b/manifests/cinder_client.pp new file mode 100644 index 0000000..e48d1af --- /dev/null +++ b/manifests/cinder_client.pp @@ -0,0 +1,36 @@ +# == Class: watcher::cinder_client +# +# Configure the cinder_client options +# +# === Parameters +# +# [*api_version*] +# (Optional) Version of Cinder API to use in cinderclient. +# Defaults to $::os_service_default +# +# [*endpoint_type*] +# (Optional) Type of endpoint to use in cinderclient. +# Defaults to $::os_service_default +# +# [*region_name*] +# (Optional) Region in Identify service catalog to use for communication +# with the OpenStack service. +# Defaults to $::os_service_default. +# +class watcher::cinder_client ( + $api_version = $::os_service_default, + $endpoint_type = $::os_service_default, + $region_name = $::os_service_default, +) { + + include watcher::deps + include watcher::params + + $api_version_real = pick($::watcher::cinder_client_api_version, $api_version) + + watcher_config { + 'cinder_client/api_version': value => $api_version_real; + 'cinder_client/endpoint_type': value => $endpoint_type; + 'cinder_client/region_name': value => $region_name; + } +} diff --git a/manifests/glance_client.pp b/manifests/glance_client.pp new file mode 100644 index 0000000..6a5d865 --- /dev/null +++ b/manifests/glance_client.pp @@ -0,0 +1,36 @@ +# == Class: watcher::glance_client +# +# Configure the glance_client options +# +# === Parameters +# +# [*api_version*] +# (Optional) Version of Glance API to use in glanceclient. +# Defaults to $::os_service_default +# +# [*endpoint_type*] +# (Optional) Type of endpoint to use in glanceclient. +# Defaults to $::os_service_default +# +# [*region_name*] +# (Optional) Region in Identify service catalog to use for communication +# with the OpenStack service. +# Defaults to $::os_service_default. +# +class watcher::glance_client ( + $api_version = $::os_service_default, + $endpoint_type = $::os_service_default, + $region_name = $::os_service_default, +) { + + include watcher::deps + include watcher::params + + $api_version_real = pick($::watcher::glance_client_api_version, $api_version) + + watcher_config { + 'glance_client/api_version': value => $api_version_real; + 'glance_client/endpoint_type': value => $endpoint_type; + 'glance_client/region_name': value => $region_name; + } +} diff --git a/manifests/init.pp b/manifests/init.pp index 334fc15..91b2216 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -8,22 +8,6 @@ # (required) Enable SSL on the API server. # Defaults to false. # -# [*cinder_client_api_version*] -# (required) Version of Cinder API to use in cinderclient. -# Default is $::os_service_default. -# -# [*glance_client_api_version*] -# (required) Version of Glance API to use in glanceclient. -# Default is $::os_service_default. -# -# [*neutron_client_api_version*] -# (required) Version of Neutron API to use in neutronclient. -# Default is $::os_service_default. -# -# [*nova_client_api_version*] -# (required) Version of Nova API to use in novaclient. -# Default is $::os_service_default -# # [*package_ensure*] # (optional) Whether the watcher api package will be installed # Defaults to 'present' @@ -234,6 +218,22 @@ # (required) Version of Ceilometer API to use in ceilometerclient. # Default is undef # +# [*cinder_client_api_version*] +# (required) Version of Cinder API to use in cinderclient. +# Default is $::os_service_default. +# +# [*glance_client_api_version*] +# (required) Version of Glance API to use in glanceclient. +# Default is $::os_service_default. +# +# [*neutron_client_api_version*] +# (required) Version of Neutron API to use in neutronclient. +# Default is $::os_service_default. +# +# [*nova_client_api_version*] +# (required) Version of Nova API to use in novaclient. +# Default is $::os_service_default +# # === Authors # # Daniel Pawlik @@ -241,10 +241,6 @@ class watcher ( $purge_config = false, $use_ssl = false, - $cinder_client_api_version = $::os_service_default, - $glance_client_api_version = $::os_service_default, - $neutron_client_api_version = $::os_service_default, - $nova_client_api_version = $::os_service_default, $package_ensure = 'present', $rabbit_login_method = $::os_service_default, $rabbit_retry_interval = $::os_service_default, @@ -291,6 +287,10 @@ class watcher ( # DEPRECATED PARAMETERS $amqp_allow_insecure_clients = undef, $ceilometer_client_api_version = undef, + $cinder_client_api_version = undef, + $glance_client_api_version = undef, + $neutron_client_api_version = undef, + $nova_client_api_version = undef, ) { include openstacklib::openstackclient @@ -309,6 +309,30 @@ will be removed in a future release.') warning('The ceilometer_client_api_version parameter is deprecated and has no effect') } + if $cinder_client_api_version != undef { + warning('The cinder_client_api_version parameter is deprecated. \ +Use the watcher::cinder_client class instead') + include watcher::cinder_client + } + + if $glance_client_api_version != undef { + warning('The glance_client_api_version parameter is deprecated. \ +Use the watcher::glance_client class instead') + include watcher::glance_client + } + + if $neutron_client_api_version != undef { + warning('The neutron_client_api_version parameter is deprecated. \ +Use the watcher::neutron_client class instead') + include watcher::neutron_client + } + + if $nova_client_api_version != undef { + warning('The nova_client_api_version parameter is deprecated. \ +Use the watcher::nova_client class instead') + include watcher::nova_client + } + package { 'watcher': ensure => $package_ensure, name => $::watcher::params::common_package_name, @@ -319,13 +343,6 @@ will be removed in a future release.') purge => $purge_config, } - watcher_config { - 'cinder_client/api_version': value => $cinder_client_api_version; - 'glance_client/api_version': value => $glance_client_api_version; - 'neutron_client/api_version': value => $neutron_client_api_version; - 'nova_client/api_version': value => $nova_client_api_version; - } - oslo::messaging::rabbit { 'watcher_config': amqp_durable_queues => $amqp_durable_queues, kombu_ssl_version => $kombu_ssl_version, diff --git a/manifests/neutron_client.pp b/manifests/neutron_client.pp new file mode 100644 index 0000000..8354d4a --- /dev/null +++ b/manifests/neutron_client.pp @@ -0,0 +1,36 @@ +# == Class: watcher::neutron_client +# +# Configure the neutron_client options +# +# === Parameters +# +# [*api_version*] +# (Optional) Version of Neutron API to use in neutronclient. +# Defaults to $::os_service_default +# +# [*endpoint_type*] +# (Optional) Type of endpoint to use in neutronclient. +# Defaults to $::os_service_default +# +# [*region_name*] +# (Optional) Region in Identify service catalog to use for communication +# with the OpenStack service. +# Defaults to $::os_service_default. +# +class watcher::neutron_client ( + $api_version = $::os_service_default, + $endpoint_type = $::os_service_default, + $region_name = $::os_service_default, +) { + + include watcher::deps + include watcher::params + + $api_version_real = pick($::watcher::neutron_client_api_version, $api_version) + + watcher_config { + 'neutron_client/api_version': value => $api_version_real; + 'neutron_client/endpoint_type': value => $endpoint_type; + 'neutron_client/region_name': value => $region_name; + } +} diff --git a/manifests/nova_client.pp b/manifests/nova_client.pp new file mode 100644 index 0000000..21d5c05 --- /dev/null +++ b/manifests/nova_client.pp @@ -0,0 +1,36 @@ +# == Class: watcher::nova_client +# +# Configure the nova_client options +# +# === Parameters +# +# [*api_version*] +# (Optional) Version of Nova API to use in novaclient. +# Defaults to $::os_service_default +# +# [*endpoint_type*] +# (Optional) Type of endpoint to use in novaclient. +# Defaults to $::os_service_default +# +# [*region_name*] +# (Optional) Region in Identify service catalog to use for communication +# with the OpenStack service. +# Defaults to $::os_service_default. +# +class watcher::nova_client ( + $api_version = $::os_service_default, + $endpoint_type = $::os_service_default, + $region_name = $::os_service_default, +) { + + include watcher::deps + include watcher::params + + $api_version_real = pick($::watcher::nova_client_api_version, $api_version) + + watcher_config { + 'nova_client/api_version': value => $api_version_real; + 'nova_client/endpoint_type': value => $endpoint_type; + 'nova_client/region_name': value => $region_name; + } +} diff --git a/releasenotes/notes/client-classes-e167f5676c4888d1.yaml b/releasenotes/notes/client-classes-e167f5676c4888d1.yaml new file mode 100644 index 0000000..a38c468 --- /dev/null +++ b/releasenotes/notes/client-classes-e167f5676c4888d1.yaml @@ -0,0 +1,14 @@ +--- +features: + - | + The following new class have been added. + + - ``watcher::cinder_client`` + - ``watcher::glance_client`` + - ``watcher::neutron_client`` + - ``watcher::nova_client`` + +deprecations: + - | + The ``watcher::_client_api_version`` parameters have been + deprecated in favor of the new ``watcher::_client`` classes. diff --git a/spec/classes/watcher_cinder_client_spec.rb b/spec/classes/watcher_cinder_client_spec.rb new file mode 100644 index 0000000..1f460cf --- /dev/null +++ b/spec/classes/watcher_cinder_client_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'watcher::cinder_client' do + + shared_examples 'watcher::cinder_client' do + context 'with defaults' do + let :params do + {} + end + + it 'should set the defaults' do + should contain_watcher_config('cinder_client/api_version').with_value('') + should contain_watcher_config('cinder_client/endpoint_type').with_value('') + should contain_watcher_config('cinder_client/region_name').with_value('') + end + end + + context 'with parameters overridden' do + let :params do + { + :api_version => 3, + :endpoint_type => 'publicURL', + :region_name => 'regionOne' + } + end + + it 'should set the defaults' do + should contain_watcher_config('cinder_client/api_version').with_value(3) + should contain_watcher_config('cinder_client/endpoint_type').with_value('publicURL') + should contain_watcher_config('cinder_client/region_name').with_value('regionOne') + 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 'watcher::cinder_client' + end + end + +end diff --git a/spec/classes/watcher_glance_client_spec.rb b/spec/classes/watcher_glance_client_spec.rb new file mode 100644 index 0000000..478c111 --- /dev/null +++ b/spec/classes/watcher_glance_client_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'watcher::glance_client' do + + shared_examples 'watcher::glance_client' do + context 'with defaults' do + let :params do + {} + end + + it 'should set the defaults' do + should contain_watcher_config('glance_client/api_version').with_value('') + should contain_watcher_config('glance_client/endpoint_type').with_value('') + should contain_watcher_config('glance_client/region_name').with_value('') + end + end + + context 'with parameters overridden' do + let :params do + { + :api_version => 2, + :endpoint_type => 'publicURL', + :region_name => 'regionOne' + } + end + + it 'should set the defaults' do + should contain_watcher_config('glance_client/api_version').with_value(2) + should contain_watcher_config('glance_client/endpoint_type').with_value('publicURL') + should contain_watcher_config('glance_client/region_name').with_value('regionOne') + 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 'watcher::glance_client' + end + end + +end diff --git a/spec/classes/watcher_neutron_client_spec.rb b/spec/classes/watcher_neutron_client_spec.rb new file mode 100644 index 0000000..df82512 --- /dev/null +++ b/spec/classes/watcher_neutron_client_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'watcher::neutron_client' do + + shared_examples 'watcher::neutron_client' do + context 'with defaults' do + let :params do + {} + end + + it 'should set the defaults' do + should contain_watcher_config('neutron_client/api_version').with_value('') + should contain_watcher_config('neutron_client/endpoint_type').with_value('') + should contain_watcher_config('neutron_client/region_name').with_value('') + end + end + + context 'with parameters overridden' do + let :params do + { + :api_version => 2.0, + :endpoint_type => 'publicURL', + :region_name => 'regionOne' + } + end + + it 'should set the defaults' do + should contain_watcher_config('neutron_client/api_version').with_value(2.0) + should contain_watcher_config('neutron_client/endpoint_type').with_value('publicURL') + should contain_watcher_config('neutron_client/region_name').with_value('regionOne') + 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 'watcher::neutron_client' + end + end + +end diff --git a/spec/classes/watcher_nova_client_spec.rb b/spec/classes/watcher_nova_client_spec.rb new file mode 100644 index 0000000..b176f7d --- /dev/null +++ b/spec/classes/watcher_nova_client_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'watcher::nova_client' do + + shared_examples 'watcher::nova_client' do + context 'with defaults' do + let :params do + {} + end + + it 'should set the defaults' do + should contain_watcher_config('nova_client/api_version').with_value('') + should contain_watcher_config('nova_client/endpoint_type').with_value('') + should contain_watcher_config('nova_client/region_name').with_value('') + end + end + + context 'with parameters overridden' do + let :params do + { + :api_version => 2, + :endpoint_type => 'publicURL', + :region_name => 'regionOne' + } + end + + it 'should set the defaults' do + should contain_watcher_config('nova_client/api_version').with_value(2) + should contain_watcher_config('nova_client/endpoint_type').with_value('publicURL') + should contain_watcher_config('nova_client/region_name').with_value('regionOne') + 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 'watcher::nova_client' + end + end + +end