Pass region_name to SwiftAPI
Currently when SwiftAPI(common/swift.py) is initialized, region_name is not specified; with multi-region setup, ironic may pick wrong swift endpoint. This fix loads region_name from keystone_authtoken/region_name, and pass the value to SwiftAPI Closes-Bug: #1554933 Change-Id: I7295fc96c3b9ed50214576e80723d1d9db1a7e38
This commit is contained in:
parent
ec76063870
commit
11db34a48a
@ -50,6 +50,8 @@ CONF.import_opt('insecure', 'keystonemiddleware.auth_token',
|
|||||||
group='keystone_authtoken')
|
group='keystone_authtoken')
|
||||||
CONF.import_opt('cafile', 'keystonemiddleware.auth_token',
|
CONF.import_opt('cafile', 'keystonemiddleware.auth_token',
|
||||||
group='keystone_authtoken')
|
group='keystone_authtoken')
|
||||||
|
CONF.import_opt('region_name', 'keystonemiddleware.auth_token',
|
||||||
|
group='keystone_authtoken')
|
||||||
|
|
||||||
|
|
||||||
class SwiftAPI(object):
|
class SwiftAPI(object):
|
||||||
@ -60,7 +62,8 @@ class SwiftAPI(object):
|
|||||||
tenant_name=None,
|
tenant_name=None,
|
||||||
key=None,
|
key=None,
|
||||||
auth_url=None,
|
auth_url=None,
|
||||||
auth_version=None):
|
auth_version=None,
|
||||||
|
region_name=None):
|
||||||
"""Constructor for creating a SwiftAPI object.
|
"""Constructor for creating a SwiftAPI object.
|
||||||
|
|
||||||
:param user: the name of the user for Swift account
|
:param user: the name of the user for Swift account
|
||||||
@ -68,6 +71,7 @@ class SwiftAPI(object):
|
|||||||
:param key: the 'password' or key to authenticate with
|
:param key: the 'password' or key to authenticate with
|
||||||
:param auth_url: the url for authentication
|
:param auth_url: the url for authentication
|
||||||
:param auth_version: the version of api to use for authentication
|
:param auth_version: the version of api to use for authentication
|
||||||
|
:param region_name: the region used for getting endpoints of swift
|
||||||
"""
|
"""
|
||||||
user = user or CONF.keystone_authtoken.admin_user
|
user = user or CONF.keystone_authtoken.admin_user
|
||||||
tenant_name = tenant_name or CONF.keystone_authtoken.admin_tenant_name
|
tenant_name = tenant_name or CONF.keystone_authtoken.admin_tenant_name
|
||||||
@ -83,6 +87,9 @@ class SwiftAPI(object):
|
|||||||
'key': key,
|
'key': key,
|
||||||
'authurl': auth_url,
|
'authurl': auth_url,
|
||||||
'auth_version': auth_version}
|
'auth_version': auth_version}
|
||||||
|
region_name = region_name or CONF.keystone_authtoken.region_name
|
||||||
|
if region_name:
|
||||||
|
params['os_options'] = {'region_name': region_name}
|
||||||
|
|
||||||
self.connection = swift_client.Connection(**params)
|
self.connection = swift_client.Connection(**params)
|
||||||
|
|
||||||
|
@ -47,17 +47,30 @@ class SwiftTestCase(base.TestCase):
|
|||||||
self.config(swift_max_retries=2, group='swift')
|
self.config(swift_max_retries=2, group='swift')
|
||||||
self.config(insecure=0, group='keystone_authtoken')
|
self.config(insecure=0, group='keystone_authtoken')
|
||||||
self.config(cafile='/path/to/ca/file', group='keystone_authtoken')
|
self.config(cafile='/path/to/ca/file', group='keystone_authtoken')
|
||||||
|
self.expected_params = {'retries': 2,
|
||||||
|
'insecure': 0,
|
||||||
|
'user': 'admin',
|
||||||
|
'tenant_name': 'tenant',
|
||||||
|
'key': 'password',
|
||||||
|
'authurl': 'http://authurl/v2.0',
|
||||||
|
'cacert': '/path/to/ca/file',
|
||||||
|
'auth_version': '2'}
|
||||||
|
|
||||||
def test___init__(self, connection_mock):
|
def test___init__(self, connection_mock):
|
||||||
swift.SwiftAPI()
|
swift.SwiftAPI()
|
||||||
params = {'retries': 2,
|
connection_mock.assert_called_once_with(**self.expected_params)
|
||||||
'insecure': 0,
|
|
||||||
'user': 'admin',
|
def test__init__with_region_from_config(self, connection_mock):
|
||||||
'tenant_name': 'tenant',
|
self.config(region_name='region1', group='keystone_authtoken')
|
||||||
'key': 'password',
|
swift.SwiftAPI()
|
||||||
'authurl': 'http://authurl/v2.0',
|
params = self.expected_params.copy()
|
||||||
'cacert': '/path/to/ca/file',
|
params['os_options'] = {'region_name': 'region1'}
|
||||||
'auth_version': '2'}
|
connection_mock.assert_called_once_with(**params)
|
||||||
|
|
||||||
|
def test__init__with_region_from_constructor(self, connection_mock):
|
||||||
|
swift.SwiftAPI(region_name='region1')
|
||||||
|
params = self.expected_params.copy()
|
||||||
|
params['os_options'] = {'region_name': 'region1'}
|
||||||
connection_mock.assert_called_once_with(**params)
|
connection_mock.assert_called_once_with(**params)
|
||||||
|
|
||||||
@mock.patch.object(__builtin__, 'open', autospec=True)
|
@mock.patch.object(__builtin__, 'open', autospec=True)
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Fixes a bug where the keystone_authtoken/region_name wasn't passed
|
||||||
|
to Swift when instantiating its client, in a multi-region environment
|
||||||
|
this is needed so the client can choose the correct swift endpoint.
|
Loading…
Reference in New Issue
Block a user