Add stamp DB version to the migration script

The existing nova-api to placement database migration shell scripts
don't include the post task to stamp the placement database to the
(b4ed3a175331) version. Without that stamping, syncing the DB to the
current version fails on having the initial upgrade: (initial) ->
(b4ed3a175331). This is because it assumes the initial DB has no
contents and tries to create the tables again.

This patch changes the shell scripts to include that stamping task
rather than leaving it as operators' manual duties to safely bring
the placement DB under alembic version control.

With this change, the shell scripts will need to be executed under the
following condition:
 - The placement is already installed to execute `placement-manage *`
 - The placement cli can access the placement's database, for example,
   by reffering to the `[placement_database]` section in the
   `placement.conf`.

Depends-On: https://review.openstack.org/620485
Change-Id: I75926b0efb3983d62603f2fd30b5a8cc30203d46
This commit is contained in:
Tetsuro Nakamura 2018-12-03 21:43:40 +00:00
parent 3d33ed668c
commit bfd6528c75
2 changed files with 64 additions and 0 deletions

View File

@ -15,6 +15,7 @@ NOVA_API_DB_HOST=${NOVA_API_DB_HOST:-localhost}
NOVA_API_DB=${NOVA_API_DB:-nova_api}
TMPDIR=${TMPDIR:-/tmp}
LAST_MYSQL_ERR=${TMPDIR}/migrate-mysql-db.err
INITIAL_PLACEMENT_DB_VERSION=${INITIAL_DB_VERSION:-b4ed3a175331}
ME=$(basename "$0")
declare -a ARGS
@ -120,6 +121,26 @@ function check_db() {
fi
}
function check_cli() {
# Returns 0 if placement cli is installed and configured,
# 1 if it is not installed, or 2 if the access to the
# placement database fails
# Usage: check_cli -> 0
placement-manage --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
# placement not installed
return 1
fi
placement-manage db version > /dev/null 2>&1
if [ $? -ne 0 ]; then
# DB connection fails
return 2
fi
}
function migrate_data() {
# Actually migrate data from a source to destination symbolic
# database. Returns 1 if failure, 0 otherwise.
@ -213,6 +234,7 @@ function show_help() {
echo " 3: Migration already completed"
echo " 4: No data to migrate from nova (new deployment)"
echo " 5: Unable to connect to one or both databases"
echo " 6: Unable to execute placement's CLI commands"
exit 0
}
@ -239,6 +261,8 @@ check_db NOVA_API
nova_present=$?
check_db PLACEMENT
placement_present=$?
check_cli
placement_cli=$?
# Try to come up with a good reason to refuse to migrate
if [ $nova_present -eq 0 -a $placement_present -eq 0 ]; then
@ -253,6 +277,13 @@ elif [ $nova_present -eq 2 ]; then
elif [ $placement_present -eq 2 ]; then
echo "Unable to proceed without connection to placement database"
exit 5
elif [ $placement_cli -eq 1 ]; then
echo "Unable to proceed without placement installed"
exit 6
elif [ $placement_cli -eq 2 ]; then
echo "The 'placement-manage db version' command fails"
echo "Is placement.conf configured to access the new database?"
exit 6
fi
# If we get here, we expect to be able to migrate. Require them to opt into
@ -262,6 +293,7 @@ echo Nova database contains data, placement database does not. Okay to proceed w
if getflag migrate $*; then
migrate_data NOVA_API PLACEMENT
placement-manage db stamp $INITIAL_PLACEMENT_DB_VERSION
else
echo "To actually migrate, run me with --migrate"
fi

View File

@ -16,6 +16,7 @@ NOVA_API_DB_HOST=${NOVA_API_DB_HOST:-localhost}
NOVA_API_DB=${NOVA_API_DB:-nova_api}
TMPDIR=${TMPDIR:-/tmp}
LAST_PSQL_ERR=${TMPDIR}/migrate-psql-db.err
INITIAL_PLACEMENT_DB_VERSION=${INITIAL_DB_VERSION:-b4ed3a175331}
declare -a ARGS
declare -a OPTS
@ -117,6 +118,26 @@ function check_db() {
fi
}
function check_cli() {
# Returns 0 if placement cli is installed and configured,
# 1 if it is not installed, or 2 if the access to the
# placement database fails
# Usage: check_cli -> 0
placement-manage --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
# placement not installed
return 1
fi
placement-manage db version > /dev/null 2>&1
if [ $? -ne 0 ]; then
# DB connection fails
return 2
fi
}
function migrate_data() {
# Actually migrate data from a source to destination symbolic
# database. Returns 1 if failure, 0 otherwise.
@ -205,6 +226,7 @@ if getflag help; then
echo " 3: Migration already completed"
echo " 4: No data to migrate from nova (new deployment)"
echo " 5: Unable to connect to one or both databases"
echo " 6: Unable to execute placement's CLI commands"
exit 0
fi
@ -225,6 +247,8 @@ check_db NOVA_API
nova_present=$?
check_db PLACEMENT
placement_present=$?
check_cli
placement_cli=$?
# Try to come up with a good reason to refuse to migrate
if [ $nova_present -eq 0 -a $placement_present -eq 0 ]; then
@ -239,6 +263,13 @@ elif [ $nova_present -eq 2 ]; then
elif [ $placement_present -eq 2 ]; then
echo "Unable to proceed without connection to placement database"
exit 5
elif [ $placement_cli -eq 1 ]; then
echo "Unable to proceed without placement installed"
exit 6
elif [ $placement_cli -eq 2 ]; then
echo "The 'placement-manage db version' command fails"
echo "Is placement.conf configured to access the new database?"
exit 6
fi
# If we get here, we expect to be able to migrate. Require them to opt into
@ -248,6 +279,7 @@ echo Nova database contains data, placement database does not. Okay to proceed w
if getflag migrate $*; then
migrate_data NOVA_API PLACEMENT
placement-manage db stamp $INITIAL_PLACEMENT_DB_VERSION
else
echo "To actually migrate, run me with --migrate"
fi