Merge "Replace snet config with endpoint config"
This commit is contained in:
commit
bd04fbeed5
@ -46,9 +46,6 @@ DEFAULT_LARGE_OBJECT_CHUNK_SIZE = 200 # 200M
|
|||||||
ONE_MB = 1000 * 1024
|
ONE_MB = 1000 * 1024
|
||||||
|
|
||||||
_SWIFT_OPTS = [
|
_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',
|
cfg.StrOpt('swift_store_auth_version', default='2',
|
||||||
help=_('Version of the authentication service to use. '
|
help=_('Version of the authentication service to use. '
|
||||||
'Valid versions are 2 for keystone and 1 for swauth '
|
'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 '
|
help=_('The region of the swift endpoint to be used for '
|
||||||
'single tenant. This setting is only necessary if the '
|
'single tenant. This setting is only necessary if the '
|
||||||
'tenant has multiple swift endpoints.')),
|
'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',
|
cfg.StrOpt('swift_store_endpoint_type', default='publicURL',
|
||||||
help=_('A string giving the endpoint type of the swift '
|
help=_('A string giving the endpoint type of the swift '
|
||||||
'service to use (publicURL, adminURL or internalURL). '
|
'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.admin_tenants = glance_conf.swift_store_admin_tenants
|
||||||
self.region = glance_conf.swift_store_region
|
self.region = glance_conf.swift_store_region
|
||||||
self.service_type = glance_conf.swift_store_service_type
|
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.endpoint_type = glance_conf.swift_store_endpoint_type
|
||||||
self.snet = glance_conf.swift_enable_snet
|
|
||||||
self.insecure = glance_conf.swift_store_auth_insecure
|
self.insecure = glance_conf.swift_store_auth_insecure
|
||||||
self.ssl_compression = glance_conf.swift_store_ssl_compression
|
self.ssl_compression = glance_conf.swift_store_ssl_compression
|
||||||
self.cacert = glance_conf.swift_store_cacert
|
self.cacert = glance_conf.swift_store_cacert
|
||||||
@ -791,11 +793,10 @@ class SingleTenantStore(BaseStore):
|
|||||||
os_options['service_type'] = self.service_type
|
os_options['service_type'] = self.service_type
|
||||||
|
|
||||||
return swiftclient.Connection(
|
return swiftclient.Connection(
|
||||||
auth_url, user, location.key, insecure=self.insecure,
|
auth_url, user, location.key, preauthurl=self.conf_endpoint,
|
||||||
tenant_name=tenant_name, snet=self.snet,
|
insecure=self.insecure, tenant_name=tenant_name,
|
||||||
auth_version=self.auth_version, os_options=os_options,
|
auth_version=self.auth_version, os_options=os_options,
|
||||||
ssl_compression=self.ssl_compression,
|
ssl_compression=self.ssl_compression, cacert=self.cacert)
|
||||||
cacert=self.cacert)
|
|
||||||
|
|
||||||
|
|
||||||
class MultiTenantStore(BaseStore):
|
class MultiTenantStore(BaseStore):
|
||||||
@ -812,9 +813,12 @@ class MultiTenantStore(BaseStore):
|
|||||||
"a service catalog.")
|
"a service catalog.")
|
||||||
raise exceptions.BadStoreConfiguration(store_name="swift",
|
raise exceptions.BadStoreConfiguration(store_name="swift",
|
||||||
reason=reason)
|
reason=reason)
|
||||||
self.storage_url = auth.get_endpoint(
|
self.storage_url = self.conf_endpoint
|
||||||
context.service_catalog, service_type=self.service_type,
|
if not self.storage_url:
|
||||||
endpoint_region=self.region, endpoint_type=self.endpoint_type)
|
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://'):
|
if self.storage_url.startswith('http://'):
|
||||||
self.scheme = 'swift+http'
|
self.scheme = 'swift+http'
|
||||||
else:
|
else:
|
||||||
@ -879,7 +883,7 @@ class MultiTenantStore(BaseStore):
|
|||||||
preauthurl=location.swift_url,
|
preauthurl=location.swift_url,
|
||||||
preauthtoken=context.auth_token,
|
preauthtoken=context.auth_token,
|
||||||
tenant_name=context.tenant,
|
tenant_name=context.tenant,
|
||||||
auth_version='2', snet=self.snet, insecure=self.insecure,
|
auth_version='2', insecure=self.insecure,
|
||||||
ssl_compression=self.ssl_compression,
|
ssl_compression=self.ssl_compression,
|
||||||
cacert=self.cacert)
|
cacert=self.cacert)
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ class OptsTestCase(base.StoreBaseTest):
|
|||||||
'sheepdog_store_address',
|
'sheepdog_store_address',
|
||||||
'sheepdog_store_chunk_size',
|
'sheepdog_store_chunk_size',
|
||||||
'sheepdog_store_port',
|
'sheepdog_store_port',
|
||||||
'swift_enable_snet',
|
|
||||||
'swift_store_admin_tenants',
|
'swift_store_admin_tenants',
|
||||||
'swift_store_auth_address',
|
'swift_store_auth_address',
|
||||||
'swift_store_cacert',
|
'swift_store_cacert',
|
||||||
@ -97,6 +96,7 @@ class OptsTestCase(base.StoreBaseTest):
|
|||||||
'swift_store_config_file',
|
'swift_store_config_file',
|
||||||
'swift_store_container',
|
'swift_store_container',
|
||||||
'swift_store_create_container_on_put',
|
'swift_store_create_container_on_put',
|
||||||
|
'swift_store_endpoint',
|
||||||
'swift_store_endpoint_type',
|
'swift_store_endpoint_type',
|
||||||
'swift_store_key',
|
'swift_store_key',
|
||||||
'swift_store_large_object_chunk_size',
|
'swift_store_large_object_chunk_size',
|
||||||
|
@ -195,7 +195,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version):
|
|||||||
def fake_http_connection(*args, **kwargs):
|
def fake_http_connection(*args, **kwargs):
|
||||||
return None
|
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:
|
if url is None:
|
||||||
return None, None
|
return None, None
|
||||||
if 'http' in url and '://' not in url:
|
if 'http' in url and '://' not in url:
|
||||||
@ -964,10 +964,9 @@ class TestStoreAuthV2(TestStoreAuthV1):
|
|||||||
|
|
||||||
class FakeConnection(object):
|
class FakeConnection(object):
|
||||||
def __init__(self, authurl, user, key, retries=5, preauthurl=None,
|
def __init__(self, authurl, user, key, retries=5, preauthurl=None,
|
||||||
preauthtoken=None, snet=False, starting_backoff=1,
|
preauthtoken=None, starting_backoff=1, tenant_name=None,
|
||||||
tenant_name=None, os_options=None, auth_version="1",
|
os_options=None, auth_version="1", insecure=False,
|
||||||
insecure=False, ssl_compression=True,
|
ssl_compression=True, cacert=None):
|
||||||
cacert=None):
|
|
||||||
if os_options is None:
|
if os_options is None:
|
||||||
os_options = {}
|
os_options = {}
|
||||||
|
|
||||||
@ -976,7 +975,6 @@ class FakeConnection(object):
|
|||||||
self.key = key
|
self.key = key
|
||||||
self.preauthurl = preauthurl
|
self.preauthurl = preauthurl
|
||||||
self.preauthtoken = preauthtoken
|
self.preauthtoken = preauthtoken
|
||||||
self.snet = snet
|
|
||||||
self.tenant_name = tenant_name
|
self.tenant_name = tenant_name
|
||||||
self.os_options = os_options
|
self.os_options = os_options
|
||||||
self.auth_version = auth_version
|
self.auth_version = auth_version
|
||||||
@ -1009,10 +1007,39 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
|
|||||||
self.assertEqual(connection.auth_version, '2')
|
self.assertEqual(connection.auth_version, '2')
|
||||||
self.assertEqual(connection.user, 'user1')
|
self.assertEqual(connection.user, 'user1')
|
||||||
self.assertEqual(connection.tenant_name, 'tenant')
|
self.assertEqual(connection.tenant_name, 'tenant')
|
||||||
self.assertFalse(connection.snet)
|
|
||||||
self.assertEqual(connection.key, 'key1')
|
self.assertEqual(connection.key, 'key1')
|
||||||
self.assertIsNone(connection.preauthurl)
|
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.assertFalse(connection.insecure)
|
||||||
self.assertEqual(connection.os_options,
|
self.assertEqual(connection.os_options,
|
||||||
{'service_type': 'object-store',
|
{'service_type': 'object-store',
|
||||||
@ -1075,12 +1102,6 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
|
|||||||
{'service_type': 'object-store',
|
{'service_type': 'object-store',
|
||||||
'endpoint_type': 'internalURL'})
|
'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):
|
def test_bad_location_uri(self):
|
||||||
self.store.configure()
|
self.store.configure()
|
||||||
self.location.uri = 'http://bad_uri://'
|
self.location.uri = 'http://bad_uri://'
|
||||||
@ -1128,18 +1149,10 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest):
|
|||||||
self.assertEqual(connection.user, 'tenant:user1')
|
self.assertEqual(connection.user, 'tenant:user1')
|
||||||
self.assertEqual(connection.tenant_name, 'tenant')
|
self.assertEqual(connection.tenant_name, 'tenant')
|
||||||
self.assertIsNone(connection.key)
|
self.assertIsNone(connection.key)
|
||||||
self.assertFalse(connection.snet)
|
|
||||||
self.assertEqual(connection.preauthurl, 'https://example.com')
|
self.assertEqual(connection.preauthurl, 'https://example.com')
|
||||||
self.assertEqual(connection.preauthtoken, '0123')
|
self.assertEqual(connection.preauthtoken, '0123')
|
||||||
self.assertEqual(connection.os_options, {})
|
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):
|
class TestMultiTenantStoreContext(base.StoreBaseTest):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user