Improve handling of database migration checks

The `--check` subcommand is suppose to provide useful information
and status codes depending on the state of the keystone database.
Operators and automation use this information to determine what their
next step is in a rolling upgrade. The current logic is broken
becuase it doesn't account for new installations that might be
relying on this information.

This change breaks that case into multiple try/except statements and
handles each appropriately so that the status code and logging
information is accurate for operators and automation using this
information for upgrading a new keystone database.

Change-Id: I331fa663a99f79ea9a79a75e4ae07c45278556bf
Closes-Bug: 1698900
This commit is contained in:
Lance Bragstad 2017-06-19 17:41:13 +00:00
parent 45265c0ddf
commit 2a2f8535e2
3 changed files with 22 additions and 3 deletions

View File

@ -459,15 +459,21 @@ class DbSync(BaseApp):
status = 0
try:
expand_version = upgrades.get_db_version(repo='expand_repo')
migrate_version = upgrades.get_db_version(
repo='data_migration_repo')
contract_version = upgrades.get_db_version(repo='contract_repo')
except migration.exception.DbMigrationError:
LOG.info('Your database is not currently under version '
'control or the database is already controlled. Your '
'first step is to run `keystone-manage db_sync '
'--expand`.')
return 2
try:
migrate_version = upgrades.get_db_version(
repo='data_migration_repo')
except migration.exception.DbMigrationError:
migrate_version = 0
try:
contract_version = upgrades.get_db_version(repo='contract_repo')
except migration.exception.DbMigrationError:
contract_version = 0
repo = migrate.versioning.repository.Repository(
upgrades.find_repo('expand_repo'))

View File

@ -1710,6 +1710,13 @@ class FullMigration(SqlMigrateBase, unit.TestCase):
checker = cli.DbSync()
latest_version = self.repos[EXPAND_REPO].max_version
# If the expand repository doesn't exist yet, then we need to make sure
# we advertise that `--expand` must be run first.
log_info = self.useFixture(fixtures.FakeLogger(level=log.INFO))
status = checker.check_db_sync_status()
self.assertIn("keystone-manage db_sync --expand", log_info.output)
self.assertEqual(status, 2)
# Assert the correct message is printed when expand is the first step
# that needs to run
self.expand(1)

View File

@ -0,0 +1,6 @@
fixes:
- |
The implementation for checking database state during an upgrade with the
use of `keystone-manage db_sync --check` has been corrected. This allows
users and automation to determine what step is next in a rolling upgrade
based on logging and command status codes.