[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 c84ae9762c)
This commit is contained in:
Rodolfo Alonso Hernandez 2021-01-15 13:52:08 +00:00
parent f037a32556
commit 7946e41a62
1 changed files with 16 additions and 13 deletions

View File

@ -592,17 +592,17 @@ 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:
def _migrate_up(self, config, engine, dest, curr):
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)
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):
@ -613,7 +613,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,