Exemple #1
0
def setup():
    import mox  # Fail fast if you don't have mox. Workaround for bug 810424

    from cinder import rpc  # Register rpc_backend before fake_flags sets it
    FLAGS.register_opts(rpc.rpc_opts)

    from cinder.db import migration
    from cinder.tests import fake_flags

    if FLAGS.sql_connection == "sqlite://":
        if migration.db_version() > 1:
            return
    else:
        testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()

    if FLAGS.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Exemple #2
0
 def test_db_version_not_controlled(
     self,
     mock_find_repo,
     mock_get_engine,
     mock_is_migrate,
     mock_is_alembic,
     mock_migrate_version,
     mock_m_context_configure,
 ):
     """Database is not controlled."""
     mock_is_migrate.return_value = False
     mock_is_alembic.return_value = False
     ret = migration.db_version()
     self.assertIsNone(ret)
     mock_find_repo.assert_called_once_with()
     mock_get_engine.assert_called_once_with()
     mock_is_migrate.assert_called_once()
     mock_is_alembic.assert_called_once()
     mock_migrate_version.assert_not_called()
     mock_m_context_configure.assert_not_called()
Exemple #3
0
 def test_db_version_migrate(
     self,
     mock_find_repo,
     mock_get_engine,
     mock_is_migrate,
     mock_is_alembic,
     mock_migrate_version,
     mock_m_context_configure,
 ):
     """Database is controlled by sqlalchemy-migrate."""
     mock_is_migrate.return_value = True
     mock_is_alembic.return_value = False
     ret = migration.db_version()
     self.assertEqual(mock_migrate_version.return_value, ret)
     mock_find_repo.assert_called_once_with()
     mock_get_engine.assert_called_once_with()
     mock_is_migrate.assert_called_once()
     mock_is_alembic.assert_called_once()
     mock_migrate_version.assert_called_once_with(
         mock_get_engine.return_value, mock_find_repo.return_value)
     mock_m_context_configure.assert_not_called()
Exemple #4
0
def setup():
    import mox  # Fail fast if you don't have mox. Workaround for bug 810424

    from cinder.db import migration
    from cinder.tests import fake_flags
    fake_flags.set_defaults(FLAGS)

    if FLAGS.sql_connection == "sqlite://":
        if migration.db_version() > 1:
            return
    else:
        testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()

    if FLAGS.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Exemple #5
0
 def test_db_version_alembic(
     self,
     mock_find_repo,
     mock_get_engine,
     mock_is_migrate,
     mock_is_alembic,
     mock_migrate_version,
     mock_m_context_configure,
 ):
     """Database is controlled by alembic."""
     mock_is_migrate.return_value = False
     mock_is_alembic.return_value = True
     ret = migration.db_version()
     mock_m_context = mock_m_context_configure.return_value
     self.assertEqual(
         mock_m_context.get_current_revision.return_value,
         ret,
     )
     mock_find_repo.assert_called_once_with()
     mock_get_engine.assert_called_once_with()
     mock_is_migrate.assert_called_once()
     mock_is_alembic.assert_called_once()
     mock_migrate_version.assert_not_called()
     mock_m_context_configure.assert_called_once()
Exemple #6
0
 def version(self):
     """Print the current database version."""
     print(db_migration.db_version())
Exemple #7
0
 def test_db_version_alembic(self):
     migration.db_sync()
     head = alembic_script.ScriptDirectory.from_config(
         self.config, ).get_current_head()
     self.assertEqual(head, migration.db_version())