From 16a00799a9adc19b71359a5b9b0eba1030ad08b4 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sat, 21 Nov 2015 17:35:49 -0500 Subject: [PATCH] Update mistral::db::sync to run 'update head' This patch modifies mistral::db::sync so that it runs 'update head' in addition to 'populate'. This brings the mistral "db_sync" class more inline with other Puppet Openstack modules that run DB sync and fixes issues in bootstrapping mistral in that running populate without first having an 'upgrade head' would always fail. Both actions appear to be idempotent so re-running them should be fine. Change-Id: I13f037c3eea944d5f41ced904623e38ce3fcae44 --- manifests/db/postgresql.pp | 2 +- manifests/db/sync.pp | 35 +++++++++++++----- manifests/params.pp | 4 ++- spec/classes/mistral_db_sync_spec.rb | 53 ++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 spec/classes/mistral_db_sync_spec.rb diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index 241c3eb..7851c70 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -50,6 +50,6 @@ class mistral::db::postgresql( privileges => $privileges, } - ::Openstacklib::Db::Postgresql['mistral'] ~> Exec<| title == 'mistral-dbsync' |> + ::Openstacklib::Db::Postgresql['mistral'] ~> Exec<| title == 'mistral-db-sync' |> } diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index 038bfaa..e64c065 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -1,15 +1,34 @@ # -# Class to execute "mistral-dbsync" +# Class to execute "mistral-db-manage 'upgrade head' and 'populate'" # class mistral::db::sync { - exec { 'mistral-dbsync': - command => $::mistral::params::dbsync_command, - path => '/usr/bin', - user => 'mistral', - logoutput => on_failure, - subscribe => File[$::mistral::params::mistral_conf], + include ::mistral::params + + Package<| tag =='mistral-common' |> ~> Exec['mistral-db-sync'] + Exec['mistral-db-sync'] ~> Service<| tag == 'mistral-service' |> + Mistral_config <||> -> Exec['mistral-db-sync'] + Mistral_config <| title == 'database/connection' |> ~> Exec['mistral-db-sync'] + + exec { 'mistral-db-sync': + command => $::mistral::params::db_sync_command, + path => '/usr/bin', + user => 'mistral', + logoutput => on_failure, + refreshonly => true, + } + + Exec['mistral-db-sync'] -> Exec['mistral-db-populate'] + Package<| tag =='mistral-common' |> ~> Exec['mistral-db-populate'] + Exec['mistral-db-populate'] ~> Service<| tag == 'mistral-service' |> + Mistral_config <||> -> Exec['mistral-db-populate'] + Mistral_config <| title == 'database/connection' |> ~> Exec['mistral-db-populate'] + exec { 'mistral-db-populate': + command => $::mistral::params::db_populate_command, + path => '/usr/bin', + user => 'mistral', + logoutput => on_failure, + refreshonly => true, } - Exec['mistral-dbsync'] ~> Service<| title == 'mistral' |> } diff --git a/manifests/params.pp b/manifests/params.pp index 68ba211..b198603 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,11 +3,13 @@ # Parameters for puppet-mistral # class mistral::params { + $mistral_conf_dir = '/etc/mistral' $mistral_conf = "${mistral_conf_dir}/mistral.conf" $client_package = 'python-mistralclient' $log_dir ='/var/log/mistral' - $dbsync_command = "/usr/bin/python /usr/bin/mistral-db-manage --config-file=${mistral_conf} populate" + $db_sync_command = "mistral-db-manage --config-file=${mistral_conf} upgrade head" + $db_populate_command = "mistral-db-manage --config-file=${mistral_conf} populate" $update_service_command = '/usr/bin/systemctl daemon-reload' case $::osfamily { diff --git a/spec/classes/mistral_db_sync_spec.rb b/spec/classes/mistral_db_sync_spec.rb new file mode 100644 index 0000000..a64c040 --- /dev/null +++ b/spec/classes/mistral_db_sync_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'mistral::db::sync' do + + shared_examples_for 'mistral-db-sync' do + + it 'runs mistral-db-manage upgrade head' do + + is_expected.to contain_exec('mistral-db-sync').with( + :command => 'mistral-db-manage --config-file=/etc/mistral/mistral.conf upgrade head', + :path => '/usr/bin', + :user => 'mistral', + :refreshonly => 'true', + :logoutput => 'on_failure' + ) + + is_expected.to contain_exec('mistral-db-populate').with( + :command => 'mistral-db-manage --config-file=/etc/mistral/mistral.conf populate', + :path => '/usr/bin', + :user => 'mistral', + :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 'mistral-db-sync' + end + + context 'on a Debian osfamily' do + let :facts do + { + :operatingsystemrelease => '8.0', + :osfamily => 'Debian', + :concat_basedir => '/var/lib/puppet/concat' + } + end + + it_configures 'mistral-db-sync' + end + +end