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
(cherry picked from commit c4c6dc736e)
This commit is contained in:
imacdonn 2018-09-26 04:30:49 +00:00 committed by Matt Riedemann
parent 24531a3583
commit fc9c877201
2 changed files with 23 additions and 6 deletions

View File

@ -685,9 +685,7 @@ Error: %s""") % six.text_type(e))
'migrated') % {'total': found,
'meth': name,
'done': done})
migrations.setdefault(name, (0, 0))
migrations[name] = (migrations[name][0] + found,
migrations[name][1] + done)
migrations[name] = found, done
if max_count is not None:
ran += done
if ran >= max_count:
@ -716,8 +714,14 @@ Error: %s""") % six.text_type(e))
migration_info = {}
while ran is None or ran != 0:
migrations = self._run_migration(ctxt, max_count)
migration_info.update(migrations)
ran = sum([done for found, done in migrations.values()])
ran = 0
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:
break

View File

@ -767,6 +767,7 @@ Error: invalid connection
@mock.patch('nova.context.get_admin_context')
def test_online_migrations_no_max_count(self, mock_get_context):
self.useFixture(fixtures.MonkeyPatch('sys.stdout', StringIO()))
total = [120]
batches = [50, 40, 30, 0]
runs = []
@ -776,11 +777,23 @@ Error: invalid connection
runs.append(count)
count = batches.pop(0)
total[0] -= count
return total[0], count
return count, count
command_cls = self._fake_db_command((fake_migration,))
command = command_cls()
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(0, total[0])
self.assertEqual([50, 50, 50, 50], runs)