diff --git a/manifests/api.pp b/manifests/api.pp index f4ae85c6..da184d8f 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -84,44 +84,43 @@ class aodh::api ( } if $manage_service { - $api_service_name = $aodh::params::api_service_name - if $api_service_name != 'httpd' and $service_name == $api_service_name { - if $enabled { - $service_ensure = 'running' - } else { - $service_ensure = 'stopped' - } + case $service_name { + 'httpd': { + Service <| title == 'httpd' |> { tag +> 'aodh-service' } - service { 'aodh-api': - ensure => $service_ensure, - name => $api_service_name, - enable => $enabled, - hasstatus => true, - hasrestart => true, - tag => 'aodh-service', - } - # On any paste-api.ini config change, we must restart Aodh API. - Aodh_api_paste_ini<||> ~> Service['aodh-api'] - # On any uwsgi config change, we must restart Aodh API. - Aodh_api_uwsgi_config<||> ~> Service['aodh-api'] - } elsif $service_name == 'httpd' { - Service <| title == 'httpd' |> { tag +> 'aodh-service' } - - if $api_service_name != 'httpd' { - service { 'aodh-api': - ensure => 'stopped', - name => $api_service_name, - enable => false, - tag => 'aodh-service', + if $aodh::params::api_service_name { + service { 'aodh-api': + ensure => 'stopped', + name => $aodh::params::api_service_name, + enable => false, + tag => 'aodh-service', + } + # we need to make sure aodh-api/eventlet is stopped before trying to start apache + Service['aodh-api'] -> Service['httpd'] } - # we need to make sure aodh-api/eventlet is stopped before trying to start apache - Service['aodh-api'] -> Service[$service_name] - } - # On any paste-api.ini config change, we must restart Aodh API. - Aodh_api_paste_ini<||> ~> Service[$service_name] - } else { - fail('Invalid service_name.') + # On any paste-api.ini config change, we must restart Aodh API. + Aodh_api_paste_ini<||> ~> Service['httpd'] + } + default: { + $service_ensure = $enabled ? { + true => 'running', + default => 'stopped', + } + + service { 'aodh-api': + ensure => $service_ensure, + name => $service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'aodh-service', + } + # On any paste-api.ini config change, we must restart Aodh API. + Aodh_api_paste_ini<||> ~> Service['aodh-api'] + # On any uwsgi config change, we must restart Aodh API. + Aodh_api_uwsgi_config<||> ~> Service['aodh-api'] + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 1c89b43e..a47fc8af 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -14,7 +14,7 @@ class aodh::params { 'RedHat': { $common_package_name = 'openstack-aodh-common' $api_package_name = 'openstack-aodh-api' - $api_service_name = 'httpd' + $api_service_name = undef $notifier_package_name = 'openstack-aodh-notifier' $notifier_service_name = 'openstack-aodh-notifier' $evaluator_package_name = 'openstack-aodh-evaluator' @@ -31,7 +31,7 @@ class aodh::params { $api_package_name = 'aodh-api' case $facts['os']['name'] { 'Ubuntu': { - $api_service_name = 'httpd' + $api_service_name = undef } default: { $api_service_name = 'aodh-api' diff --git a/spec/classes/aodh_api_spec.rb b/spec/classes/aodh_api_spec.rb index 346cafb8..435e2997 100644 --- a/spec/classes/aodh_api_spec.rb +++ b/spec/classes/aodh_api_spec.rb @@ -3,22 +3,21 @@ require 'spec_helper' describe 'aodh::api' do let :pre_condition do - "include apache - class { 'aodh': } - include aodh::db - class { 'aodh::keystone::authtoken': - password => 'a_big_secret', - }" - end - - let :params do - { :enabled => true, - :manage_service => true, - :package_ensure => 'latest', + <<-EOS + include apache + class { 'aodh': } + class { 'aodh::keystone::authtoken': + password => 'a_big_secret', } +EOS end shared_examples 'aodh-api' do + let :params do + { + :service_name => 'httpd' + } + end it { is_expected.to contain_class('aodh::deps') } it { is_expected.to contain_class('aodh::params') } @@ -26,7 +25,7 @@ describe 'aodh::api' do it 'installs aodh-api package' do is_expected.to contain_package('aodh-api').with( - :ensure => 'latest', + :ensure => 'present', :name => platform_params[:api_package_name], :tag => ['openstack', 'aodh-package'], ) @@ -91,42 +90,12 @@ describe 'aodh::api' do is_expected.to contain_aodh_config('api/gnocchi_external_domain_name').with_value('MyDomain') end end - - context 'when service_name is not valid' do - before do - params.merge!({ :service_name => 'foobar' }) - end - - let :pre_condition do - "include apache - include aodh::db - class { 'aodh': } - class { 'aodh::keystone::authtoken': - password => 'a_big_secret', - }" - end - - it_raises 'a Puppet::Error', /Invalid service_name/ - end end - - shared_examples_for 'aodh-api without standalone service' do - - let :pre_condition do - "include apache - include aodh::db - class { 'aodh': } - class {'aodh::keystone::authtoken': - password => 'password', - }" - end - - it { is_expected.to_not contain_service('aodh-api') } - end - - shared_examples 'aodh-api with standalone service' do + let :params do + {} + end [{:enabled => true}, {:enabled => false}].each do |param_hash| context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do @@ -136,7 +105,7 @@ describe 'aodh::api' do it 'configures aodh-api service' do is_expected.to contain_service('aodh-api').with( - :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', + :ensure => params[:enabled] ? 'running' : 'stopped', :name => platform_params[:api_service_name], :enable => params[:enabled], :hasstatus => true, @@ -144,12 +113,10 @@ describe 'aodh::api' do :tag => 'aodh-service', ) end - it { is_expected.to contain_service('aodh-api').that_subscribes_to('Anchor[aodh::service::begin]')} - it { is_expected.to contain_service('aodh-api').that_notifies('Anchor[aodh::service::end]')} end end - context 'with disabled service managing' do + context 'with disabled service management' do before do params.merge!({ :manage_service => false, @@ -166,21 +133,12 @@ describe 'aodh::api' do params.merge!({ :service_name => 'httpd' }) end - let :pre_condition do - "include apache - include aodh::db - class { 'aodh': } - class { 'aodh::keystone::authtoken': - password => 'a_big_secret', - }" - end - it 'configures aodh-api service with Apache' do is_expected.to contain_service('aodh-api').with( - :ensure => 'stopped', - :name => platform_params[:api_service_name], - :enable => false, - :tag => 'aodh-service', + :ensure => 'stopped', + :name => platform_params[:api_service_name], + :enable => false, + :tag => 'aodh-service', ) end end @@ -198,25 +156,20 @@ describe 'aodh::api' do case facts[:os]['family'] when 'Debian' if facts[:os]['name'] == 'Ubuntu' - { :api_package_name => 'aodh-api', - :api_service_name => 'httpd' } + { :api_package_name => 'aodh-api' } else { :api_package_name => 'aodh-api', :api_service_name => 'aodh-api' } end when 'RedHat' - { :api_package_name => 'openstack-aodh-api', - :api_service_name => 'httpd' } + { :api_package_name => 'openstack-aodh-api' } end end if facts[:os]['family'] == 'Debian' and facts[:os]['name'] != 'Ubuntu' it_behaves_like 'aodh-api with standalone service' - else - it_behaves_like 'aodh-api without standalone service' end it_behaves_like 'aodh-api' end end - end