From 399172e19205267fc4326b4bbea620124ded3663 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 10 Jan 2023 13:50:48 +0900 Subject: [PATCH] Support db schema upgrade The rally db command provides the separate upgrade subcommand to upgrade schema of existing database. This change provides the option to use the upgrade command instead of the create command so that users can use the sync class for schema upgrade. Change-Id: I778381879c9aa6c790423262c90142a6b383c252 --- manifests/db/sync.pp | 14 +++++++++- .../notes/db-upgrade-07d90ec4fc07f990.yaml | 6 +++++ spec/classes/rally_db_sync_spec.rb | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/db-upgrade-07d90ec4fc07f990.yaml diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index e115428..ac4082c 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -13,15 +13,27 @@ # (Optional) Timeout for the execution of the db_sync # Defaults to 300 # +# [*upgrade*] +# (Optional) Run rally db upgrade command instead of rally db create command. +# Defaults to false +# class rally::db::sync( $extra_params = '--config-file /etc/rally/rally.conf', $db_sync_timeout = 300, + $upgrade = false, ) { include rally::deps + validate_legacy(Boolean, 'validate_bool', $upgrade) + + $subcommand = $upgrade ? { + true => 'upgrade', + default => 'create' + } + exec { 'rally db_sync': - command => "rally ${extra_params} db create", + command => "rally ${extra_params} db ${subcommand}", path => '/usr/bin', user => 'root', refreshonly => true, diff --git a/releasenotes/notes/db-upgrade-07d90ec4fc07f990.yaml b/releasenotes/notes/db-upgrade-07d90ec4fc07f990.yaml new file mode 100644 index 0000000..3ee8d7a --- /dev/null +++ b/releasenotes/notes/db-upgrade-07d90ec4fc07f990.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The new ``rally::db::sync::upgrade`` parameter has been added. When this + parameter is set to ``true``, ``rally db upgrade`` command is executed + instead of ``rally db create`` command. diff --git a/spec/classes/rally_db_sync_spec.rb b/spec/classes/rally_db_sync_spec.rb index e873dc1..14de187 100644 --- a/spec/classes/rally_db_sync_spec.rb +++ b/spec/classes/rally_db_sync_spec.rb @@ -50,6 +50,32 @@ describe 'rally::db::sync' do ) } end + + context "upgrade enabled" do + let :params do + { + :upgrade => true + } + end + + it { + is_expected.to contain_exec('rally db_sync').with( + :command => 'rally --config-file /etc/rally/rally.conf db upgrade', + :user => 'root', + :path => '/usr/bin', + :refreshonly => 'true', + :try_sleep => 5, + :tries => 10, + :timeout => 300, + :logoutput => 'on_failure', + :subscribe => ['Anchor[rally::install::end]', + 'Anchor[rally::config::end]', + 'Anchor[rally::dbsync::begin]'], + :notify => 'Anchor[rally::dbsync::end]', + :tag => 'openstack-db', + ) + } + end end on_supported_os({