Add --verbose to subset of cmds in neutron-db-manage

This commit updates neutron/db/migration/cli.py such that --verbose can
be passed to the following commands:

- current
- history
- branches

We also update tests in neutron/tests/unit/db/test_migration.py and add
a new test for 'neutron-db-manage branches' as that appears to be
untested.

Lastly, we add a brief description of the newly added capability to
doc/source/devref/alembic_migrations.rst.

Change-Id: I9fc136055b422f12a22c1365f52f17df53219820
Closes-Bug: #1488021
This commit is contained in:
Matt Thompson 2015-09-17 12:27:44 +01:00
parent 693db7cf7c
commit b08c3d57a9
3 changed files with 45 additions and 3 deletions

View File

@ -59,6 +59,12 @@ Instead of reading the DB connection from the configuration file(s) the
neutron-db-manage --database-connection mysql+pymysql://root:secret@127.0.0.1/neutron?charset=utf8 <commands>
The ``branches``, ``current``, and ``history`` commands all accept a
``--verbose`` option, which, when passed, will instruct ``neutron-db-manage``
to display more verbose output for the specified command::
neutron-db-manage current --verbose
For some commands the wrapper needs to know the entrypoint of the core plugin
for the installation. This can be read from the configuration file(s) or
specified using the ``--core_plugin`` option::

View File

@ -116,6 +116,11 @@ def _get_alembic_entrypoint(project):
return migration_entrypoints[project]
def do_generic_show(config, cmd):
kwargs = {'verbose': CONF.command.verbose}
do_alembic_command(config, cmd, **kwargs)
def do_check_migration(config, cmd):
do_alembic_command(config, 'branches')
validate_labels(config)
@ -307,7 +312,11 @@ def update_heads_file(config):
def add_command_parsers(subparsers):
for name in ['current', 'history', 'branches']:
parser = add_alembic_subparser(subparsers, name)
parser.set_defaults(func=do_alembic_command)
parser.set_defaults(func=do_generic_show)
parser.add_argument('--verbose',
action='store_true',
help='Display more verbose output for the '
'specified command')
help_text = (getattr(alembic_command, 'branches').__doc__ +
' and validate head file')

View File

@ -165,11 +165,38 @@ class TestCli(base.BaseTestCase):
[{'revision': 'foo', 'sql': True}]
)
def test_branches(self):
self._main_test_helper(
['prog', 'branches'],
'branches',
[{'verbose': False}])
self._main_test_helper(
['prog', 'branches', '--verbose'],
'branches',
[{'verbose': True}])
def test_current(self):
self._main_test_helper(['prog', 'current'], 'current')
self._main_test_helper(
['prog', 'current'],
'current',
[{'verbose': False}])
self._main_test_helper(
['prog', 'current', '--verbose'],
'current',
[{'verbose': True}])
def test_history(self):
self._main_test_helper(['prog', 'history'], 'history')
self._main_test_helper(
['prog', 'history'],
'history',
[{'verbose': False}])
self._main_test_helper(
['prog', 'history', '--verbose'],
'history',
[{'verbose': True}])
def test_check_migration(self):
with mock.patch.object(cli, 'validate_heads_file') as validate: