]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Allow db fields configuration without doing the dbsync
authorYanis Guenane <yanis.guenane@enovance.com>
Wed, 19 Feb 2014 18:50:34 +0000 (13:50 -0500)
committerEmilien Macchi <emilien.macchi@enovance.com>
Fri, 21 Feb 2014 07:53:51 +0000 (08:53 +0100)
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
(cherry picked from commit 1aa1d795f0c06bb5266886b8599814e61fbef3f3)

manifests/db.pp
spec/classes/ceilometer_db_spec.rb

index dbe02cd036d8db57177070b8b42ef044a482fff7..1cf955aea0033b105aaba9b86bb78989f0f9f8c0 100644 (file)
@@ -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,
index 793f8b647fae8b45c2b26b35c3cd1c6c64ac359b..aa3610010f91447c05049ce5201d118bb525d15b 100644 (file)
@@ -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