Merge "swift: Take into account swift_store_endpoint"

This commit is contained in:
Zuul 2021-08-11 10:11:23 +00:00 committed by Gerrit Code Review
commit 108947320d
3 changed files with 33 additions and 2 deletions

View File

@ -143,11 +143,16 @@ class SingleTenantConnectionManager(SwiftConnectionManager):
def _get_storage_url(self):
"""Get swift endpoint from keystone
Return endpoint for swift from service catalog. The method works only
Keystone v3. If you are using different version (1 or 2)
Return endpoint for swift from service catalog if not overridden in
store configuration. The method works only Keystone v3.
If you are using different version (1 or 2)
it returns None.
:return: swift endpoint
"""
if self.store.conf_endpoint:
return self.store.conf_endpoint
if self.store.auth_version == '3':
try:
return self.client.session.get_endpoint(

View File

@ -46,6 +46,7 @@ class TestConnectionManager(base.StoreBaseTest):
auth_version='3')
store.backend_group = None
store.conf_endpoint = None
store.init_client.return_value = self.client
return store

View File

@ -1534,6 +1534,31 @@ class TestSingleTenantStoreConnections(base.StoreBaseTest):
'endpoint_type': 'publicURL'},
connection.os_options)
@mock.patch("keystoneauth1.session.Session.get_endpoint")
@mock.patch("keystoneauth1.session.Session.get_auth_headers",
new=mock.Mock())
def _test_connection_manager_authv3_conf_endpoint(
self, mock_ep, expected_endpoint="https://from-catalog.com"):
self.config(swift_store_auth_version='3')
mock_ep.return_value = "https://from-catalog.com"
ctx = mock.MagicMock()
self.store.configure()
connection_manager = manager.SingleTenantConnectionManager(
store=self.store,
store_location=self.location,
context=ctx
)
conn = connection_manager._init_connection()
self.assertEqual(expected_endpoint, conn.preauthurl)
def test_connection_manager_authv3_without_conf_endpoint(self):
self._test_connection_manager_authv3_conf_endpoint()
def test_connection_manager_authv3_with_conf_endpoint(self):
self.config(swift_store_endpoint='http://localhost')
self._test_connection_manager_authv3_conf_endpoint(
expected_endpoint='http://localhost')
def test_connection_with_no_trailing_slash(self):
self.location.auth_or_store_url = 'example.com/v2'
connection = self.store.get_connection(self.location)