From 25e73d5cbf66984f69deb0e808a25f97772bd9dd Mon Sep 17 00:00:00 2001 From: imacdonn Date: Wed, 26 Sep 2018 04:30:49 +0000 Subject: [PATCH] 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 c4c6dc736e084f2d919b9bcf93d26df87e0341c9) (cherry picked from commit fc9c8772012b528176c3f58d99a58491bb1aedb4) (cherry picked from commit d8b99f05abb2fa8964a326958804f47daf95da64) --- nova/cmd/manage.py | 14 +++++++++----- nova/tests/unit/test_nova_manage.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 872d630fa83b..0ecc95d23c38 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -833,9 +833,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: @@ -864,8 +862,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 23f5fb2c4220..a32bae2c1403 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -674,6 +674,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 = [] @@ -683,11 +684,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)