diff --git a/manifests/server/notifications.pp b/manifests/server/notifications.pp index 18a1c863d..dd554dfbf 100644 --- a/manifests/server/notifications.pp +++ b/manifests/server/notifications.pp @@ -16,97 +16,89 @@ # # === Parameters # -# [*password*] -# (required) Password for connection to nova in admin context. -# -# [*notify_nova_on_port_status_changes*] -# (optional) Send notification to nova when port status is active. -# Defaults to true -# -# [*notify_nova_on_port_data_changes*] -# (optional) Send notifications to nova when port data (fixed_ips/floatingips) -# change so nova can update its cache. -# Defaults to true -# # [*send_events_interval*] # (optional) Number of seconds between sending events to nova if there are # any events to send. # Defaults to $::os_service_default # -# [*auth_type*] -# (optional) An authentication type to use with an OpenStack Identity server. -# The value should contain auth plugin name -# Defaults to 'password' -# -# [*username*] -# (optional) Username for connection to nova in admin context -# Defaults to 'nova' -# -# [*project_domain_name*] -# (Optional) Name of domain for $project_name -# Defaults to 'Default' -# -# [*project_name*] -# (optional) Nova project's name -# Defaults to 'services' -# -# [*user_domain_name*] -# (Optional) Name of domain for $username -# Defaults to 'Default' -# -# [*auth_url*] -# (optional) Authorization URL for connection to nova in admin context. -# If version independent identity plugin is used available versions will be -# determined using auth_url -# Defaults to 'http://127.0.0.1:5000' -# -# [*region_name*] -# (optional) Name of nova region to use. Useful if keystone manages more than -# one region. -# Defaults to $::os_service_default -# -# [*endpoint_type*] -# (optional) The type of nova endpoint to use when looking up in -# the keystone catalog. -# Defaults to $::os_service_default -# # [*http_retries*] # (optional) Number of novaclient/ironicclient retries on failed http calls. # Defaults to $::os_service_default # +# DEPRECATED PARAMETERS +# +# [*password*] +# (optional) Password for connection to nova in admin context. +# +# [*notify_nova_on_port_status_changes*] +# (optional) Send notification to nova when port status is active. +# Defaults to undef +# +# [*notify_nova_on_port_data_changes*] +# (optional) Send notifications to nova when port data (fixed_ips/floatingips) +# change so nova can update its cache. +# Defaults to undef +# +# [*auth_type*] +# (optional) An authentication type to use with an OpenStack Identity server. +# The value should contain auth plugin name +# Defaults to undef +# +# [*username*] +# (optional) Username for connection to nova in admin context +# Defaults to undef +# +# [*project_domain_name*] +# (Optional) Name of domain for $project_name +# Defaults to undef +# +# [*project_name*] +# (optional) Nova project's name +# Defaults to undef +# +# [*user_domain_name*] +# (Optional) Name of domain for $username +# Defaults to undef +# +# [*auth_url*] +# (optional) Authorization URL for connection to nova in admin context. +# If version independent identity plugin is used available versions will be +# determined using auth_url +# Defaults to undef +# +# [*region_name*] +# (optional) Name of nova region to use. Useful if keystone manages more than +# one region. +# Defaults to undef +# +# [*endpoint_type*] +# (optional) The type of nova endpoint to use when looking up in +# the keystone catalog. +# Defaults to undef +# class neutron::server::notifications ( - $password, - $notify_nova_on_port_status_changes = true, - $notify_nova_on_port_data_changes = true, $send_events_interval = $::os_service_default, - $auth_type = 'password', - $username = 'nova', - $project_domain_name = 'Default', - $project_name = 'services', - $user_domain_name = 'Default', - $auth_url = 'http://127.0.0.1:5000', - $region_name = $::os_service_default, - $endpoint_type = $::os_service_default, $http_retries = $::os_service_default, + # DEPRECATED PARAMETERS + $password = undef, + $notify_nova_on_port_status_changes = undef, + $notify_nova_on_port_data_changes = undef, + $auth_type = undef, + $username = undef, + $project_domain_name = undef, + $project_name = undef, + $user_domain_name = undef, + $auth_url = undef, + $region_name = undef, + $endpoint_type = undef, ) { include neutron::deps - neutron_config { - 'nova/auth_url': value => $auth_url; - 'nova/username': value => $username; - 'nova/password': value => $password, secret => true; - 'nova/project_domain_name': value => $project_domain_name; - 'nova/project_name': value => $project_name; - 'nova/user_domain_name': value => $user_domain_name; - 'nova/region_name': value => $region_name; - 'nova/endpoint_type': value => $endpoint_type; - 'nova/auth_type': value => $auth_type; - } + # TODO(tkajinam): Remove this when we cleanup deprecated parameters + include neutron::server::notifications::nova neutron_config { - 'DEFAULT/notify_nova_on_port_status_changes': value => $notify_nova_on_port_status_changes; - 'DEFAULT/notify_nova_on_port_data_changes': value => $notify_nova_on_port_data_changes; 'DEFAULT/send_events_interval': value => $send_events_interval; 'DEFAULT/http_retries': value => $http_retries; } diff --git a/manifests/server/notifications/nova.pp b/manifests/server/notifications/nova.pp new file mode 100644 index 000000000..3a37a2076 --- /dev/null +++ b/manifests/server/notifications/nova.pp @@ -0,0 +1,125 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: neutron::server::notifications::nova +# +# Configure notifications to nova +# +# === Parameters +# +# [*password*] +# (required) Password for connection to nova in admin context. +# +# [*notify_nova_on_port_status_changes*] +# (optional) Send notification to nova when port status is active. +# Defaults to $::os_service_default +# +# [*notify_nova_on_port_data_changes*] +# (optional) Send notifications to nova when port data (fixed_ips/floatingips) +# change so nova can update its cache. +# Defaults to $::os_service_default +# +# [*auth_type*] +# (optional) An authentication type to use with an OpenStack Identity server. +# The value should contain auth plugin name +# Defaults to 'password' +# +# [*username*] +# (optional) Username for connection to nova in admin context +# Defaults to 'nova' +# +# [*project_domain_name*] +# (Optional) Name of domain for $project_name +# Defaults to 'Default' +# +# [*project_name*] +# (optional) Nova project's name +# Defaults to 'services' +# +# [*user_domain_name*] +# (Optional) Name of domain for $username +# Defaults to 'Default' +# +# [*auth_url*] +# (optional) Authorization URL for connection to nova in admin context. +# If version independent identity plugin is used available versions will be +# determined using auth_url +# Defaults to 'http://127.0.0.1:5000' +# +# [*region_name*] +# (optional) Name of nova region to use. Useful if keystone manages more than +# one region. +# Defaults to $::os_service_default +# +# [*endpoint_type*] +# (optional) The type of nova endpoint to use when looking up in +# the keystone catalog. +# Defaults to $::os_service_default +# +class neutron::server::notifications::nova ( + $password = undef, + $notify_nova_on_port_status_changes = $::os_service_default, + $notify_nova_on_port_data_changes = $::os_service_default, + $auth_type = 'password', + $username = 'nova', + $project_domain_name = 'Default', + $project_name = 'services', + $user_domain_name = 'Default', + $auth_url = 'http://127.0.0.1:5000', + $region_name = $::os_service_default, + $endpoint_type = $::os_service_default, +) { + + include neutron::deps + + $password_real = pick($::neutron::server::notifications::password, $password) + if $password_real == undef { + fail('password should be set') + } + + $auth_type_real = pick($::neutron::server::notifications::auth_type, $auth_type) + $username_real = pick($::neutron::server::notifications::username, $username) + $project_name_real = pick($::neutron::server::notifications::project_name, $project_name) + $user_domain_name_real = pick( + $::neutron::server::notifications::user_domain_name, + $user_domain_name) + $project_domain_name_real = pick( + $::neutron::server::notifications::project_domain_name, + $project_domain_name) + $auth_url_real = pick($::neutron::server::notifications::auth_url, $auth_url) + $region_name_real = pick($::neutron::server::notifications::region_name, $region_name) + $endpoint_type_real = pick($::neutron::server::notifications::endpoint_type, $endpoint_type) + + neutron_config { + 'nova/auth_url': value => $auth_url_real; + 'nova/username': value => $username_real; + 'nova/password': value => $password_real, secret => true; + 'nova/project_domain_name': value => $project_domain_name_real; + 'nova/project_name': value => $project_name_real; + 'nova/user_domain_name': value => $user_domain_name_real; + 'nova/region_name': value => $region_name_real; + 'nova/endpoint_type': value => $endpoint_type_real; + 'nova/auth_type': value => $auth_type_real; + } + + $notify_nova_on_port_status_changes_real = pick( + $::neutron::server::notifications::notify_nova_on_port_status_changes, + $notify_nova_on_port_status_changes) + $notify_nova_on_port_data_changes_real = pick( + $::neutron::server::notifications::notify_nova_on_port_data_changes, + $notify_nova_on_port_data_changes) + + neutron_config { + 'DEFAULT/notify_nova_on_port_status_changes': value => $notify_nova_on_port_status_changes_real; + 'DEFAULT/notify_nova_on_port_data_changes': value => $notify_nova_on_port_data_changes_real; + } +} diff --git a/releasenotes/notes/server-notifications-nova-4df35db13a4f85c8.yaml b/releasenotes/notes/server-notifications-nova-4df35db13a4f85c8.yaml new file mode 100644 index 000000000..442b135e3 --- /dev/null +++ b/releasenotes/notes/server-notifications-nova-4df35db13a4f85c8.yaml @@ -0,0 +1,22 @@ +--- +features: + - | + The new ``server::notifications::nova`` class has been added to configure + parameters for notifications to nova. +deprecations: + - | + The following parameters in ``server::notifications`` class has been + deprecated and will be removed in a future release. Use the corresponding + parameters in ``server::notifications::nova`` class. + + - ``password`` + - ``auth_type`` + - ``username`` + - ``project_name`` + - ``user_domain_name`` + - ``project_domain_name`` + - ``auth_url`` + - ``region_name`` + - ``endpoint_type`` + - ``notify_nova_on_port_status_changes`` + - ``notify_nova_on_port_data_changes`` diff --git a/spec/classes/neutron_server_notifications_nova_spec.rb b/spec/classes/neutron_server_notifications_nova_spec.rb new file mode 100644 index 000000000..673f66ab9 --- /dev/null +++ b/spec/classes/neutron_server_notifications_nova_spec.rb @@ -0,0 +1,87 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for neutron::server::notifications::nova class +# + +require 'spec_helper' + +describe 'neutron::server::notifications::nova' do + let :params do + { + :auth_type => 'password', + :username => 'nova', + :password => 'secrete', + :project_domain_name => 'Default', + :project_name => 'services', + :user_domain_name => 'Default', + :auth_url => 'http://127.0.0.1:5000', + } + end + + shared_examples 'neutron::server::notifications::nova' do + it 'configure neutron.conf' do + should contain_neutron_config('DEFAULT/notify_nova_on_port_status_changes').with_value('') + should contain_neutron_config('DEFAULT/notify_nova_on_port_data_changes').with_value('') + should contain_neutron_config('nova/auth_url').with_value('http://127.0.0.1:5000') + should contain_neutron_config('nova/auth_type').with_value('password') + should contain_neutron_config('nova/username').with_value('nova') + should contain_neutron_config('nova/password').with_value('secrete').with_secret( true ) + should contain_neutron_config('nova/region_name').with_value('') + should contain_neutron_config('nova/project_domain_name').with_value('Default') + should contain_neutron_config('nova/user_domain_name').with_value('Default') + should contain_neutron_config('nova/endpoint_type').with_value('') + end + + context 'when overriding parameters' do + before :each do + params.merge!( + :notify_nova_on_port_status_changes => false, + :notify_nova_on_port_data_changes => false, + :auth_url => 'http://keystone:5000/v3', + :auth_type => 'password', + :username => 'joe', + :region_name => 'MyRegion', + :project_domain_name => 'Default_1', + :user_domain_name => 'Default_2', + :endpoint_type => 'internal', + ) + end + + it 'should configure neutron server with overrided parameters' do + should contain_neutron_config('DEFAULT/notify_nova_on_port_status_changes').with_value(false) + should contain_neutron_config('DEFAULT/notify_nova_on_port_data_changes').with_value(false) + should contain_neutron_config('nova/auth_url').with_value('http://keystone:5000/v3') + should contain_neutron_config('nova/auth_type').with_value('password') + should contain_neutron_config('nova/username').with_value('joe') + should contain_neutron_config('nova/password').with_value('secrete').with_secret( true ) + should contain_neutron_config('nova/region_name').with_value('MyRegion') + should contain_neutron_config('nova/project_domain_name').with_value('Default_1') + should contain_neutron_config('nova/user_domain_name').with_value('Default_2') + should contain_neutron_config('nova/endpoint_type').with_value('internal') + 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 'neutron::server::notifications::nova' + end + end +end diff --git a/spec/classes/neutron_server_notifications_spec.rb b/spec/classes/neutron_server_notifications_spec.rb index 6e0095b10..8744c9236 100644 --- a/spec/classes/neutron_server_notifications_spec.rb +++ b/spec/classes/neutron_server_notifications_spec.rb @@ -17,66 +17,31 @@ require 'spec_helper' describe 'neutron::server::notifications' do let :params do - { - :notify_nova_on_port_status_changes => true, - :notify_nova_on_port_data_changes => true, - :auth_type => 'password', - :username => 'nova', - :password => 'secrete', - :project_domain_name => 'Default', - :project_name => 'services', - :user_domain_name => 'Default', - :auth_url => 'http://127.0.0.1:5000', - } + {} + end + + let :pre_condition do + "class { 'neutron::server::notifications::nova': + password => 'secrete', + }" end shared_examples 'neutron server notifications' do it 'configure neutron.conf' do - should contain_neutron_config('DEFAULT/notify_nova_on_port_status_changes').with_value(true) - should contain_neutron_config('DEFAULT/notify_nova_on_port_data_changes').with_value(true) should contain_neutron_config('DEFAULT/send_events_interval').with_value('') - should contain_neutron_config('nova/auth_type').with_value('password') - should contain_neutron_config('nova/auth_url').with_value('http://127.0.0.1:5000') - should contain_neutron_config('nova/username').with_value('nova') - should contain_neutron_config('nova/password').with_value('secrete') - should contain_neutron_config('nova/password').with_secret( true ) - should contain_neutron_config('nova/region_name').with_value('') - should contain_neutron_config('nova/project_domain_name').with_value('Default') - should contain_neutron_config('nova/user_domain_name').with_value('Default') - should contain_neutron_config('nova/endpoint_type').with_value('') should contain_neutron_config('DEFAULT/http_retries').with_value('') end context 'when overriding parameters' do before :each do params.merge!( - :notify_nova_on_port_status_changes => false, - :notify_nova_on_port_data_changes => false, - :send_events_interval => '10', - :auth_url => 'http://keystone:5000/v3', - :auth_type => 'password', - :username => 'joe', - :region_name => 'MyRegion', - :project_domain_name => 'Default_1', - :user_domain_name => 'Default_2', - :endpoint_type => 'internal', - :http_retries => 3, + :send_events_interval => '10', + :http_retries => 3, ) end it 'should configure neutron server with overrided parameters' do - should contain_neutron_config('DEFAULT/notify_nova_on_port_status_changes').with_value(false) - should contain_neutron_config('DEFAULT/notify_nova_on_port_data_changes').with_value(false) should contain_neutron_config('DEFAULT/send_events_interval').with_value('10') - should contain_neutron_config('nova/auth_url').with_value('http://keystone:5000/v3') - should contain_neutron_config('nova/auth_type').with_value('password') - should contain_neutron_config('nova/username').with_value('joe') - should contain_neutron_config('nova/password').with_value('secrete') - should contain_neutron_config('nova/password').with_secret( true ) - should contain_neutron_config('nova/region_name').with_value('MyRegion') - should contain_neutron_config('nova/project_domain_name').with_value('Default_1') - should contain_neutron_config('nova/user_domain_name').with_value('Default_2') - should contain_neutron_config('nova/endpoint_type').with_value('internal') should contain_neutron_config('DEFAULT/http_retries').with_value(3) end end