From 43ad68554622888d593c9b08c54f09dd962fc5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Gagne=CC=81?= Date: Tue, 5 Aug 2014 11:58:27 -0400 Subject: [PATCH] Add ability to disable ceilometer-collector without db You are no longer required to include ceilometer::db when disabling ceilometer-collector using the enabled parameter. The relationships with any database resources are now only enforced when the service is enabled. Closes-bug: #1352958 Change-Id: I00a5e651184788acdd30de1908e2bf38566f78e1 (cherry picked from commit 8c9f4fcd53e4ef0fb7694de6dce6e001c7e8cf7d) --- manifests/collector.pp | 6 ++-- spec/classes/ceilometer_collector_spec.rb | 44 ++++++++++++++++------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/manifests/collector.pp b/manifests/collector.pp index cc0661f69..2506efbe7 100644 --- a/manifests/collector.pp +++ b/manifests/collector.pp @@ -17,6 +17,8 @@ if $enabled { $service_ensure = 'running' + Class['ceilometer::db'] -> Service['ceilometer-collector'] + Exec['ceilometer-dbsync'] ~> Service['ceilometer-collector'] } else { $service_ensure = 'stopped' } @@ -27,8 +29,6 @@ name => $::ceilometer::params::collector_service_name, enable => $enabled, hasstatus => true, - hasrestart => true, - require => Class['ceilometer::db'], - subscribe => Exec['ceilometer-dbsync'] + hasrestart => true } } diff --git a/spec/classes/ceilometer_collector_spec.rb b/spec/classes/ceilometer_collector_spec.rb index 5bb8e20b1..25e6d650b 100644 --- a/spec/classes/ceilometer_collector_spec.rb +++ b/spec/classes/ceilometer_collector_spec.rb @@ -8,22 +8,40 @@ shared_examples_for 'ceilometer-collector' do - it { should contain_class('ceilometer::params') } + context 'when enabled' do + before do + pre_condition << "class { 'ceilometer::db': }" + end - it 'installs ceilometer-collector package' do - should contain_package(platform_params[:collector_package_name]) + it { should contain_class('ceilometer::params') } + + it 'installs ceilometer-collector package' do + should contain_package(platform_params[:collector_package_name]) + end + + it 'configures ceilometer-collector service' do + should contain_service('ceilometer-collector').with( + :ensure => 'running', + :name => platform_params[:collector_service_name], + :enable => true, + :hasstatus => true, + :hasrestart => true + ) + end + + it 'configures relationships on database' do + should contain_class('ceilometer::db').with_before('Service[ceilometer-collector]') + should contain_exec('ceilometer-dbsync').with_notify('Service[ceilometer-collector]') + end end - it 'configures ceilometer-collector service' do - should contain_service('ceilometer-collector').with( - :ensure => 'running', - :name => platform_params[:collector_service_name], - :enable => true, - :hasstatus => true, - :hasrestart => true, - :require => 'Class[Ceilometer::Db]', - :subscribe => 'Exec[ceilometer-dbsync]' - ) + context 'when disabled' do + let :params do + { :enabled => false } + end + + # Catalog compilation does not crash for lack of ceilometer::db + it { should compile } end end