Merge "cmd: Remove deprecated '--extension' argument"

This commit is contained in:
Zuul 2022-02-08 15:58:09 +00:00 committed by Gerrit Code Review
commit 8ef0bde1ce
2 changed files with 86 additions and 79 deletions

View File

@ -211,15 +211,6 @@ class Doctor(BaseApp):
raise SystemExit(doctor.diagnose()) raise SystemExit(doctor.diagnose())
def assert_not_extension(extension):
if extension:
print(_("All extensions have been moved into keystone core and as "
"such its migrations are maintained by the main keystone "
"database control. Use the command: keystone-manage "
"db_sync"))
raise RuntimeError
class DbSync(BaseApp): class DbSync(BaseApp):
"""Sync the database.""" """Sync the database."""
@ -228,44 +219,59 @@ class DbSync(BaseApp):
@classmethod @classmethod
def add_argument_parser(cls, subparsers): def add_argument_parser(cls, subparsers):
parser = super(DbSync, cls).add_argument_parser(subparsers) parser = super(DbSync, cls).add_argument_parser(subparsers)
parser.add_argument('version', default=None, nargs='?', parser.add_argument(
help=('Migrate the database up to a specified ' 'version',
'version. If not provided, db_sync will ' default=None,
'migrate the database to the latest known ' nargs='?',
'version. Schema downgrades are not ' help=(
'supported.')) 'Migrate the database up to a specified version. '
parser.add_argument('--extension', default=None, 'If not provided, db_sync will migrate the database to the '
help=('This is a deprecated option to migrate a ' 'latest known version. '
'specified extension. Since extensions are ' 'Schema downgrades are not supported.'
'now part of the main repository, ' ),
'specifying db_sync without this option ' )
'will cause all extensions to be migrated.'))
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument('--expand', default=False, action='store_true', group.add_argument(
help=('Expand the database schema in preparation ' '--expand',
'for data migration.')) default=False,
group.add_argument('--migrate', default=False, action='store_true',
action='store_true', help=(
help=('Copy all data that needs to be migrated ' 'Expand the database schema in preparation for data migration.'
'within the database ahead of starting the ' ),
'first keystone node upgraded to the new ' )
'release. This command should be run ' group.add_argument(
'after the --expand command. Once the ' '--migrate',
'--migrate command has completed, you can ' default=False,
'upgrade all your keystone nodes to the new ' action='store_true',
'release and restart them.')) help=(
'Copy all data that needs to be migrated within the database '
group.add_argument('--contract', default=False, action='store_true', 'ahead of starting the first keystone node upgraded to the '
help=('Remove any database tables and columns ' 'new release. '
'that are no longer required. This command ' 'This command should be run after the --expand command. '
'should be run after all keystone nodes are ' 'Once the --migrate command has completed, you can upgrade '
'running the new release.')) 'all your keystone nodes to the new release and restart them.'
),
group.add_argument('--check', default=False, action='store_true', )
help=('Check for outstanding database actions that ' group.add_argument(
'still need to be executed. This command can ' '--contract',
'be used to verify the condition of the ' default=False,
'current database state.')) action='store_true',
help=(
'Remove any database tables and columns that are no longer '
'required. This command should be run after all keystone '
'nodes are running the new release.'
),
)
group.add_argument(
'--check',
default=False,
action='store_true',
help=(
'Check for outstanding database actions that still need to be '
'executed. This command can be used to verify the condition '
'of the current database state.'
),
)
return parser return parser
@classmethod @classmethod
@ -274,16 +280,19 @@ class DbSync(BaseApp):
try: try:
expand_version = upgrades.get_db_version(repo='expand_repo') expand_version = upgrades.get_db_version(repo='expand_repo')
except migration.exception.DBMigrationError: except migration.exception.DBMigrationError:
LOG.info('Your database is not currently under version ' LOG.info(
'control or the database is already controlled. Your ' 'Your database is not currently under version '
'first step is to run `keystone-manage db_sync ' 'control or the database is already controlled. Your '
'--expand`.') 'first step is to run `keystone-manage db_sync --expand`.'
)
return 2 return 2
try: try:
migrate_version = upgrades.get_db_version( migrate_version = upgrades.get_db_version(
repo='data_migration_repo') repo='data_migration_repo')
except migration.exception.DBMigrationError: except migration.exception.DBMigrationError:
migrate_version = 0 migrate_version = 0
try: try:
contract_version = upgrades.get_db_version(repo='contract_repo') contract_version = upgrades.get_db_version(repo='contract_repo')
except migration.exception.DBMigrationError: except migration.exception.DBMigrationError:
@ -293,8 +302,10 @@ class DbSync(BaseApp):
upgrades.find_repo('expand_repo')) upgrades.find_repo('expand_repo'))
migration_script_version = int(max(repo.versions.versions)) migration_script_version = int(max(repo.versions.versions))
if (contract_version > migrate_version or migrate_version > if (
expand_version): contract_version > migrate_version or
migrate_version > expand_version
):
LOG.info('Your database is out of sync. For more information ' LOG.info('Your database is out of sync. For more information '
'refer to https://docs.openstack.org/keystone/' 'refer to https://docs.openstack.org/keystone/'
'latest/admin/identity-upgrading.html') 'latest/admin/identity-upgrading.html')
@ -311,29 +322,31 @@ class DbSync(BaseApp):
LOG.info('Migrate version is ahead of contract. Your next ' LOG.info('Migrate version is ahead of contract. Your next '
'step is to run `keystone-manage db_sync --contract`.') 'step is to run `keystone-manage db_sync --contract`.')
status = 4 status = 4
elif (migration_script_version == expand_version == migrate_version == elif (
contract_version): migration_script_version == expand_version == migrate_version ==
contract_version
):
LOG.info('All db_sync commands are upgraded to the same ' LOG.info('All db_sync commands are upgraded to the same '
'version and up-to-date.') 'version and up-to-date.')
LOG.info('The latest installed migration script version is: ' LOG.info(
'%(script)d.\nCurrent repository versions:\nExpand: ' 'The latest installed migration script version is: %(script)d.\n'
'%(expand)d \nMigrate: %(migrate)d\nContract: ' 'Current repository versions:\n'
'%(contract)d', {'script': migration_script_version, 'Expand: %(expand)d\n'
'expand': expand_version, 'Migrate: %(migrate)d\n'
'migrate': migrate_version, 'Contract: %(contract)d',
'contract': contract_version}) {
'script': migration_script_version,
'expand': expand_version,
'migrate': migrate_version,
'contract': contract_version,
},
)
return status return status
@staticmethod @staticmethod
def main(): def main():
assert_not_extension(CONF.command.extension)
# It is possible to run expand and migrate at the same time,
# expand needs to run first however.
if CONF.command.check: if CONF.command.check:
sys.exit(DbSync.check_db_sync_status()) sys.exit(DbSync.check_db_sync_status())
elif CONF.command.expand and CONF.command.migrate:
upgrades.expand_schema()
upgrades.migrate_data()
elif CONF.command.expand: elif CONF.command.expand:
upgrades.expand_schema() upgrades.expand_schema()
elif CONF.command.migrate: elif CONF.command.migrate:
@ -350,20 +363,8 @@ class DbVersion(BaseApp):
name = 'db_version' name = 'db_version'
@classmethod
def add_argument_parser(cls, subparsers):
parser = super(DbVersion, cls).add_argument_parser(subparsers)
parser.add_argument('--extension', default=None,
help=('This is a deprecated option to print the '
'version of a specified extension. Since '
'extensions are now part of the main '
'repository, the version of an extension is '
'implicit in the version of the main '
'repository.'))
@staticmethod @staticmethod
def main(): def main():
assert_not_extension(CONF.command.extension)
print(upgrades.get_db_version()) print(upgrades.get_db_version())

View File

@ -0,0 +1,6 @@
---
upgrade:
- |
The ``--extension`` option of ``keystone-manage db_sync`` has been
deprecated since 10.0.0 (Newton) and raised an error when provided. It
has now been removed entirely.