Merge "Replace snet config with endpoint config"

This commit is contained in:
Jenkins 2015-02-03 20:15:06 +00:00 committed by Gerrit Code Review
commit bd04fbeed5
3 changed files with 52 additions and 35 deletions

View File

@ -46,9 +46,6 @@ DEFAULT_LARGE_OBJECT_CHUNK_SIZE = 200 # 200M
ONE_MB = 1000 * 1024
_SWIFT_OPTS = [
cfg.BoolOpt('swift_enable_snet', default=False,
help=_('Whether to use ServiceNET to communicate with the '
'Swift storage servers.')),
cfg.StrOpt('swift_store_auth_version', default='2',
help=_('Version of the authentication service to use. '
'Valid versions are 2 for keystone and 1 for swauth '
@ -63,6 +60,11 @@ _SWIFT_OPTS = [
help=_('The region of the swift endpoint to be used for '
'single tenant. This setting is only necessary if the '
'tenant has multiple swift endpoints.')),
cfg.StrOpt('swift_store_endpoint',
default=None,
help=_('If set, the configured endpoint will be used. If '
'None, the storage url from the auth response will be '
'used.')),
cfg.StrOpt('swift_store_endpoint_type', default='publicURL',
help=_('A string giving the endpoint type of the swift '
'service to use (publicURL, adminURL or internalURL). '
@ -387,8 +389,8 @@ class BaseStore(driver.Store):
self.admin_tenants = glance_conf.swift_store_admin_tenants
self.region = glance_conf.swift_store_region
self.service_type = glance_conf.swift_store_service_type
self.conf_endpoint = glance_conf.swift_store_endpoint
self.endpoint_type = glance_conf.swift_store_endpoint_type
self.snet = glance_conf.swift_enable_snet
self.insecure = glance_conf.swift_store_auth_insecure
self.ssl_compression = glance_conf.swift_store_ssl_compression
self.cacert = glance_conf.swift_store_cacert
@ -791,11 +793,10 @@ class SingleTenantStore(BaseStore):
os_options['service_type'] = self.service_type
return swiftclient.Connection(
auth_url, user, location.key, insecure=self.insecure,
tenant_name=tenant_name, snet=self.snet,
auth_url, user, location.key, preauthurl=self.conf_endpoint,
insecure=self.insecure, tenant_name=tenant_name,
auth_version=self.auth_version, os_options=os_options,
ssl_compression=self.ssl_compression,
cacert=self.cacert)
ssl_compression=self.ssl_compression, cacert=self.cacert)
class MultiTenantStore(BaseStore):
@ -812,9 +813,12 @@ class MultiTenantStore(BaseStore):
"a service catalog.")
raise exceptions.BadStoreConfiguration(store_name="swift",
reason=reason)
self.storage_url = auth.get_endpoint(
context.service_catalog, service_type=self.service_type,
endpoint_region=self.region, endpoint_type=self.endpoint_type)
self.storage_url = self.conf_endpoint
if not self.storage_url:
self.storage_url = auth.get_endpoint(
context.service_catalog, service_type=self.service_type,
endpoint_region=self.region, endpoint_type=self.endpoint_type)
if self.storage_url.startswith('http://'):
self.scheme = 'swift+http'
else:
@ -879,7 +883,7 @@ class MultiTenantStore(BaseStore):
preauthurl=location.swift_url,
preauthtoken=context.auth_token,
tenant_name=context.tenant,
auth_version='2', snet=self.snet, insecure=self.insecure,
auth_version='2', insecure=self.insecure,
ssl_compression=self.ssl_compression,
cacert=self.cacert)

View File

@ -88,7 +88,6 @@ class OptsTestCase(base.StoreBaseTest):
'sheepdog_store_address',
'sheepdog_store_chunk_size',
'sheepdog_store_port',
'swift_enable_snet',
'swift_store_admin_tenants',
'swift_store_auth_address',
'swift_store_cacert',
@ -97,6 +96,7 @@ class OptsTestCase(base.StoreBaseTest):
'swift_store_config_file',
'swift_store_container',
'swift_store_create_container_on_put',
'swift_store_endpoint',
'swift_store_endpoint_type',
'swift_store_key',
'swift_store_large_object_chunk_size',

View File

@ -195,7 +195,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version):
def fake_http_connection(*args, **kwargs):
return None
def fake_get_auth(url, user, key, snet, auth_version, **kwargs):
def fake_get_auth(url, user, key, auth_version, **kwargs):
if url is None:
return None, None
if 'http' in url and '://' not in url:
@ -964,10 +964,9 @@ class TestStoreAuthV2(TestStoreAuthV1):
class FakeConnection(object):
def __init__(self, authurl, user, key, retries=5, preauthurl=None,
preauthtoken=None, snet=False, starting_backoff=1,
tenant_name=None, os_options=None, auth_version="1",
insecure=False, ssl_compression=True,
cacert=None):
preauthtoken=None, starting_backoff=1, tenant_name=None,
os_options=None, auth_version="1", insecure=False,
ssl_compression=True, cacert=None):
if os_options is None:
os_options = {}
@ -976,7 +975,6 @@ class FakeConnection(object):
self.key = key
self.preauthurl = preauthurl
self.preauthtoken = preauthtoken
self.snet = snet
self.tenant_name = tenant_name
self.os_options = os_options
self.auth_version = auth_version
@ -1009,10 +1007,39 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
self.assertEqual(connection.auth_version, '2')
self.assertEqual(connection.user, 'user1')
self.assertEqual(connection.tenant_name, 'tenant')
self.assertFalse(connection.snet)
self.assertEqual(connection.key, 'key1')
self.assertIsNone(connection.preauthurl)
self.assertIsNone(connection.preauthtoken)
self.assertFalse(connection.insecure)
self.assertEqual(connection.os_options,
{'service_type': 'object-store',
'endpoint_type': 'publicURL'})
def test_connection_with_conf_endpoint(self):
ctx = context.RequestContext(user='tenant:user1', tenant='tenant')
self.config(swift_store_endpoint='https://internal.com')
self.store.configure()
connection = self.store.get_connection(self.location, context=ctx)
self.assertEqual(connection.authurl, 'https://example.com/v2/')
self.assertEqual(connection.auth_version, '2')
self.assertEqual(connection.user, 'user1')
self.assertEqual(connection.tenant_name, 'tenant')
self.assertEqual(connection.key, 'key1')
self.assertEqual(connection.preauthurl, 'https://internal.com')
self.assertFalse(connection.insecure)
self.assertEqual(connection.os_options,
{'service_type': 'object-store',
'endpoint_type': 'publicURL'})
def test_connection_with_conf_endpoint_no_context(self):
self.config(swift_store_endpoint='https://internal.com')
self.store.configure()
connection = self.store.get_connection(self.location)
self.assertEqual(connection.authurl, 'https://example.com/v2/')
self.assertEqual(connection.auth_version, '2')
self.assertEqual(connection.user, 'user1')
self.assertEqual(connection.tenant_name, 'tenant')
self.assertEqual(connection.key, 'key1')
self.assertEqual(connection.preauthurl, 'https://internal.com')
self.assertFalse(connection.insecure)
self.assertEqual(connection.os_options,
{'service_type': 'object-store',
@ -1075,12 +1102,6 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
{'service_type': 'object-store',
'endpoint_type': 'internalURL'})
def test_connection_with_snet(self):
self.config(swift_enable_snet=True)
self.store.configure()
connection = self.store.get_connection(self.location)
self.assertTrue(connection.snet)
def test_bad_location_uri(self):
self.store.configure()
self.location.uri = 'http://bad_uri://'
@ -1128,18 +1149,10 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
self.assertEqual(connection.user, 'tenant:user1')
self.assertEqual(connection.tenant_name, 'tenant')
self.assertIsNone(connection.key)
self.assertFalse(connection.snet)
self.assertEqual(connection.preauthurl, 'https://example.com')
self.assertEqual(connection.preauthtoken, '0123')
self.assertEqual(connection.os_options, {})
def test_connection_with_snet(self):
self.config(swift_enable_snet=True)
self.store.configure()
connection = self.store.get_connection(self.location,
context=self.context)
self.assertTrue(connection.snet)
class TestMultiTenantStoreContext(base.StoreBaseTest):