Merge "Fix online_data_migrations() not passing context"

This commit is contained in:
Jenkins 2016-02-29 23:35:38 +00:00 committed by Gerrit Code Review
commit 349e12e1bc
2 changed files with 13 additions and 8 deletions

View File

@ -991,12 +991,12 @@ class DbCommands(object):
print(_('There were no records found where '
'instance_uuid was NULL.'))
def _run_migration(self, max_count):
def _run_migration(self, ctxt, max_count):
ran = 0
for migration_meth in self.online_migrations:
count = max_count - ran
try:
found, done = migration_meth(count)
found, done = migration_meth(ctxt, count)
except Exception:
print(_("Error attempting to run %(method)s") % dict(
method=migration_meth))
@ -1016,6 +1016,7 @@ class DbCommands(object):
@args('--max-count', metavar='<number>', dest='max_count',
help='Maximum number of objects to consider')
def online_data_migrations(self, max_count=None):
ctxt = context.get_admin_context()
if max_count is not None:
max_count = int(max_count)
unlimited = False
@ -1029,7 +1030,7 @@ class DbCommands(object):
ran = None
while ran is None or ran != 0:
ran = self._run_migration(max_count)
ran = self._run_migration(ctxt, max_count)
if not unlimited:
break

View File

@ -476,19 +476,23 @@ class DBCommandsTestCase(test.NoDBTestCase):
return _CommandSub
def test_online_migrations(self):
@mock.patch('nova.context.get_admin_context')
def test_online_migrations(self, mock_get_context):
ctxt = mock_get_context.return_value
command_cls = self._fake_db_command()
command = command_cls()
command.online_data_migrations(10)
command_cls.online_migrations[0].assert_called_once_with(10)
command_cls.online_migrations[1].assert_called_once_with(6)
command_cls.online_migrations[0].assert_called_once_with(ctxt, 10)
command_cls.online_migrations[1].assert_called_once_with(ctxt, 6)
def test_online_migrations_no_max_count(self):
@mock.patch('nova.context.get_admin_context')
def test_online_migrations_no_max_count(self, mock_get_context):
total = [120]
batches = [50, 40, 30, 0]
runs = []
def fake_migration(count):
def fake_migration(context, count):
self.assertEqual(mock_get_context.return_value, context)
runs.append(count)
count = batches.pop(0)
total[0] -= count