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

View File

@ -592,18 +592,18 @@ class _TestWalkMigrations(object):
# Destination, current # Destination, current
yield rev.revision, rev.down_revision yield rev.revision, rev.down_revision
def _migrate_up(self, config, engine, dest, curr, with_data=False): def _migrate_up(self, config, engine, dest, curr):
if with_data: data = None
data = None check = getattr(self, "_check_%s" % dest, None)
pre_upgrade = getattr( pre_upgrade = getattr(self, "_pre_upgrade_%s" % dest, None)
self, "_pre_upgrade_%s" % dest, None) if pre_upgrade:
if pre_upgrade: if curr:
data = pre_upgrade(engine) migration.do_alembic_command(config, 'upgrade', curr)
migration.do_alembic_command(config, 'upgrade', dest) data = pre_upgrade(engine)
if with_data:
check = getattr(self, "_check_%s" % dest, None) if check and data:
if check and data: migration.do_alembic_command(config, 'upgrade', dest)
check(engine, data) check(engine, data)
def test_walk_versions(self): def test_walk_versions(self):
"""Test migrations ability to upgrade and downgrade. """Test migrations ability to upgrade and downgrade.
@ -613,7 +613,10 @@ class _TestWalkMigrations(object):
config = self._get_alembic_config(engine.url) config = self._get_alembic_config(engine.url)
revisions = self._revisions() revisions = self._revisions()
for dest, curr in 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, class TestWalkMigrationsMysql(testlib_api.MySQLTestCaseMixin,