]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
add data injection on migrations
authorSean Dague <sdague@linux.vnet.ibm.com>
Tue, 5 Feb 2013 12:28:22 +0000 (07:28 -0500)
committerSean Dague <sdague@linux.vnet.ibm.com>
Tue, 5 Feb 2013 19:05:15 +0000 (14:05 -0500)
bring over the data injection from migrations from nova, which allows
us to inject sample data at every migration in the walk_versions, and
run a check after the migration to make sure that things look as we
expected.

Change-Id: I8b1d36f1363c12768dea228a3ecfafc1b919f083

cinder/tests/test_migrations.py

index 21a74d2b6bfca00084f08e36794143bf55bfdfd4..4b86eef776cafa54adab22d51d2b6843f49e3690 100644 (file)
@@ -296,7 +296,7 @@ class TestMigrations(test.TestCase):
         for version in xrange(migration.INIT_VERSION + 2,
                               TestMigrations.REPOSITORY.latest + 1):
             # upgrade -> downgrade -> upgrade
-            self._migrate_up(engine, version)
+            self._migrate_up(engine, version, with_data=True)
             if snake_walk:
                 self._migrate_down(engine, version - 1)
                 self._migrate_up(engine, version)
@@ -321,13 +321,38 @@ class TestMigrations(test.TestCase):
                          migration_api.db_version(engine,
                                                   TestMigrations.REPOSITORY))
 
-    def _migrate_up(self, engine, version):
-        migration_api.upgrade(engine,
-                              TestMigrations.REPOSITORY,
-                              version)
-        self.assertEqual(version,
-                         migration_api.db_version(engine,
-                                                  TestMigrations.REPOSITORY))
+    def _migrate_up(self, engine, version, with_data=False):
+        """migrate up to a new version of the db.
+
+        We allow for data insertion and post checks at every
+        migration version with special _prerun_### and
+        _check_### functions in the main test.
+        """
+        # NOTE(sdague): try block is here because it's impossible to debug
+        # where a failed data migration happens otherwise
+        try:
+            if with_data:
+                data = None
+                prerun = getattr(self, "_prerun_%d" % version, None)
+                if prerun:
+                    data = prerun(engine)
+
+                migration_api.upgrade(engine,
+                                      TestMigrations.REPOSITORY,
+                                      version)
+                self.assertEqual(
+                    version,
+                    migration_api.db_version(engine,
+                                             TestMigrations.REPOSITORY))
+
+            if with_data:
+                check = getattr(self, "_check_%d" % version, None)
+                if check:
+                    check(engine, data)
+        except Exception:
+            LOG.error("Failed to migrate to version %s on engine %s" %
+                      (version, engine))
+            raise
 
     def test_migration_004(self):
         """Test that volume_type_id migration works correctly."""