]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Creation of ceilometer::db::sync
authorYanis Guenane <yguenane@redhat.com>
Wed, 22 Jul 2015 12:53:29 +0000 (14:53 +0200)
committerYanis Guenane <yguenane@redhat.com>
Mon, 17 Aug 2015 08:09:41 +0000 (10:09 +0200)
In order to standardize the way dbsync are run across our modules,
we create a new class ceilometer::db::sync.
This class will be included if sync_db is enabled.

By making this transition the ceilometer::db::sync can be returned
by the ENC.

A use case would be in an highly available environment, with 3 galera
nodes, include ceilometer::db on every node with sync_db set to false
and have the ENC return ceilometer::db::sync just for one node.

Change-Id: I410f41fb4e61be848372820cdeb2110efc327161

manifests/api.pp
manifests/collector.pp
manifests/db.pp
manifests/db/sync.pp [new file with mode: 0644]
spec/classes/ceilometer_api_spec.rb
spec/classes/ceilometer_collector_spec.rb
spec/classes/ceilometer_db_spec.rb
spec/classes/ceilometer_db_sync_spec.rb [new file with mode: 0644]

index cc67d6f989e038a61cad9da2e0e5d9f4484dfa18..7347c2c88f0514e15f782f98ba36d999b72c692f 100644 (file)
@@ -115,6 +115,7 @@ class ceilometer::api (
       $service_ensure = 'stopped'
     }
   }
+
   Package['ceilometer-common'] -> Service[$service_name]
 
   if $service_name == $::ceilometer::params::api_service_name {
index c651a01bbd536c7ac5c887d21110d7b270f2f8fd..8e22a93eba0908d7a93d6909e30d93ebd2efb971 100644 (file)
@@ -53,8 +53,6 @@ class ceilometer::collector (
   if $manage_service {
     if $enabled {
       $service_ensure = 'running'
-      Class['ceilometer::db'] -> Service['ceilometer-collector']
-      Exec['ceilometer-dbsync'] ~> Service['ceilometer-collector']
     } else {
       $service_ensure = 'stopped'
     }
index fd121d99af7e41fbb2538da0f37844831dded700..a6acd77d1501fee522f0a5907d5f6adb1504db83 100644 (file)
@@ -50,12 +50,6 @@ 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,
@@ -68,15 +62,8 @@ class ceilometer::db (
     'database/connection': value => $database_connection, secret => true;
   }
 
-  Ceilometer_config['database/connection'] ~> Exec['ceilometer-dbsync']
-
-  exec { 'ceilometer-dbsync':
-    command     => $command,
-    path        => '/usr/bin',
-    user        => $::ceilometer::params::user,
-    refreshonly => true,
-    logoutput   => on_failure,
-    subscribe   => Ceilometer_config['database/connection']
+  if $sync_db {
+    include ::ceilometer::db::sync
   }
 
 }
diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp
new file mode 100644 (file)
index 0000000..fd9d7fa
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Class to execute ceilometer dbsync
+#
+class ceilometer::db::sync {
+
+  include ::ceilometer::params
+
+  Package<| tag == 'ceilometer-package' |> ~> Exec['ceilometer-dbsync']
+  Exec['ceilometer-dbsync'] ~> Service <| tag == 'ceilometer-service' |>
+
+  Ceilometer_config<||> -> Exec['ceilometer-dbsync']
+  Ceilometer_config<| title == 'database/connection' |> ~> Exec['ceilometer-dbsync']
+
+  exec { 'ceilometer-dbsync':
+    command     => $::ceilometer::params::dbsync_command,
+    path        => '/usr/bin',
+    user        => $::ceilometer::params::user,
+    refreshonly => true,
+    logoutput   => on_failure,
+  }
+
+}
index e9f7f3d13ff2ea21c26a10d57c7edd9b1b07eee7..094e2181bea31a808bd954e9ad5ca06f379ba882 100644 (file)
@@ -91,7 +91,6 @@ describe 'ceilometer::api' do
             :hasstatus  => true,
             :hasrestart => true,
             :require    => 'Class[Ceilometer::Db]',
-            :subscribe  => 'Exec[ceilometer-dbsync]',
             :tag        => 'ceilometer-service',
           )
         end
index bd7a9e2c79f077b8ed99191987c7bbc932017441..6a0ade1cac8facc78babbab5b7b48da044f3102d 100644 (file)
@@ -69,10 +69,6 @@ describe 'ceilometer::collector' do
         )
       end
 
-      it 'configures relationships on database' do
-        is_expected.to contain_class('ceilometer::db').with_before(['Service[ceilometer-collector]'])
-        is_expected.to contain_exec('ceilometer-dbsync').with_notify(['Service[ceilometer-collector]'])
-      end
     end
 
     context 'when disabled' do
index a4c897fd140d3fea3fe392f2573ac36fb39d9b29..da580ecd83c565ff3b601b6036b4a09c4b89ea82 100644 (file)
@@ -25,14 +25,8 @@ describe 'ceilometer::db' do
       is_expected.to contain_ceilometer_config('database/connection').with_value( params[:database_connection] ).with_secret(true)
     end
 
-    it 'runs ceilometer-dbsync' do
-      is_expected.to contain_exec('ceilometer-dbsync').with(
-        :command     => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf',
-        :path        => '/usr/bin',
-        :refreshonly => 'true',
-        :user        => 'ceilometer',
-        :logoutput   => 'on_failure'
-      )
+    it 'includes ceilometer::db::sync' do
+      is_expected.to contain_class('ceilometer::db::sync')
     end
   end
 
@@ -59,14 +53,8 @@ describe 'ceilometer::db' do
       is_expected.to contain_ceilometer_config('database/connection').with_value( params[:database_connection] ).with_secret(true)
     end
 
-    it 'runs ceilometer-dbsync' do
-      is_expected.to contain_exec('ceilometer-dbsync').with(
-        :command     => '/bin/true',
-        :path        => '/usr/bin',
-        :refreshonly => 'true',
-        :user        => 'ceilometer',
-        :logoutput   => 'on_failure'
-      )
+    it 'does not include ceilometer::db::sync' do
+      is_expected.not_to contain_class('ceilometer::db::sync')
     end
   end
 
@@ -92,14 +80,8 @@ describe 'ceilometer::db' do
         :name => 'python-pymongo')
     end
 
-    it 'runs ceilometer-dbsync' do
-      is_expected.to contain_exec('ceilometer-dbsync').with(
-        :command     => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf',
-        :path        => '/usr/bin',
-        :refreshonly => 'true',
-        :user        => 'ceilometer',
-        :logoutput   => 'on_failure'
-      )
+    it 'includes ceilometer::db::sync' do
+      is_expected.to contain_class('ceilometer::db::sync')
     end
   end
 
@@ -124,14 +106,8 @@ describe 'ceilometer::db' do
       is_expected.to contain_ceilometer_config('database/connection').with_value( params[:database_connection] ).with_secret(true)
     end
 
-    it 'runs ceilometer-dbsync' do
-      is_expected.to contain_exec('ceilometer-dbsync').with(
-        :command     => '/bin/true',
-        :path        => '/usr/bin',
-        :refreshonly => 'true',
-        :user        => 'ceilometer',
-        :logoutput   => 'on_failure'
-      )
+    it 'does not include ceilomter::db::sync' do
+      is_expected.not_to contain_class('ceilometer::db::sync')
     end
   end
 
@@ -154,14 +130,8 @@ describe 'ceilometer::db' do
         :name => 'python-pysqlite2')
     end
 
-    it 'runs ceilometer-dbsync' do
-      is_expected.to contain_exec('ceilometer-dbsync').with(
-        :command     => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf',
-        :path        => '/usr/bin',
-        :refreshonly => 'true',
-        :user        => 'ceilometer',
-        :logoutput   => 'on_failure'
-      )
+    it 'includes ceilometer::db::sync' do
+      is_expected.to contain_class('ceilometer::db::sync')
     end
   end
 
diff --git a/spec/classes/ceilometer_db_sync_spec.rb b/spec/classes/ceilometer_db_sync_spec.rb
new file mode 100644 (file)
index 0000000..9e3761b
--- /dev/null
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe 'ceilometer::db::sync' do
+
+  shared_examples_for 'ceilometer-dbsync' do
+
+    it 'runs ceilometer-dbsync' do
+      is_expected.to contain_exec('ceilometer-dbsync').with(
+        :command     => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf',
+        :path        => '/usr/bin',
+        :refreshonly => 'true',
+        :user        => 'ceilometer',
+        :logoutput   => 'on_failure'
+      )
+    end
+
+  end
+
+  context 'on a RedHat osfamily' do
+    let :facts do
+      {
+        :osfamily                 => 'RedHat',
+        :operatingsystemrelease   => '7.0',
+        :concat_basedir => '/var/lib/puppet/concat'
+      }
+    end
+
+    it_configures 'ceilometer-dbsync'
+  end
+
+  context 'on a Debian osfamily' do
+    let :facts do
+      {
+        :operatingsystemrelease => '7.8',
+        :operatingsystem        => 'Debian',
+        :osfamily               => 'Debian',
+        :concat_basedir => '/var/lib/puppet/concat'
+      }
+    end
+
+    it_configures 'ceilometer-dbsync'
+  end
+
+end