Merge "Allow connection string to be just backend name"
This commit is contained in:
@@ -15,8 +15,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from six.moves import urllib_parse
|
|
||||||
from stevedore import driver
|
from stevedore import driver
|
||||||
|
|
||||||
from taskflow import exceptions as exc
|
from taskflow import exceptions as exc
|
||||||
@@ -25,11 +25,22 @@ from taskflow import exceptions as exc
|
|||||||
# NOTE(harlowja): this is the entrypoint namespace, not the module namespace.
|
# NOTE(harlowja): this is the entrypoint namespace, not the module namespace.
|
||||||
BACKEND_NAMESPACE = 'taskflow.persistence'
|
BACKEND_NAMESPACE = 'taskflow.persistence'
|
||||||
|
|
||||||
|
# NOTE(imelnikov): regular expression to get scheme from URI,
|
||||||
|
# see RFC 3986 section 3.1
|
||||||
|
SCHEME_REGEX = re.compile(r"^([A-Za-z]{1}[A-Za-z0-9+.-]*):")
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def fetch(conf, namespace=BACKEND_NAMESPACE):
|
def fetch(conf, namespace=BACKEND_NAMESPACE):
|
||||||
backend_name = urllib_parse.urlparse(conf['connection']).scheme
|
connection = conf['connection']
|
||||||
|
|
||||||
|
match = SCHEME_REGEX.match(connection)
|
||||||
|
if match:
|
||||||
|
backend_name = match.group(1)
|
||||||
|
else:
|
||||||
|
backend_name = connection
|
||||||
|
|
||||||
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,
|
||||||
|
|||||||
@@ -46,19 +46,16 @@ class DirPersistenceTest(test.TestCase, base.PersistenceTestMixin):
|
|||||||
shutil.rmtree(self.path)
|
shutil.rmtree(self.path)
|
||||||
self.path = None
|
self.path = None
|
||||||
|
|
||||||
def test_dir_persistence_entry_point(self):
|
def _check_backend(self, conf):
|
||||||
conf = {
|
|
||||||
'connection': 'dir:',
|
|
||||||
'path': self.path
|
|
||||||
}
|
|
||||||
backend = backends.fetch(conf)
|
|
||||||
self.assertIsInstance(backend, impl_dir.DirBackend)
|
|
||||||
backend.close()
|
|
||||||
|
|
||||||
def test_file_persistence_entry_point(self):
|
|
||||||
conf = {
|
|
||||||
'connection': 'file:',
|
|
||||||
'path': self.path
|
|
||||||
}
|
|
||||||
with contextlib.closing(backends.fetch(conf)) as be:
|
with contextlib.closing(backends.fetch(conf)) as be:
|
||||||
self.assertIsInstance(be, impl_dir.DirBackend)
|
self.assertIsInstance(be, impl_dir.DirBackend)
|
||||||
|
|
||||||
|
def test_dir_backend_entry_point(self):
|
||||||
|
self._check_backend(dict(connection='dir:', path=self.path))
|
||||||
|
|
||||||
|
def test_dir_backend_name(self):
|
||||||
|
self._check_backend(dict(connection='dir', # no colon
|
||||||
|
path=self.path))
|
||||||
|
|
||||||
|
def test_file_backend_entry_point(self):
|
||||||
|
self._check_backend(dict(connection='file:', path=self.path))
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ class MemoryPersistenceTest(test.TestCase, base.PersistenceTestMixin):
|
|||||||
self._backend = None
|
self._backend = None
|
||||||
super(MemoryPersistenceTest, self).tearDown()
|
super(MemoryPersistenceTest, self).tearDown()
|
||||||
|
|
||||||
def test_memory_persistence_entry_point(self):
|
def test_memory_backend_entry_point(self):
|
||||||
conf = {'connection': 'memory:'}
|
conf = {'connection': 'memory:'}
|
||||||
with contextlib.closing(backends.fetch(conf)) as be:
|
with contextlib.closing(backends.fetch(conf)) as be:
|
||||||
self.assertIsInstance(be, impl_memory.MemoryBackend)
|
self.assertIsInstance(be, impl_memory.MemoryBackend)
|
||||||
|
|
||||||
|
def test_memory_backend_fetch_by_name(self):
|
||||||
|
conf = {'connection': 'memory'} # note no colon
|
||||||
|
with contextlib.closing(backends.fetch(conf)) as be:
|
||||||
|
self.assertIsInstance(be, impl_memory.MemoryBackend)
|
||||||
|
|||||||
Reference in New Issue
Block a user