diff --git a/manifests/coordination.pp b/manifests/coordination.pp new file mode 100644 index 00000000..bc6cf3d6 --- /dev/null +++ b/manifests/coordination.pp @@ -0,0 +1,46 @@ +# == Class: aodh::coordination +# +# Setup and configure Aodh coordination settings. +# +# === Parameters +# +# [*backend_url*] +# (Optional) Coordination backend URL. +# Defaults to $::os_service_default +# +# [*heartbeat*] +# (Optional) Number of seconds between hearbeats for distributed +# coordintation. +# Defaults to $::os_service_default +# +# [*retry_backoff*] +# (Optional) Retry backoff factor when retrying to connect with coordination +# backend. +# Defaults to $::os_service_default +# +# [*max_retry_interval*] +# (Optional) Maximum number of seconds between retry to join partitioning +# group +# Defaults to $::os_service_default +# +class aodh::coordination ( + $backend_url = $::os_service_default, + $heartbeat = $::os_service_default, + $retry_backoff = $::os_service_default, + $max_retry_interval = $::os_service_default, +) { + + include aodh::deps + + $backend_url_real = pick($::aodh::evaluator::coordination_url, $backend_url) + + oslo::coordination{ 'aodh_config': + backend_url => $backend_url_real + } + + aodh_config { + 'coordination/heartbeat': value => $heartbeat; + 'coordination/retry_backoff': value => $retry_backoff; + 'coordination/max_retry_interval': value => $max_retry_interval; + } +} diff --git a/manifests/evaluator.pp b/manifests/evaluator.pp index 8b21ed94..e39e4f96 100644 --- a/manifests/evaluator.pp +++ b/manifests/evaluator.pp @@ -17,52 +17,37 @@ # (optional) Number of workers for evaluator service. # Defaults to $::os_workers. # -# [*coordination_url*] -# (optional) The url to use for distributed group membership coordination. -# Defaults to $::os_service_default. -# # [*evaluation_interval*] # (optional) Period of evaluation cycle # Defaults to $::os_service_default. # +# DEPRECATED PARAMETERS +# +# [*coordination_url*] +# (optional) The url to use for distributed group membership coordination. +# Defaults to undef. +# class aodh::evaluator ( $manage_service = true, $enabled = true, $package_ensure = 'present', $workers = $::os_workers, - $coordination_url = $::os_service_default, $evaluation_interval = $::os_service_default, + # DEPRECATED PARAMETERS + $coordination_url = undef, ) { include aodh::deps include aodh::params - if !$coordination_url { - warning('Use $::os_service_default for the coordination_url parameter. \ -The current behavior will be changed in a future release') - $coordination_url_real = $::os_service_default - } else { - $coordination_url_real = $coordination_url - } - - if is_service_default($coordination_url_real) and !is_service_default($workers) and $workers > 1 { - warning('coordination_url should be set to use multiple workers') - $workers_real = $::os_service_default - } else { - $workers_real = $workers + if $coordination_url != undef { + warning('The coordination_url parameter is deprecated. Use the aodh::coordination class instead') + include aodh::coordination } aodh_config { 'DEFAULT/evaluation_interval' : value => $evaluation_interval; - 'evaluator/workers' : value => $workers_real; - 'coordination/backend_url' : value => $coordination_url_real; - } - - if !is_service_default($coordination_url_real) and ($coordination_url_real =~ /^redis/ ) { - ensure_packages('python-redis', { - name => $::aodh::params::redis_package_name, - tag => 'openstack', - }) + 'evaluator/workers' : value => $workers; } ensure_packages($::aodh::params::evaluator_package_name, { diff --git a/manifests/params.pp b/manifests/params.pp index c263df46..43769999 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -22,7 +22,6 @@ class aodh::params { $listener_service_name = 'openstack-aodh-listener' $aodh_wsgi_script_dir = '/var/www/cgi-bin/aodh' $aodh_wsgi_script_source = '/usr/bin/aodh-api' - $redis_package_name = 'python3-redis' } 'Debian': { $common_package_name = 'aodh-common' @@ -45,7 +44,6 @@ class aodh::params { $listener_service_name = 'aodh-listener' $aodh_wsgi_script_dir = '/usr/lib/cgi-bin/aodh' $aodh_wsgi_script_source = '/usr/share/aodh/app.wsgi' - $redis_package_name = 'python3-redis' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, \ diff --git a/releasenotes/notes/coordination-aee30fff3b537d61.yaml b/releasenotes/notes/coordination-aee30fff3b537d61.yaml new file mode 100644 index 00000000..b0b25f33 --- /dev/null +++ b/releasenotes/notes/coordination-aee30fff3b537d61.yaml @@ -0,0 +1,15 @@ +--- +features: + - | + The new ``aodh::coordination`` class has been added. + +upgrade: + - | + The ``aodh::evaluator`` class no longer adjust workers based on + the ``coordination_url`` parameter. Please set the corrdination backend + if multiple workers are used. + +deprecations: + - | + The ``aodh::evaluator::coordination_url`` parameter has been deprecated in + favor of the new ``aodh::coordination`` class. diff --git a/spec/classes/aodh_coordination_spec.rb b/spec/classes/aodh_coordination_spec.rb new file mode 100644 index 00000000..283d59de --- /dev/null +++ b/spec/classes/aodh_coordination_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe 'aodh::coordination' do + shared_examples 'aodh::coordination' do + context 'with default parameters' do + it { + is_expected.to contain_oslo__coordination('aodh_config').with( + :backend_url => '' + ) + is_expected.to contain_aodh_config('coordination/heartbeat').with_value('') + is_expected.to contain_aodh_config('coordination/retry_backoff').with_value('') + is_expected.to contain_aodh_config('coordination/max_retry_interval').with_value('') + } + end + + context 'with specified parameters' do + let :params do + { + :backend_url => 'etcd3+http://127.0.0.1:2379', + :heartbeat => 1, + :retry_backoff => 1, + :max_retry_interval => 30, + } + end + + it { + is_expected.to contain_oslo__coordination('aodh_config').with( + :backend_url => 'etcd3+http://127.0.0.1:2379' + ) + is_expected.to contain_aodh_config('coordination/heartbeat').with_value(1) + is_expected.to contain_aodh_config('coordination/retry_backoff').with_value(1) + is_expected.to contain_aodh_config('coordination/max_retry_interval').with_value(30) + } + 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 'aodh::coordination' + end + end +end diff --git a/spec/classes/aodh_evaluator_spec.rb b/spec/classes/aodh_evaluator_spec.rb index 7dd139a5..dabaae09 100644 --- a/spec/classes/aodh_evaluator_spec.rb +++ b/spec/classes/aodh_evaluator_spec.rb @@ -2,47 +2,22 @@ require 'spec_helper' describe 'aodh::evaluator' do - let :pre_condition do - "class { '::aodh': }" - end - let :params do { :enabled => true } end shared_examples_for 'aodh-evaluator' do - context 'with coordination' do - before do - params.merge!({ :coordination_url => 'redis://localhost:6379' }) - end - - it 'configures backend_url' do - is_expected.to contain_aodh_config('coordination/backend_url').with_value('redis://localhost:6379') - end - - it 'configures workers' do + context 'with defaults' do + it 'configures defaults' do is_expected.to contain_aodh_config('evaluator/workers').with_value(4) - end - - it 'installs python-redis package' do - is_expected.to contain_package('python-redis').with( - :name => platform_params[:redis_package_name], - :tag => 'openstack' - ) + is_expected.to contain_aodh_config('DEFAULT/evaluation_interval').with_value('') end end - context 'with coordination and workers' do + context 'with workers' do before do - params.merge!({ - :coordination_url => 'redis://localhost:6379', - :workers => 8, - }) - end - - it 'configures backend_url' do - is_expected.to contain_aodh_config('coordination/backend_url').with_value('redis://localhost:6379') + params.merge!({ :workers => 8 }) end it 'configures workers' do @@ -59,12 +34,13 @@ describe 'aodh::evaluator' do end end - context 'with workers' do + context 'with deprecated coordination_url' do before do - params.merge!({ :workers => 8 }) + params.merge!({ :coordination_url => 'redis://localhost:6379' }) end - it 'does not configure workers' do - is_expected.to contain_aodh_config('evaluator/workers').with_value('') + it 'configures coordination and workers' do + is_expected.to contain_aodh_config('coordination/backend_url').with_value('redis://localhost:6379') + is_expected.to contain_aodh_config('evaluator/workers').with_value(4) end end @@ -91,8 +67,7 @@ describe 'aodh::evaluator' do it 'sets default values' do is_expected.to contain_aodh_config('DEFAULT/evaluation_interval').with_value('') - is_expected.to contain_aodh_config('evaluator/workers').with_value('') - is_expected.to contain_aodh_config('coordination/backend_url').with_value('') + is_expected.to contain_aodh_config('evaluator/workers').with_value(4) end end @@ -139,12 +114,10 @@ describe 'aodh::evaluator' do case facts[:osfamily] when 'Debian' { :evaluator_package_name => 'aodh-evaluator', - :evaluator_service_name => 'aodh-evaluator', - :redis_package_name => 'python3-redis' } + :evaluator_service_name => 'aodh-evaluator' } when 'RedHat' { :evaluator_package_name => 'openstack-aodh-evaluator', - :evaluator_service_name => 'openstack-aodh-evaluator', - :redis_package_name => 'python3-redis' } + :evaluator_service_name => 'openstack-aodh-evaluator' } end end it_configures 'aodh-evaluator'