Merge "Change approach to request storage url for multi-tenant store"

This commit is contained in:
Jenkins 2016-02-24 21:03:00 +00:00 committed by Gerrit Code Review
commit d4eb2c9ed2
2 changed files with 63 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import hashlib
import logging
import math
from keystoneclient import exceptions as keystone_exc
from keystoneclient import service_catalog as keystone_sc
from oslo_config import cfg
from oslo_utils import encodeutils
@ -946,8 +947,15 @@ class MultiTenantStore(BaseStore):
return StoreLocation(specs, self.conf)
def get_connection(self, location, context=None):
try:
storage_url = self._get_endpoint(context)
except (exceptions.BadStoreConfiguration,
keystone_exc.EndpointNotFound) as e:
LOG.debug("Cannot obtain swift endpoint url from Service Catalog: "
"%s. Use url stored in database.", e)
storage_url = location.swift_url
return swiftclient.Connection(
preauthurl=location.swift_url,
preauthurl=storage_url,
preauthtoken=context.auth_token,
insecure=self.insecure,
ssl_compression=self.ssl_compression,

View File

@ -1365,7 +1365,7 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
self.location = swift.StoreLocation(specs, self.conf)
self.addCleanup(self.conf.reset)
def test_basic_connection(self):
def test_basic_connection_no_catalog(self):
self.store.configure()
connection = self.store.get_connection(self.location,
context=self.context)
@ -1378,6 +1378,59 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
self.assertEqual(connection.preauthtoken, '0123')
self.assertEqual(connection.os_options, {})
def test_connection_with_endpoint_from_catalog(self):
self.store.configure()
self.context.service_catalog = [
{
'endpoint_links': [],
'endpoints': [
{
'region': 'RegionOne',
'publicURL': 'https://scexample.com',
},
],
'type': 'object-store',
'name': 'Object Storage Service',
}
]
connection = self.store.get_connection(self.location,
context=self.context)
self.assertIsNone(connection.authurl)
self.assertEqual(connection.auth_version, '1')
self.assertIsNone(connection.user)
self.assertIsNone(connection.tenant_name)
self.assertIsNone(connection.key)
self.assertEqual(connection.preauthurl, 'https://scexample.com')
self.assertEqual(connection.preauthtoken, '0123')
self.assertEqual(connection.os_options, {})
def test_connection_with_no_endpoint_found(self):
self.store.configure()
self.context.service_catalog = [
{
'endpoint_links': [],
'endpoints': [
{
'region': 'RegionOne',
'publicURL': 'https://scexample.com',
},
],
'type': 'object-store',
'name': 'Object Storage Service',
}
]
self.store.service_type = 'incorrect-store'
connection = self.store.get_connection(self.location,
context=self.context)
self.assertIsNone(connection.authurl)
self.assertEqual(connection.auth_version, '1')
self.assertIsNone(connection.user)
self.assertIsNone(connection.tenant_name)
self.assertIsNone(connection.key)
self.assertEqual(connection.preauthurl, 'https://example.com')
self.assertEqual(connection.preauthtoken, '0123')
self.assertEqual(connection.os_options, {})
class TestMultiTenantStoreContext(base.StoreBaseTest):