Merge "Fix split on "+" for connection strings that specify dialects"
This commit is contained in:
commit
7dc11bae11
@ -58,6 +58,11 @@ def fetch(conf, namespace=BACKEND_NAMESPACE, **kwargs):
|
|||||||
else:
|
else:
|
||||||
backend_name = uri.scheme
|
backend_name = uri.scheme
|
||||||
conf = misc.merge_uri(uri, conf.copy())
|
conf = misc.merge_uri(uri, conf.copy())
|
||||||
|
# If the backend is like 'mysql+pymysql://...' which informs the
|
||||||
|
# backend to use a dialect (supported by sqlalchemy at least) we just want
|
||||||
|
# to look at the first component to find our entrypoint backend name...
|
||||||
|
if backend_name.find("+") != -1:
|
||||||
|
backend_name = backend_name.split("+", 1)[0]
|
||||||
LOG.debug('Looking for %r backend driver in %r', backend_name, namespace)
|
LOG.debug('Looking for %r backend driver in %r', backend_name, namespace)
|
||||||
try:
|
try:
|
||||||
mgr = driver.DriverManager(namespace, backend_name,
|
mgr = driver.DriverManager(namespace, backend_name,
|
||||||
|
@ -145,6 +145,14 @@ class BackendPersistenceTestMixin(base.PersistenceTestMixin):
|
|||||||
def _get_connection(self):
|
def _get_connection(self):
|
||||||
return self.backend.get_connection()
|
return self.backend.get_connection()
|
||||||
|
|
||||||
|
def test_entrypoint(self):
|
||||||
|
# Test that the entrypoint fetching also works (even with dialects)
|
||||||
|
# using the same configuration we used in setUp() but not using
|
||||||
|
# the impl_sqlalchemy SQLAlchemyBackend class directly...
|
||||||
|
with contextlib.closing(backends.fetch(self.db_conf)) as backend:
|
||||||
|
with contextlib.closing(backend.get_connection()):
|
||||||
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def _init_db(self):
|
def _init_db(self):
|
||||||
"""Sets up the database, and returns the uri to that database."""
|
"""Sets up the database, and returns the uri to that database."""
|
||||||
@ -158,17 +166,17 @@ class BackendPersistenceTestMixin(base.PersistenceTestMixin):
|
|||||||
self.backend = None
|
self.backend = None
|
||||||
try:
|
try:
|
||||||
self.db_uri = self._init_db()
|
self.db_uri = self._init_db()
|
||||||
|
self.db_conf = {
|
||||||
|
'connection': self.db_uri
|
||||||
|
}
|
||||||
# Since we are using random database names, we need to make sure
|
# Since we are using random database names, we need to make sure
|
||||||
# and remove our random database when we are done testing.
|
# and remove our random database when we are done testing.
|
||||||
self.addCleanup(self._remove_db)
|
self.addCleanup(self._remove_db)
|
||||||
conf = {
|
|
||||||
'connection': self.db_uri
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.skipTest("Failed to create temporary database;"
|
self.skipTest("Failed to create temporary database;"
|
||||||
" testing being skipped due to: %s" % (e))
|
" testing being skipped due to: %s" % (e))
|
||||||
try:
|
try:
|
||||||
self.backend = impl_sqlalchemy.SQLAlchemyBackend(conf)
|
self.backend = impl_sqlalchemy.SQLAlchemyBackend(self.db_conf)
|
||||||
self.addCleanup(self.backend.close)
|
self.addCleanup(self.backend.close)
|
||||||
with contextlib.closing(self._get_connection()) as conn:
|
with contextlib.closing(self._get_connection()) as conn:
|
||||||
conn.upgrade()
|
conn.upgrade()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user