Merge "Use storage_url in DB for multi-tenant swift store"
This commit is contained in:
commit
32bdeddfb1
|
@ -18,7 +18,6 @@ connection with valid credentials and updated token"""
|
|||
|
||||
import logging
|
||||
|
||||
from keystoneauth1 import exceptions as ks_exceptions
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
from glance_store import exceptions
|
||||
|
@ -188,13 +187,7 @@ class MultiTenantConnectionManager(SwiftConnectionManager):
|
|||
self.client.trusts.delete(self.client.trust_id)
|
||||
|
||||
def _get_storage_url(self):
|
||||
try:
|
||||
return self.store._get_endpoint(self.context)
|
||||
except (exceptions.BadStoreConfiguration,
|
||||
ks_exceptions.EndpointNotFound) as e:
|
||||
LOG.debug("Cannot obtain endpoint from context: %s. Use location "
|
||||
"value from database to obtain swift_url.", e)
|
||||
return self.location.swift_url
|
||||
return self.location.swift_url
|
||||
|
||||
def _init_connection(self):
|
||||
if self.allow_reauth:
|
||||
|
|
|
@ -20,7 +20,6 @@ import logging
|
|||
import math
|
||||
|
||||
from keystoneauth1.access import service_catalog as keystone_sc
|
||||
from keystoneauth1 import exceptions as keystone_exc
|
||||
from keystoneauth1 import identity as ks_identity
|
||||
from keystoneauth1 import session as ks_session
|
||||
from keystoneclient.v3 import client as ks_client
|
||||
|
@ -1368,15 +1367,8 @@ 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=storage_url,
|
||||
preauthurl=location.swift_url,
|
||||
preauthtoken=context.auth_token,
|
||||
insecure=self.insecure,
|
||||
ssl_compression=self.ssl_compression,
|
||||
|
|
|
@ -71,7 +71,6 @@ class TestConnectionManager(base.StoreBaseTest):
|
|||
store_location=self.location,
|
||||
context=self.context
|
||||
)
|
||||
store._get_endpoint.assert_called_once_with(self.context)
|
||||
store.get_store_connection.assert_called_once_with(
|
||||
self.context.auth_token, manager.storage_url)
|
||||
|
||||
|
@ -92,7 +91,6 @@ class TestConnectionManager(base.StoreBaseTest):
|
|||
)
|
||||
store.init_client.assert_called_once_with(self.location,
|
||||
self.context)
|
||||
store._get_endpoint.assert_called_once_with(self.context)
|
||||
store.get_store_connection.assert_called_once_with(
|
||||
self.context.auth_token, manager.storage_url)
|
||||
self.assertFalse(manager.allow_reauth)
|
||||
|
@ -107,7 +105,6 @@ class TestConnectionManager(base.StoreBaseTest):
|
|||
)
|
||||
store.init_client.assert_called_once_with(self.location,
|
||||
self.context)
|
||||
store._get_endpoint.assert_called_once_with(self.context)
|
||||
# return the same connection because it should not be expired
|
||||
auth_ref = mock.MagicMock()
|
||||
self.client.session.auth.get_auth_ref.return_value = auth_ref
|
||||
|
@ -128,7 +125,6 @@ class TestConnectionManager(base.StoreBaseTest):
|
|||
)
|
||||
store.init_client.assert_called_once_with(self.location,
|
||||
self.context)
|
||||
store._get_endpoint.assert_called_once_with(self.context)
|
||||
# return the same connection because it should not be expired
|
||||
auth_ref = mock.MagicMock()
|
||||
self.client.session.auth.get_auth_ref.return_value = auth_ref
|
||||
|
|
|
@ -34,6 +34,7 @@ from six.moves import http_client
|
|||
from six.moves import range
|
||||
import swiftclient
|
||||
|
||||
from glance_store._drivers.swift import connection_manager as manager
|
||||
from glance_store._drivers.swift import store as swift
|
||||
from glance_store._drivers.swift import utils as sutils
|
||||
from glance_store import backend
|
||||
|
@ -402,6 +403,50 @@ class SwiftTests(object):
|
|||
expected_swift_size)
|
||||
self.assertEqual(expected_location, location)
|
||||
|
||||
@mock.patch('glance_store._drivers.swift.utils'
|
||||
'.is_multiple_swift_store_accounts_enabled',
|
||||
mock.Mock(return_value=False))
|
||||
def test_multi_tenant_image_add_uses_users_context(self):
|
||||
expected_swift_size = FIVE_KB
|
||||
expected_swift_contents = b"*" * expected_swift_size
|
||||
expected_image_id = str(uuid.uuid4())
|
||||
expected_container = 'container_' + expected_image_id
|
||||
loc = 'swift+https://some_endpoint/%s/%s'
|
||||
expected_location = loc % (expected_container, expected_image_id)
|
||||
image_swift = six.BytesIO(expected_swift_contents)
|
||||
|
||||
global SWIFT_PUT_OBJECT_CALLS
|
||||
SWIFT_PUT_OBJECT_CALLS = 0
|
||||
|
||||
self.config(swift_store_container='container')
|
||||
self.config(swift_store_create_container_on_put=True)
|
||||
self.config(swift_store_multi_tenant=True)
|
||||
service_catalog = [
|
||||
{
|
||||
'endpoint_links': [],
|
||||
'endpoints': [
|
||||
{
|
||||
'adminURL': 'https://some_admin_endpoint',
|
||||
'region': 'RegionOne',
|
||||
'internalURL': 'https://some_internal_endpoint',
|
||||
'publicURL': 'https://some_endpoint',
|
||||
},
|
||||
],
|
||||
'type': 'object-store',
|
||||
'name': 'Object Storage Service',
|
||||
}
|
||||
]
|
||||
ctxt = mock.MagicMock(
|
||||
user='user', tenant='tenant', auth_token='123',
|
||||
service_catalog=service_catalog)
|
||||
store = swift.MultiTenantStore(self.conf)
|
||||
store.configure()
|
||||
loc, size, checksum, _ = store.add(expected_image_id, image_swift,
|
||||
expected_swift_size,
|
||||
context=ctxt)
|
||||
# ensure that image add uses user's context
|
||||
self.assertEqual(expected_location, loc)
|
||||
|
||||
@mock.patch('glance_store._drivers.swift.utils'
|
||||
'.is_multiple_swift_store_accounts_enabled',
|
||||
mock.Mock(return_value=True))
|
||||
|
@ -1518,7 +1563,7 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||
self.location = swift.StoreLocation(specs, self.conf)
|
||||
self.addCleanup(self.conf.reset)
|
||||
|
||||
def test_basic_connection_no_catalog(self):
|
||||
def test_basic_connection(self):
|
||||
self.store.configure()
|
||||
connection = self.store.get_connection(self.location,
|
||||
context=self.context)
|
||||
|
@ -1531,7 +1576,7 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||
self.assertEqual('0123', connection.preauthtoken)
|
||||
self.assertEqual({}, connection.os_options)
|
||||
|
||||
def test_connection_with_endpoint_from_catalog(self):
|
||||
def test_connection_does_not_use_endpoint_from_catalog(self):
|
||||
self.store.configure()
|
||||
self.context.service_catalog = [
|
||||
{
|
||||
|
@ -1553,11 +1598,12 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||
self.assertIsNone(connection.user)
|
||||
self.assertIsNone(connection.tenant_name)
|
||||
self.assertIsNone(connection.key)
|
||||
self.assertEqual('https://scexample.com', connection.preauthurl)
|
||||
self.assertNotEqual('https://scexample.com', connection.preauthurl)
|
||||
self.assertEqual('https://example.com', connection.preauthurl)
|
||||
self.assertEqual('0123', connection.preauthtoken)
|
||||
self.assertEqual({}, connection.os_options)
|
||||
|
||||
def test_connection_with_no_endpoint_found(self):
|
||||
def test_connection_manager_does_not_use_endpoint_from_catalog(self):
|
||||
self.store.configure()
|
||||
self.context.service_catalog = [
|
||||
{
|
||||
|
@ -1572,17 +1618,14 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||
'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('1', connection.auth_version)
|
||||
self.assertIsNone(connection.user)
|
||||
self.assertIsNone(connection.tenant_name)
|
||||
self.assertIsNone(connection.key)
|
||||
self.assertEqual('https://example.com', connection.preauthurl)
|
||||
self.assertEqual('0123', connection.preauthtoken)
|
||||
self.assertEqual({}, connection.os_options)
|
||||
connection_manager = manager.MultiTenantConnectionManager(
|
||||
store=self.store,
|
||||
store_location=self.location,
|
||||
context=self.context
|
||||
)
|
||||
conn = connection_manager._init_connection()
|
||||
self.assertNotEqual('https://scexample.com', conn.preauthurl)
|
||||
self.assertEqual('https://example.com', conn.preauthurl)
|
||||
|
||||
|
||||
class TestMultiTenantStoreContext(base.StoreBaseTest):
|
||||
|
|
Loading…
Reference in New Issue