]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add cinder.db.migration.db_initial_version()
authorDan Prince <dprince@redhat.com>
Mon, 28 Oct 2013 14:11:24 +0000 (10:11 -0400)
committerDan Prince <dprince@redhat.com>
Mon, 28 Oct 2013 14:11:24 +0000 (10:11 -0400)
Updates Cinder to use a new function called db_initial_version()
instead of the INIT_VERSION constant. This allows us to
move the top level INIT_VERSION constant into the
sqlalchemy migration.py implementation where it belongs.

Change-Id: I10dacdebb50d3121e3bfd094e40138807233aa64

cinder/db/migration.py
cinder/db/sqlalchemy/migration.py
cinder/test.py
cinder/tests/test_migrations.py

index 6079055e50a089220e5520f7719dabef5543b9eb..053c74a9e90b3696004c6ce3c5e2fcff6f7930c0 100644 (file)
@@ -25,9 +25,6 @@ IMPL = utils.LazyPluggable('db_backend',
                            sqlalchemy='cinder.db.sqlalchemy.migration')
 
 
-INIT_VERSION = 000
-
-
 def db_sync(version=None):
     """Migrate the database to `version` or the most recent version."""
     return IMPL.db_sync(version=version)
@@ -36,3 +33,8 @@ def db_sync(version=None):
 def db_version():
     """Display the current database version."""
     return IMPL.db_version()
+
+
+def db_initial_version():
+    """The starting version for the database."""
+    return IMPL.db_initial_version()
index e2463bc48b1e0089e9f12ce3cd15c614a3f80e1c..ed4ca87e25d22813a65527613d145501df13abac 100644 (file)
@@ -24,12 +24,12 @@ import migrate
 from migrate.versioning import util as migrate_util
 import sqlalchemy
 
-from cinder.db import migration
 from cinder.db.sqlalchemy.api import get_engine
 from cinder import exception
 from cinder.openstack.common import log as logging
 
 
+INIT_VERSION = 000
 LOG = logging.getLogger(__name__)
 
 
@@ -93,12 +93,16 @@ def db_version():
         meta.reflect(bind=engine)
         tables = meta.tables
         if len(tables) == 0:
-            db_version_control(migration.INIT_VERSION)
+            db_version_control(INIT_VERSION)
             return versioning_api.db_version(get_engine(), repository)
         else:
             raise exception.Error(_("Upgrade DB using Essex release first."))
 
 
+def db_initial_version():
+    return INIT_VERSION
+
+
 def db_version_control(version=None):
     repository = _find_migrate_repo()
     versioning_api.version_control(get_engine(), repository, version)
index cc5f33c2739afa2964a7acfdd57cb931b8c4c8d8..6eff6b2b0c714d29a6fefb62f2c52e958ab83ce2 100644 (file)
@@ -78,7 +78,7 @@ class Database(fixtures.Fixture):
         self.engine.dispose()
         conn = self.engine.connect()
         if sql_connection == "sqlite://":
-            if db_migrate.db_version() > db_migrate.INIT_VERSION:
+            if db_migrate.db_version() > db_migrate.db_initial_version():
                 return
         else:
             testdb = os.path.join(CONF.state_path, sqlite_db)
index 3c56ce3f1429f420de0e89faabf27aa72a871f85..63abae4f85f57039eb691023b17779c5311911c9 100644 (file)
@@ -309,17 +309,17 @@ class TestMigrations(test.TestCase):
         # Place the database under version control
         migration_api.version_control(engine,
                                       TestMigrations.REPOSITORY,
-                                      migration.INIT_VERSION)
-        self.assertEqual(migration.INIT_VERSION,
+                                      migration.db_initial_version())
+        self.assertEqual(migration.db_initial_version(),
                          migration_api.db_version(engine,
                                                   TestMigrations.REPOSITORY))
 
         migration_api.upgrade(engine, TestMigrations.REPOSITORY,
-                              migration.INIT_VERSION + 1)
+                              migration.db_initial_version() + 1)
 
         LOG.debug('latest version is %s' % TestMigrations.REPOSITORY.latest)
 
-        for version in xrange(migration.INIT_VERSION + 2,
+        for version in xrange(migration.db_initial_version() + 2,
                               TestMigrations.REPOSITORY.latest + 1):
             # upgrade -> downgrade -> upgrade
             self._migrate_up(engine, version, with_data=True)
@@ -331,7 +331,7 @@ class TestMigrations(test.TestCase):
             # Now walk it back down to 0 from the latest, testing
             # the downgrade paths.
             for version in reversed(
-                xrange(migration.INIT_VERSION + 1,
+                xrange(migration.db_initial_version() + 1,
                        TestMigrations.REPOSITORY.latest)):
                 # downgrade -> upgrade -> downgrade
                 self._migrate_down(engine, version)
@@ -472,7 +472,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 4)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -488,7 +488,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine,
                                   TestMigrations.REPOSITORY,
                                   upgrade_to)
@@ -539,7 +539,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 7)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -601,7 +601,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 8)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -643,7 +643,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 9)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -686,7 +686,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 10)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -730,7 +730,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 11)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -756,7 +756,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 12)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -782,7 +782,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 13)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -808,7 +808,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 15)
 
             self.assertFalse(engine.dialect.has_table(engine.connect(),
@@ -824,7 +824,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 15)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -852,7 +852,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 16)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -905,7 +905,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 17)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -943,7 +943,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 18)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine
@@ -969,7 +969,7 @@ class TestMigrations(test.TestCase):
         for (key, engine) in self.engines.items():
             migration_api.version_control(engine,
                                           TestMigrations.REPOSITORY,
-                                          migration.INIT_VERSION)
+                                          migration.db_initial_version())
             migration_api.upgrade(engine, TestMigrations.REPOSITORY, 19)
             metadata = sqlalchemy.schema.MetaData()
             metadata.bind = engine