From 25a279b5ac01628b8002c7fe9f55cd546adc1654 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 28 Oct 2013 10:11:24 -0400 Subject: [PATCH] Add cinder.db.migration.db_initial_version() 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 | 8 ++++--- cinder/db/sqlalchemy/migration.py | 8 +++++-- cinder/test.py | 2 +- cinder/tests/test_migrations.py | 40 +++++++++++++++---------------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/cinder/db/migration.py b/cinder/db/migration.py index 6079055e5..053c74a9e 100644 --- a/cinder/db/migration.py +++ b/cinder/db/migration.py @@ -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() diff --git a/cinder/db/sqlalchemy/migration.py b/cinder/db/sqlalchemy/migration.py index e2463bc48..ed4ca87e2 100644 --- a/cinder/db/sqlalchemy/migration.py +++ b/cinder/db/sqlalchemy/migration.py @@ -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) diff --git a/cinder/test.py b/cinder/test.py index cc5f33c27..6eff6b2b0 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -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) diff --git a/cinder/tests/test_migrations.py b/cinder/tests/test_migrations.py index 3c56ce3f1..63abae4f8 100644 --- a/cinder/tests/test_migrations.py +++ b/cinder/tests/test_migrations.py @@ -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 -- 2.45.2