nova-manage - fix online_data_migrations counts
When running online_data_migrations in batches, totals were not being accumulated - rather the counts each batch would clobber those from the previous one, and the last batch would run no migrations, so the totals were reported as zero. Change-Id: Ib616f2efb69baa16e18601d27b747220bbefeb16 Closes-Bug: #1794364
This commit is contained in:
parent
ebab3adb28
commit
c4c6dc736e
|
@ -686,9 +686,7 @@ Error: %s""") % six.text_type(e))
|
||||||
'migrated') % {'total': found,
|
'migrated') % {'total': found,
|
||||||
'meth': name,
|
'meth': name,
|
||||||
'done': done})
|
'done': done})
|
||||||
migrations.setdefault(name, (0, 0))
|
migrations[name] = found, done
|
||||||
migrations[name] = (migrations[name][0] + found,
|
|
||||||
migrations[name][1] + done)
|
|
||||||
if max_count is not None:
|
if max_count is not None:
|
||||||
ran += done
|
ran += done
|
||||||
if ran >= max_count:
|
if ran >= max_count:
|
||||||
|
@ -717,8 +715,14 @@ Error: %s""") % six.text_type(e))
|
||||||
migration_info = {}
|
migration_info = {}
|
||||||
while ran is None or ran != 0:
|
while ran is None or ran != 0:
|
||||||
migrations = self._run_migration(ctxt, max_count)
|
migrations = self._run_migration(ctxt, max_count)
|
||||||
migration_info.update(migrations)
|
ran = 0
|
||||||
ran = sum([done for found, done in migrations.values()])
|
for name in migrations:
|
||||||
|
migration_info.setdefault(name, (0, 0))
|
||||||
|
migration_info[name] = (
|
||||||
|
migration_info[name][0] + migrations[name][0],
|
||||||
|
migration_info[name][1] + migrations[name][1],
|
||||||
|
)
|
||||||
|
ran += migrations[name][1]
|
||||||
if not unlimited:
|
if not unlimited:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -768,6 +768,7 @@ Error: invalid connection
|
||||||
|
|
||||||
@mock.patch('nova.context.get_admin_context')
|
@mock.patch('nova.context.get_admin_context')
|
||||||
def test_online_migrations_no_max_count(self, mock_get_context):
|
def test_online_migrations_no_max_count(self, mock_get_context):
|
||||||
|
self.useFixture(fixtures.MonkeyPatch('sys.stdout', StringIO()))
|
||||||
total = [120]
|
total = [120]
|
||||||
batches = [50, 40, 30, 0]
|
batches = [50, 40, 30, 0]
|
||||||
runs = []
|
runs = []
|
||||||
|
@ -777,11 +778,23 @@ Error: invalid connection
|
||||||
runs.append(count)
|
runs.append(count)
|
||||||
count = batches.pop(0)
|
count = batches.pop(0)
|
||||||
total[0] -= count
|
total[0] -= count
|
||||||
return total[0], count
|
return count, count
|
||||||
|
|
||||||
command_cls = self._fake_db_command((fake_migration,))
|
command_cls = self._fake_db_command((fake_migration,))
|
||||||
command = command_cls()
|
command = command_cls()
|
||||||
command.online_data_migrations(None)
|
command.online_data_migrations(None)
|
||||||
|
expected = """\
|
||||||
|
Running batches of 50 until complete
|
||||||
|
50 rows matched query fake_migration, 50 migrated
|
||||||
|
40 rows matched query fake_migration, 40 migrated
|
||||||
|
30 rows matched query fake_migration, 30 migrated
|
||||||
|
+----------------+--------------+-----------+
|
||||||
|
| Migration | Total Needed | Completed |
|
||||||
|
+----------------+--------------+-----------+
|
||||||
|
| fake_migration | 120 | 120 |
|
||||||
|
+----------------+--------------+-----------+
|
||||||
|
"""
|
||||||
|
self.assertEqual(expected, sys.stdout.getvalue())
|
||||||
self.assertEqual([], batches)
|
self.assertEqual([], batches)
|
||||||
self.assertEqual(0, total[0])
|
self.assertEqual(0, total[0])
|
||||||
self.assertEqual([50, 50, 50, 50], runs)
|
self.assertEqual([50, 50, 50, 50], runs)
|
||||||
|
|
Loading…
Reference in New Issue