summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--os_client_config/cloud_config.py6
-rw-r--r--os_client_config/tests/test_cloud_config.py38
2 files changed, 39 insertions, 5 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index 32fd3b6..3174f60 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -297,7 +297,7 @@ class CloudConfig(object):
endpoint = self.get_session_endpoint(service_key='object-store')
if not endpoint:
return None
- return client_class(
+ swift_kwargs = dict(
preauthurl=endpoint,
preauthtoken=token,
auth_version=self.get_api_version('identity'),
@@ -305,8 +305,10 @@ class CloudConfig(object):
auth_token=token,
object_storage_url=endpoint,
region_name=self.get_region_name()),
- timeout=self.api_timeout,
)
+ if self.config['api_timeout'] is not None:
+ swift_kwargs['timeout'] = float(self.config['api_timeout'])
+ return client_class(**swift_kwargs)
def get_cache_expiration_time(self):
if self._openstack_config:
diff --git a/os_client_config/tests/test_cloud_config.py b/os_client_config/tests/test_cloud_config.py
index be2b8fe..45d262f 100644
--- a/os_client_config/tests/test_cloud_config.py
+++ b/os_client_config/tests/test_cloud_config.py
@@ -169,6 +169,18 @@ class TestCloudConfig(base.TestCase):
verify=True, cert=None, timeout=None)
@mock.patch.object(ksa_session, 'Session')
+ def test_get_session_with_timeout(self, mock_session):
+ config_dict = defaults.get_defaults()
+ config_dict.update(fake_services_dict)
+ config_dict['api_timeout'] = 9
+ cc = cloud_config.CloudConfig(
+ "test1", "region-al", config_dict, auth_plugin=mock.Mock())
+ cc.get_session()
+ mock_session.assert_called_with(
+ auth=mock.ANY,
+ verify=True, cert=None, timeout=9)
+
+ @mock.patch.object(ksa_session, 'Session')
def test_override_session_endpoint(self, mock_session):
config_dict = defaults.get_defaults()
config_dict.update(fake_services_dict)
@@ -222,8 +234,29 @@ class TestCloudConfig(base.TestCase):
'object_storage_url': 'http://example.com/v2'
},
preauthurl='http://example.com/v2',
+ auth_version='2.0')
+
+ @mock.patch.object(cloud_config.CloudConfig, 'get_session_endpoint')
+ def test_legacy_client_object_store_timeout(
+ self, mock_get_session_endpoint):
+ mock_client = mock.Mock()
+ mock_get_session_endpoint.return_value = 'http://example.com/v2'
+ config_dict = defaults.get_defaults()
+ config_dict.update(fake_services_dict)
+ config_dict['api_timeout'] = 9
+ cc = cloud_config.CloudConfig(
+ "test1", "region-al", config_dict, auth_plugin=mock.Mock())
+ cc.get_legacy_client('object-store', mock_client)
+ mock_client.assert_called_with(
+ preauthtoken=mock.ANY,
+ os_options={
+ 'auth_token': mock.ANY,
+ 'region_name': 'region-al',
+ 'object_storage_url': 'http://example.com/v2'
+ },
+ preauthurl='http://example.com/v2',
auth_version='2.0',
- timeout=None)
+ timeout=9.0)
def test_legacy_client_object_store_endpoint(self):
mock_client = mock.Mock()
@@ -241,8 +274,7 @@ class TestCloudConfig(base.TestCase):
'object_storage_url': 'http://example.com/v2'
},
preauthurl='http://example.com/v2',
- auth_version='2.0',
- timeout=None)
+ auth_version='2.0')
@mock.patch.object(cloud_config.CloudConfig, 'get_session_endpoint')
def test_legacy_client_image(self, mock_get_session_endpoint):