From b8c264e9db5976a0b71af364fafc566b006f162c Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 15 Jan 2021 13:52:08 +0000 Subject: [PATCH] [FT] Reduce "test_walk_versions" upgrade executions "_TestWalkMigrations.test_walk_versions" is inherited in other classes to check a specific DB revision upgrade. The goal is to, from the previous DB revision, create a testing condition and then upgrade to the related DB revision. If the upgrade is correct, the test should pass. This patch reduces the number of Neutron DB upgrade operations to just three: - Upgrade the DB to the previous DB revision to check. - Upgrade the DB to the related DB revision, after setting the testing conditions. - A final upgrade up to the latest DB revision. In a testing deployment, this reduces the execution time from 60 seconds to 35 seconds, without reducing the testing scope. Change-Id: Iffdc0373ed72aea1320155ea8bec93dce797f27c Related-Bug: #1911153 (cherry picked from commit c84ae9762c2bae84a3f5f20cfb01b8ef00f46118) --- .../tests/functional/db/test_migrations.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/neutron/tests/functional/db/test_migrations.py b/neutron/tests/functional/db/test_migrations.py index 9bc075c6bfa..d7037976382 100644 --- a/neutron/tests/functional/db/test_migrations.py +++ b/neutron/tests/functional/db/test_migrations.py @@ -593,18 +593,18 @@ class _TestWalkMigrations(object): # Destination, current yield rev.revision, rev.down_revision - def _migrate_up(self, config, engine, dest, curr, with_data=False): - if with_data: - data = None - pre_upgrade = getattr( - self, "_pre_upgrade_%s" % dest, None) - if pre_upgrade: - data = pre_upgrade(engine) - migration.do_alembic_command(config, 'upgrade', dest) - if with_data: - check = getattr(self, "_check_%s" % dest, None) - if check and data: - check(engine, data) + def _migrate_up(self, config, engine, dest, curr): + data = None + check = getattr(self, "_check_%s" % dest, None) + pre_upgrade = getattr(self, "_pre_upgrade_%s" % dest, None) + if pre_upgrade: + if curr: + migration.do_alembic_command(config, 'upgrade', curr) + data = pre_upgrade(engine) + + if check and data: + migration.do_alembic_command(config, 'upgrade', dest) + check(engine, data) def test_walk_versions(self): """Test migrations ability to upgrade and downgrade. @@ -614,7 +614,10 @@ class _TestWalkMigrations(object): config = self._get_alembic_config(engine.url) revisions = self._revisions() for dest, curr in revisions: - self._migrate_up(config, engine, dest, curr, with_data=True) + self._migrate_up(config, engine, dest, curr) + + if dest: + migration.do_alembic_command(config, 'upgrade', dest) class TestWalkMigrationsMysql(testlib_api.MySQLTestCaseMixin,