From 6d4ff50c5b448f6604d08e1bb2c739ac6aecc857 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Mon, 29 Jun 2015 15:46:13 +0200 Subject: [PATCH] Creation of neutron::db::sync In order to standardize the way dbsync are run across our modules, we create a new class neutron::db::sync. This class will be included if sync_db is enabled. By making this transition the neutron::db::sync class can be returned by the ENC. A use case would be in an highly available environment with 3 galera nodes, include neutron::server on every node with sync_db set to false and have the ENC return ceilometer::db::sync just for one node. Change-Id: I81e824e3e9e8f901b2a0084c7a5ec42c53781864 --- manifests/db/sync.pp | 20 +++++++++++++ manifests/server.pp | 17 +---------- spec/classes/neutron_db_sync_spec.rb | 43 ++++++++++++++++++++++++++++ spec/classes/neutron_server_spec.rb | 12 ++------ 4 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 manifests/db/sync.pp create mode 100644 spec/classes/neutron_db_sync_spec.rb diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp new file mode 100644 index 000000000..82b159108 --- /dev/null +++ b/manifests/db/sync.pp @@ -0,0 +1,20 @@ +# +# Class to execute neutron dbsync +# +class neutron::db::sync { + + include ::neutron::params + + Package<| title == 'neutron-server' |> -> Exec['neutron-db-sync'] + Package<| title == 'neutron' |> -> Exec['neutron-db-sync'] + Neutron_config<||> ~> Exec['neutron-db-sync'] + Neutron_config<| title == 'database/connection' |> ~> Exec['neutron-db-sync'] + Exec['neutron-db-sync'] ~> Service <| title == 'neutron-server' |> + + exec { 'neutron-db-sync': + command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head', + path => '/usr/bin', + refreshonly => true, + logoutput => on_failure, + } +} diff --git a/manifests/server.pp b/manifests/server.pp index d159aa747..7ec84d903 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -281,22 +281,7 @@ class neutron::server ( } if $sync_db { - if ($::neutron::params::server_package) { - # Debian platforms - Package<| title == 'neutron-server' |> ~> Exec['neutron-db-sync'] - } else { - # RH platforms - Package<| title == 'neutron' |> ~> Exec['neutron-db-sync'] - } - - exec { 'neutron-db-sync': - command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head', - path => '/usr/bin', - before => Service['neutron-server'], - subscribe => Neutron_config['database/connection'], - refreshonly => true - } - Neutron_config<||> ~> Exec['neutron-db-sync'] + include ::neutron::db::sync } neutron_config { diff --git a/spec/classes/neutron_db_sync_spec.rb b/spec/classes/neutron_db_sync_spec.rb new file mode 100644 index 000000000..dd6c4248f --- /dev/null +++ b/spec/classes/neutron_db_sync_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe 'neutron::db::sync' do + + shared_examples_for 'neutron-dbsync' do + + it 'runs neutron-db-sync' do + is_expected.to contain_exec('neutron-db-sync').with( + :command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head', + :path => '/usr/bin', + :refreshonly => 'true', + :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 'neutron-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 'neutron-dbsync' + end + +end diff --git a/spec/classes/neutron_server_spec.rb b/spec/classes/neutron_server_spec.rb index 0e256aae1..177c69daa 100644 --- a/spec/classes/neutron_server_spec.rb +++ b/spec/classes/neutron_server_spec.rb @@ -96,7 +96,7 @@ describe 'neutron::server' do :ensure => 'running', :require => 'Class[Neutron]' ) - is_expected.not_to contain_exec('neutron-db-sync') + is_expected.not_to contain_class('neutron::db::sync') is_expected.to contain_neutron_api_config('filter:authtoken/auth_admin_prefix').with( :ensure => 'absent' ) @@ -236,14 +236,8 @@ describe 'neutron::server' do :sync_db => true ) end - it 'should exec neutron-db-sync' do - is_expected.to contain_exec('neutron-db-sync').with( - :command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head', - :path => '/usr/bin', - :before => 'Service[neutron-server]', - :subscribe => 'Neutron_config[database/connection]', - :refreshonly => true - ) + it 'includes neutron::db::sync' do + is_expected.to contain_class('neutron::db::sync') end end