From 1aa1d795f0c06bb5266886b8599814e61fbef3f3 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Wed, 19 Feb 2014 13:50:34 -0500 Subject: [PATCH] Allow db fields configuration without doing the dbsync This commit allows one to configure the db fields without running the actual dbsync command. It remains compliant with the current implementation, leaving exec {'ceilometer-dbsync': in the catalog. One, now, can decide if it wants the dbsync to take place or not. This is useful when one picks mongodb as a backend and wants to use replicaset This way it can scale horizontally and painlessly using the initSync feature of mongodb. With this pattern one can add new member of the replica set easily. Change-Id: I8618bb385147176512fbda1540ba75ac95fccbf1 --- manifests/db.pp | 14 ++++++- spec/classes/ceilometer_db_spec.rb | 60 +++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/manifests/db.pp b/manifests/db.pp index dbe02cd..1cf955a 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -6,8 +6,12 @@ # [*database_connection*] # the connection string. format: [driver]://[user]:[password]@[host]/[database] # +# [*sync_db*] +# enable dbsync. +# class ceilometer::db ( - $database_connection = 'mysql://ceilometer:ceilometer@localhost/ceilometer' + $database_connection = 'mysql://ceilometer:ceilometer@localhost/ceilometer', + $sync_db = true ) { include ceilometer::params @@ -36,6 +40,12 @@ class ceilometer::db ( } } + if $sync_db { + $command = $::ceilometer::params::dbsync_command + } else { + $command = '/bin/true' + } + if $backend_package and !defined(Package[$backend_package]) { package {'ceilometer-backend-package': ensure => present, @@ -50,7 +60,7 @@ class ceilometer::db ( Ceilometer_config['database/connection'] ~> Exec['ceilometer-dbsync'] exec { 'ceilometer-dbsync': - command => $::ceilometer::params::dbsync_command, + command => $command, path => '/usr/bin', user => $::ceilometer::params::username, refreshonly => true, diff --git a/spec/classes/ceilometer_db_spec.rb b/spec/classes/ceilometer_db_spec.rb index 793f8b6..aa36100 100644 --- a/spec/classes/ceilometer_db_spec.rb +++ b/spec/classes/ceilometer_db_spec.rb @@ -9,7 +9,8 @@ describe 'ceilometer::db' do end let :params do - { :database_connection => 'mongodb://localhost:1234/ceilometer' } + { :database_connection => 'mongodb://localhost:1234/ceilometer', + :sync_db => true } end it { should contain_class('ceilometer::params') } @@ -20,6 +21,15 @@ describe 'ceilometer::db' do :name => 'python-pymongo') should contain_ceilometer_config('database/connection').with_value('mongodb://localhost:1234/ceilometer') end + + it 'runs ceilometer-dbsync' do + should contain_exec('ceilometer-dbsync').with( + :command => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end end # Fedora > 18 has python-pymongo too @@ -32,7 +42,8 @@ describe 'ceilometer::db' do end let :params do - { :database_connection => 'mongodb://localhost:1234/ceilometer' } + { :database_connection => 'mongodb://localhost:1234/ceilometer', + :sync_db => false } end it { should contain_class('ceilometer::params') } @@ -43,6 +54,15 @@ describe 'ceilometer::db' do :name => 'python-pymongo') should contain_ceilometer_config('database/connection').with_value('mongodb://localhost:1234/ceilometer') end + + it 'runs ceilometer-dbsync' do + should contain_exec('ceilometer-dbsync').with( + :command => '/bin/true', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end end # RHEL has python-pymongo too @@ -55,7 +75,8 @@ describe 'ceilometer::db' do end let :params do - { :database_connection => 'mongodb://localhost:1234/ceilometer' } + { :database_connection => 'mongodb://localhost:1234/ceilometer', + :sync_db => true } end it { should contain_class('ceilometer::params') } @@ -65,6 +86,15 @@ describe 'ceilometer::db' do :ensure => 'present', :name => 'python-pymongo') end + + it 'runs ceilometer-dbsync' do + should contain_exec('ceilometer-dbsync').with( + :command => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end end # RHEL has python-sqlite2 @@ -77,7 +107,8 @@ describe 'ceilometer::db' do end let :params do - { :database_connection => 'sqlite:///var/lib/ceilometer.db' } + { :database_connection => 'sqlite:///var/lib/ceilometer.db', + :sync_db => false } end it { should contain_class('ceilometer::params') } @@ -88,6 +119,15 @@ describe 'ceilometer::db' do :name => 'python-sqlite2') should contain_ceilometer_config('database/connection').with_value('sqlite:///var/lib/ceilometer.db') end + + it 'runs ceilometer-dbsync' do + should contain_exec('ceilometer-dbsync').with( + :command => '/bin/true', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end end # debian has "python-pysqlite2" @@ -97,7 +137,8 @@ describe 'ceilometer::db' do end let :params do - { :database_connection => 'sqlite:///var/lib/ceilometer.db' } + { :database_connection => 'sqlite:///var/lib/ceilometer.db', + :sync_db => true } end it { should contain_class('ceilometer::params') } @@ -107,6 +148,15 @@ describe 'ceilometer::db' do :ensure => 'present', :name => 'python-pysqlite2') end + + it 'runs ceilometer-dbsync' do + should contain_exec('ceilometer-dbsync').with( + :command => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf', + :path => '/usr/bin', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + end end end -- 2.45.2