From c8b9384ccf0e9c69f35978f3abbb5e5d5638d859 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Wed, 24 Oct 2012 13:44:37 +0100
Subject: [PATCH] Use updated parallel install versions of epel package
Use sqlalchemy >= 0.6.3 WebOb >= 1.2 Routes >= 1.12.3 PasteDeploy >= 1.5.0
and depend on the parallel installable
versions of these packages to satisfy those requirements.
Delve into pkg_resources a little to get it to modify sys.path,
so that our parallel installed egg takes precedence over the
system default module versions.
---
bin/cinder-manage | 4 +++-
cinder/__init__.py | 30 ++++++++++++++++++++++++++++++
cinder/db/sqlalchemy/migration.py | 7 ++++++-
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/bin/cinder-manage b/bin/cinder-manage
index 3c05d77..9474e2e 100755
--- a/bin/cinder-manage
+++ b/bin/cinder-manage
@@ -62,7 +62,6 @@ import sys
from oslo.config import cfg
-
# If ../cinder/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
@@ -84,6 +83,9 @@ from cinder.openstack.common import uuidutils
from cinder import utils
from cinder import version
+from sqlalchemy import create_engine, MetaData, Table
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import sessionmaker
CONF = cfg.CONF
diff --git a/cinder/__init__.py b/cinder/__init__.py
index d765b08..720320e 100644
--- a/cinder/__init__.py
+++ b/cinder/__init__.py
@@ -30,3 +30,33 @@
.. moduleauthor:: Manish Singh
.. moduleauthor:: Andy Smith
"""
+
+import sys
+import pkg_resources
+
+# If there is a conflicting non egg module,
+# i.e. an older standard system module installed,
+# then replace it with this requirement
+def replace_dist(requirement):
+ try:
+ return pkg_resources.require(requirement)
+ except pkg_resources.VersionConflict:
+ e = sys.exc_info()[1]
+ dist=e.args[0]
+ req=e.args[1]
+ if dist.key == req.key and not dist.location.endswith('.egg'):
+ del pkg_resources.working_set.by_key[dist.key]
+ # We assume there is no need to adjust sys.path
+ # and the associated pkg_resources.working_set.entries
+ return pkg_resources.require(requirement)
+
+replace_dist("WebOb >= 1.2")
+replace_dist("SQLAlchemy >= 0.6.3")
+replace_dist("Routes >= 1.12.3")
+
+replace_dist("PasteDeploy >= 1.5.0")
+# This hack is needed because replace_dist() results in
+# the standard paste module path being at the start of __path__.
+# TODO: See can we get pkg_resources to do the right thing directly
+import paste
+paste.__path__.insert(0, paste.__path__.pop(-1))
diff --git a/cinder/db/sqlalchemy/migration.py b/cinder/db/sqlalchemy/migration.py
index e2463bc..9ba7b73 100644
--- a/cinder/db/sqlalchemy/migration.py
+++ b/cinder/db/sqlalchemy/migration.py
@@ -56,7 +56,12 @@ if (not hasattr(migrate, '__version__') or
# NOTE(jkoelker) Delay importing migrate until we are patched
-from migrate import exceptions as versioning_exceptions
+try:
+ # Try the more specific path first (migrate <= 0.6)
+ from migrate.versioning import exceptions as versioning_exceptions
+except ImportError:
+ # Use the newer path (migrate >= 0.7)
+ from migrate import exceptions as versioning_exceptions
from migrate.versioning import api as versioning_api
from migrate.versioning.repository import Repository