diff --git a/examples/aodh.pp b/examples/aodh.pp index 2d6179975..1dcb65eb8 100644 --- a/examples/aodh.pp +++ b/examples/aodh.pp @@ -14,4 +14,5 @@ } class { '::aodh::evaluator': } class { '::aodh::notifier': } +class { '::aodh::listener': } class { '::aodh::client': } diff --git a/manifests/listener.pp b/manifests/listener.pp new file mode 100644 index 000000000..5a532d326 --- /dev/null +++ b/manifests/listener.pp @@ -0,0 +1,48 @@ +# Installs the aodh listener service +# +# == Params +# [*enabled*] +# (optional) Should the service be enabled. +# Defaults to true. +# +# [*manage_service*] +# (optional) Whether the service should be managed by Puppet. +# Defaults to true. +# +# [*package_ensure*] +# (optional) ensure state for package. +# Defaults to 'present' +# +class aodh::listener ( + $manage_service = true, + $enabled = true, + $package_ensure = 'present', +) { + + include ::aodh::params + + Aodh_config<||> ~> Service['aodh-listener'] + + Package[$::aodh::params::listener_package_name] -> Service['aodh-listener'] + ensure_resource( 'package', [$::aodh::params::listener_package_name], + { ensure => $package_ensure } + ) + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + } + + Package['aodh'] -> Service['aodh-listener'] + service { 'aodh-listener': + ensure => $service_ensure, + name => $::aodh::params::listener_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'aodh-service', + } +} diff --git a/spec/acceptance/aodh_wsgi_apache_spec.rb b/spec/acceptance/aodh_wsgi_apache_spec.rb index 8e2e54cbe..3c4f98451 100644 --- a/spec/acceptance/aodh_wsgi_apache_spec.rb +++ b/spec/acceptance/aodh_wsgi_apache_spec.rb @@ -125,6 +125,7 @@ class { '::aodh::auth': } class { '::aodh::client': } class { '::aodh::notifier': } + class { '::aodh::listener': } case $::osfamily { 'Debian': { warning('aodh-evaluator cannot be run on ubuntu system, package is broken. See LP#1508463') diff --git a/spec/classes/aodh_listener_spec.rb b/spec/classes/aodh_listener_spec.rb new file mode 100644 index 000000000..91cb27e52 --- /dev/null +++ b/spec/classes/aodh_listener_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' +# LP1492636 - Cohabitation of compile matcher and webmock +WebMock.disable_net_connect!(:allow => "169.254.169.254") + +describe 'aodh::listener' do + + let :pre_condition do + "class { '::aodh': }" + end + + shared_examples_for 'aodh-listener' do + + context 'when enabled' do + it { is_expected.to contain_class('aodh::params') } + + it 'installs aodh-listener package' do + is_expected.to contain_package(platform_params[:listener_package_name]).with( + :ensure => 'present' + ) + end + + it 'configures aodh-listener service' do + is_expected.to contain_service('aodh-listener').with( + :ensure => 'running', + :name => platform_params[:listener_service_name], + :enable => true, + :hasstatus => true, + :hasrestart => true, + :tag => 'aodh-service', + ) + end + + end + + context 'when disabled' do + let :params do + { :enabled => false } + end + + # Catalog compilation does not crash for lack of aodh::db + it { is_expected.to compile } + it 'configures aodh-listener service' do + is_expected.to contain_service('aodh-listener').with( + :ensure => 'stopped', + :name => platform_params[:listener_service_name], + :enable => false, + :hasstatus => true, + :hasrestart => true, + :tag => 'aodh-service', + ) + end + end + + context 'when service management is disabled' do + let :params do + { :enabled => false, + :manage_service => false } + end + + it 'configures aodh-listener service' do + is_expected.to contain_service('aodh-listener').with( + :ensure => nil, + :name => platform_params[:listener_service_name], + :enable => false, + :hasstatus => true, + :hasrestart => true, + :tag => 'aodh-service', + ) + end + end + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian' } + end + + let :platform_params do + { :listener_package_name => 'aodh-listener', + :listener_service_name => 'aodh-listener' } + end + + it_configures 'aodh-listener' + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + + let :platform_params do + { :listener_package_name => 'openstack-aodh-listener', + :listener_service_name => 'openstack-aodh-listener' } + end + + it_configures 'aodh-listener' + end +end