Merge "Revert "Log alembic migration script's output with oslo_log""
This commit is contained in:
commit
736582e9d5
@ -23,7 +23,6 @@ from alembic import migration as alembic_migration
|
||||
from alembic import script as alembic_script
|
||||
from alembic import util as alembic_util
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
@ -33,7 +32,6 @@ from neutron.conf.db import migration_cli
|
||||
from neutron.db import migration
|
||||
from neutron.db.migration.connection import DBConnection
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
HEAD_FILENAME = 'HEAD'
|
||||
HEADS_FILENAME = 'HEADS'
|
||||
@ -69,16 +67,16 @@ def do_alembic_command(config, cmd, revision=None, desc=None, **kwargs):
|
||||
|
||||
project = config.get_main_option('neutron_project')
|
||||
if desc:
|
||||
LOG.info('Running %(cmd)s (%(desc)s) for %(project)s ...',
|
||||
{'cmd': cmd, 'desc': desc, 'project': project})
|
||||
alembic_util.msg(_('Running %(cmd)s (%(desc)s) for %(project)s ...') %
|
||||
{'cmd': cmd, 'desc': desc, 'project': project})
|
||||
else:
|
||||
LOG.info('Running %(cmd)s for %(project)s ...',
|
||||
{'cmd': cmd, 'project': project})
|
||||
alembic_util.msg(_('Running %(cmd)s for %(project)s ...') %
|
||||
{'cmd': cmd, 'project': project})
|
||||
try:
|
||||
getattr(alembic_command, cmd)(config, *args, **kwargs)
|
||||
except alembic_util.CommandError as e:
|
||||
alembic_util.err(six.text_type(e))
|
||||
LOG.info('OK')
|
||||
alembic_util.msg(_('OK'))
|
||||
|
||||
|
||||
def _get_alembic_entrypoint(project):
|
||||
@ -250,10 +248,10 @@ def _compare_labels(revision, expected_labels):
|
||||
bad_labels_with_release = (revision.branch_labels -
|
||||
_get_release_labels(expected_labels))
|
||||
if not bad_labels_with_release:
|
||||
LOG.warning(
|
||||
'Release aware branch labels (%s) are deprecated. '
|
||||
'Please switch to expand@ and contract@ '
|
||||
'labels.', bad_labels)
|
||||
alembic_util.warn(
|
||||
_('Release aware branch labels (%s) are deprecated. '
|
||||
'Please switch to expand@ and contract@ '
|
||||
'labels.') % bad_labels)
|
||||
return
|
||||
|
||||
script_name = os.path.basename(revision.path)
|
||||
@ -348,8 +346,8 @@ def validate_head_files(config):
|
||||
contract_head = _get_contract_head_file_path(config)
|
||||
expand_head = _get_expand_head_file_path(config)
|
||||
if not os.path.exists(contract_head) or not os.path.exists(expand_head):
|
||||
LOG.warning("Repository does not contain HEAD files for "
|
||||
"contract and expand branches.")
|
||||
alembic_util.warn(_("Repository does not contain HEAD files for "
|
||||
"contract and expand branches."))
|
||||
return
|
||||
head_map = _get_heads_map(config)
|
||||
_check_head(CONTRACT_BRANCH, contract_head, head_map[CONTRACT_BRANCH])
|
||||
@ -389,11 +387,11 @@ def has_offline_migrations(config, cmd):
|
||||
# it means we should shut down all neutron-server instances before
|
||||
# proceeding with upgrade.
|
||||
project = config.get_main_option('neutron_project')
|
||||
LOG.info('Need to apply migrations from %(project)s '
|
||||
'contract branch. This will require all Neutron '
|
||||
'server instances to be shutdown before '
|
||||
'proceeding with the upgrade.',
|
||||
{"project": project})
|
||||
alembic_util.msg(_('Need to apply migrations from %(project)s '
|
||||
'contract branch. This will require all Neutron '
|
||||
'server instances to be shutdown before '
|
||||
'proceeding with the upgrade.') %
|
||||
{"project": project})
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -653,6 +651,6 @@ def main():
|
||||
return_val |= bool(CONF.command.func(config, CONF.command.name))
|
||||
|
||||
if CONF.command.name == 'has_offline_migrations' and not return_val:
|
||||
LOG.info('No offline migrations pending.')
|
||||
alembic_util.msg(_('No offline migrations pending.'))
|
||||
|
||||
return return_val
|
||||
|
@ -123,7 +123,7 @@ class TestCli(base.BaseTestCase):
|
||||
self.do_alembic_cmd_p = mock.patch.object(cli, 'do_alembic_command')
|
||||
self.do_alembic_cmd = self.do_alembic_cmd_p.start()
|
||||
self.mock_alembic_err = mock.patch('alembic.util.err').start()
|
||||
self.mock_log_warn = mock.patch.object(cli.LOG, "warning").start()
|
||||
self.mock_alembic_warn = mock.patch('alembic.util.warn').start()
|
||||
self.mock_alembic_err.side_effect = SystemExit
|
||||
|
||||
def mocked_root_dir(cfg):
|
||||
@ -419,7 +419,7 @@ class TestCli(base.BaseTestCase):
|
||||
cli.validate_head_files(fake_config)
|
||||
elif head_files_not_exist:
|
||||
cli.validate_head_files(fake_config)
|
||||
self.assertTrue(self.mock_log_warn.called)
|
||||
self.assertTrue(self.mock_alembic_warn.called)
|
||||
else:
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
|
Loading…
Reference in New Issue
Block a user