Skip to content

Commit

Permalink
Merge "Monkey patch migrate < 0.7.3"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 25, 2012
2 parents 2172e49 + a7df900 commit e60398b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
44 changes: 38 additions & 6 deletions nova/tests/test_migrations.py
Expand Up @@ -26,31 +26,63 @@

import ConfigParser
import commands
import distutils.version as dist_version
import os
import unittest
import urlparse

import migrate.versioning.api as migration_api
from migrate.versioning.repository import Repository
import migrate
from migrate.versioning import util as migrate_util
from sqlalchemy import create_engine

import nova.db.sqlalchemy.migrate_repo
from nova import log as logging
from nova import test


LOG = logging.getLogger('nova.tests.test_migrations')

MIGRATE_PKG_VER = dist_version.StrictVersion(migrate.__version__)
USE_MIGRATE_PATCH = MIGRATE_PKG_VER < dist_version.StrictVersion('0.7.3')


@migrate_util.decorator
def patched_with_engine(f, *a, **kw):
url = a[0]
engine = migrate_util.construct_engine(url, **kw)

try:
kw['engine'] = engine
return f(*a, **kw)
finally:
if isinstance(engine, migrate_util.Engine) and engine is not url:
migrate_util.log.debug('Disposing SQLAlchemy engine %s', engine)
engine.dispose()


# TODO(jkoelker) When migrate 0.7.3 is released and nova depends
# on that version or higher, this can be removed
if USE_MIGRATE_PATCH:
migrate_util.with_engine = patched_with_engine


# NOTE(jkoelker) Delay importing migrate until we are patched
from migrate.versioning import api as migration_api
from migrate.versioning.repository import Repository


class TestMigrations(unittest.TestCase):
"""Test sqlalchemy-migrate migrations"""

TEST_DATABASES = {}
DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__),
'test_migrations.conf')
# Test machines can set the NOVA_TEST_MIGRATIONS_CONF variable
# to override the location of the config file for migration testing
CONFIG_FILE_PATH = os.environ.get('NOVA_TEST_MIGRATIONS_CONF',
os.path.join('test_migrations.conf'))
REPOSITORY_PATH = os.path.abspath(os.path.join('..', 'db', 'sqlalchemy',
'migrate_repo'))
REPOSITORY = Repository(REPOSITORY_PATH)
DEFAULT_CONFIG_FILE)
MIGRATE_FILE = nova.db.sqlalchemy.migrate_repo.__file__
REPOSITORY = Repository(os.path.abspath(os.path.dirname(MIGRATE_FILE)))

def __init__(self, *args, **kwargs):
super(TestMigrations, self).__init__(*args, **kwargs)
Expand Down
10 changes: 0 additions & 10 deletions run_tests.sh
Expand Up @@ -185,16 +185,6 @@ if [ $recreate_db -eq 1 ]; then
rm -f tests.sqlite
fi

# Workaround for sqlalchemy-migrate issue 72
# see: http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=72
if [ $patch_migrate -eq 1 ]; then
pyver=python`python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'`
target=${venv}/lib/${pyver}/site-packages/migrate/versioning/util/__init__.py
if [ -f $target ]; then
sed -i -e '/^\s\+finally:$/ {N; /^\(\s\+finally:\n\s\+if isinstance(engine, Engine)\):$/ {s//\1 and engine is not url:/}}' $target
fi
fi

run_tests

# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
Expand Down

0 comments on commit e60398b

Please sign in to comment.