Remove deprecated methods from migration CLI file

Commit Ie4ddd29d8c51be74a112864aae3d16fb5e52c0fa marked methods:
 * _validate_head_file
 * update_head_file
as deprecated.

Related-Bug: #1501380
Change-Id: I0c08b32120974a7f82d2ae967cf13374c2e797ce
This commit is contained in:
Dariusz Smigiel (dasm) 2016-03-22 15:32:41 +00:00 committed by Darek Smigiel (dasm)
parent bb99b8c648
commit 7d806fb990
2 changed files with 7 additions and 93 deletions

View File

@ -22,7 +22,6 @@ from alembic import environment
from alembic import migration as alembic_migration
from alembic import script as alembic_script
from alembic import util as alembic_util
import debtcollector
from oslo_config import cfg
from oslo_utils import fileutils
from oslo_utils import importutils
@ -58,9 +57,6 @@ migration_entrypoints = {
}
BRANCHLESS_WARNING = 'Branchless migration chains are deprecated as of Mitaka.'
neutron_alembic_ini = os.path.join(os.path.dirname(__file__), 'alembic.ini')
# Interpret the config file for Python logging.
@ -152,7 +148,7 @@ def do_generic_show(config, cmd):
def do_check_migration(config, cmd):
do_alembic_command(config, 'branches')
validate_revisions(config)
validate_head_file(config)
validate_head_files(config)
def add_alembic_subparser(sub, cmd):
@ -284,10 +280,7 @@ def do_revision(config, cmd):
# autogeneration code will take care of enforcing proper directories
do_alembic_command(config, cmd, **kwargs)
if _use_separate_migration_branches(config):
update_head_files(config)
else:
update_head_file(config)
update_head_files(config)
def _get_release_labels(labels):
@ -377,32 +370,6 @@ def _get_branch_points(script):
return branchpoints
def validate_head_file(config):
'''Check that HEAD file contains the latest head for the branch.'''
if _use_separate_migration_branches(config):
_validate_head_files(config)
else:
_validate_head_file(config)
@debtcollector.removals.remove(message=BRANCHLESS_WARNING)
def _validate_head_file(config):
'''Check that HEAD file contains the latest head for the branch.'''
script = alembic_script.ScriptDirectory.from_config(config)
expected_head = script.get_heads()
head_path = _get_head_file_path(config)
try:
with open(head_path) as file_:
observed_head = file_.read().split()
if observed_head == expected_head:
return
except IOError:
pass
alembic_util.err(
_('HEAD file does not match migration timeline head, expected: %s')
% expected_head)
def _get_heads_map(config):
script = alembic_script.ScriptDirectory.from_config(config)
heads = script.get_heads()
@ -429,7 +396,7 @@ def _check_head(branch_name, head_file, head):
'head': head})
def _validate_head_files(config):
def validate_head_files(config):
'''Check that HEAD files contain the latest head for the branch.'''
contract_head = _get_contract_head_file_path(config)
expand_head = _get_expand_head_file_path(config)
@ -458,14 +425,6 @@ def update_head_files(config):
fileutils.delete_if_exists(file_)
@debtcollector.removals.remove(message=BRANCHLESS_WARNING)
def update_head_file(config):
script = alembic_script.ScriptDirectory.from_config(config)
head = script.get_heads()
with open(_get_head_file_path(config), 'w+') as f:
f.write('\n'.join(head))
def _get_current_database_heads(config):
with DBConnection(config.neutron_config.database.connection) as conn:
opts = {

View File

@ -204,7 +204,7 @@ class TestCli(base.BaseTestCase):
self._validate_cmd('heads')
def test_check_migration(self):
with mock.patch.object(cli, 'validate_head_file') as validate:
with mock.patch.object(cli, 'validate_head_files') as validate:
self._main_test_helper(['prog', 'check_migration'], 'branches')
self.assertEqual(len(self.projects), validate.call_count)
@ -394,31 +394,6 @@ class TestCli(base.BaseTestCase):
def test_upgrade_rejects_delta_with_relative_revision(self, use_mock):
self.assert_command_fails(['prog', 'upgrade', '+2', '--delta', '3'])
def _test_validate_head_file_helper(self, heads, file_heads=None):
if file_heads is None:
file_heads = []
fake_config = self.configs[0]
mock_open = self.useFixture(
tools.OpenFixture(cli._get_head_file_path(fake_config),
'\n'.join(file_heads))).mock_open
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc,\
mock.patch.object(cli, '_use_separate_migration_branches',
return_value=False):
fc.return_value.get_heads.return_value = heads
if all(head in file_heads for head in heads):
cli.validate_head_file(fake_config)
else:
self.assertRaises(
SystemExit,
cli.validate_head_file,
fake_config
)
self.assertTrue(self.mock_alembic_err.called)
mock_open.assert_called_with(
cli._get_head_file_path(fake_config))
fc.assert_called_once_with(fake_config)
def _test_validate_head_files_helper(self, heads, contract_head='',
expand_head=''):
fake_config = self.configs[0]
@ -445,14 +420,14 @@ class TestCli(base.BaseTestCase):
fake_config), expand_head + '\n')).mock_open
if contract_head in heads and expand_head in heads:
cli.validate_head_file(fake_config)
cli.validate_head_files(fake_config)
elif head_files_not_exist:
cli.validate_head_file(fake_config)
cli.validate_head_files(fake_config)
self.assertTrue(self.mock_alembic_warn.called)
else:
self.assertRaises(
SystemExit,
cli.validate_head_file,
cli.validate_head_files,
fake_config
)
self.assertTrue(self.mock_alembic_err.called)
@ -477,26 +452,6 @@ class TestCli(base.BaseTestCase):
self._test_validate_head_files_helper(['a', 'b'], contract_head='c',
expand_head='d')
def test_validate_head_file_branchless_wrong_contents(self):
self._test_validate_head_file_helper(['a'], ['b'])
def test_validate_head_file_branchless_success(self):
self._test_validate_head_file_helper(['a'], ['a'])
def test_validate_head_file_branchless_missing_file(self):
self._test_validate_head_file_helper(['a'])
def test_update_head_file_success(self):
head = ['b']
mock_open = self.useFixture(
tools.OpenFixture(cli._get_head_file_path(
self.configs[0]))).mock_open
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
fc.return_value.get_heads.return_value = head
cli.update_head_file(self.configs[0])
mock_open.return_value.write.assert_called_with(
'\n'.join(head))
@mock.patch.object(cli, '_use_separate_migration_branches',
return_value=True)
@mock.patch.object(fileutils, 'delete_if_exists')