diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 09875a54b544..f6c9259c0c2b 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -761,9 +761,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: @@ -792,8 +790,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 diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index 4986c78fee26..4a7440277d38 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -615,6 +615,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 = [] @@ -624,11 +625,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)