summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keystoneauth1/adapter.py10
-rw-r--r--keystoneauth1/tests/unit/test_session.py27
2 files changed, 36 insertions, 1 deletions
diff --git a/keystoneauth1/adapter.py b/keystoneauth1/adapter.py
index 11ce228..13ec12e 100644
--- a/keystoneauth1/adapter.py
+++ b/keystoneauth1/adapter.py
@@ -88,6 +88,10 @@ class Adapter(object):
88 should be retried (optional, 88 should be retried (optional,
89 defaults to HTTP 503, has no effect 89 defaults to HTTP 503, has no effect
90 when status_code_retries is 0). 90 when status_code_retries is 0).
91 :param bool raise_exc: If True, requests returning failing HTTP responses
92 will raise an exception; if False, the response is
93 returned. This can be overridden on a per-request
94 basis via the kwarg of the same name.
91 """ 95 """
92 96
93 client_name = None 97 client_name = None
@@ -102,7 +106,7 @@ class Adapter(object):
102 global_request_id=None, 106 global_request_id=None,
103 min_version=None, max_version=None, 107 min_version=None, max_version=None,
104 default_microversion=None, status_code_retries=None, 108 default_microversion=None, status_code_retries=None,
105 retriable_status_codes=None): 109 retriable_status_codes=None, raise_exc=None):
106 if version and (min_version or max_version): 110 if version and (min_version or max_version):
107 raise TypeError( 111 raise TypeError(
108 "version is mutually exclusive with min_version and" 112 "version is mutually exclusive with min_version and"
@@ -131,6 +135,7 @@ class Adapter(object):
131 self.default_microversion = default_microversion 135 self.default_microversion = default_microversion
132 self.status_code_retries = status_code_retries 136 self.status_code_retries = status_code_retries
133 self.retriable_status_codes = retriable_status_codes 137 self.retriable_status_codes = retriable_status_codes
138 self.raise_exc = raise_exc
134 139
135 self.global_request_id = global_request_id 140 self.global_request_id = global_request_id
136 141
@@ -202,6 +207,9 @@ class Adapter(object):
202 kwargs.setdefault('headers', {}).setdefault( 207 kwargs.setdefault('headers', {}).setdefault(
203 "X-OpenStack-Request-ID", self.global_request_id) 208 "X-OpenStack-Request-ID", self.global_request_id)
204 209
210 if self.raise_exc is not None:
211 kwargs.setdefault('raise_exc', self.raise_exc)
212
205 return self.session.request(url, method, **kwargs) 213 return self.session.request(url, method, **kwargs)
206 214
207 def get_token(self, auth=None): 215 def get_token(self, auth=None):
diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py
index 29047bc..09c7cd5 100644
--- a/keystoneauth1/tests/unit/test_session.py
+++ b/keystoneauth1/tests/unit/test_session.py
@@ -1580,6 +1580,33 @@ class AdapterTest(utils.TestCase):
1580 validate({'default_microversion': '1.2'}, {'microversion': '1.5'}, 1580 validate({'default_microversion': '1.2'}, {'microversion': '1.5'},
1581 {'microversion': '1.5'}) 1581 {'microversion': '1.5'})
1582 1582
1583 def test_raise_exc_override(self):
1584 sess = client_session.Session()
1585 url = 'http://url'
1586
1587 def validate(adap_kwargs, get_kwargs, exp_kwargs):
1588 with mock.patch.object(sess, 'request') as m:
1589 adapter.Adapter(sess, **adap_kwargs).get(url, **get_kwargs)
1590 m.assert_called_once_with(url, 'GET', endpoint_filter={},
1591 **exp_kwargs)
1592
1593 # No raise_exc in Adapter or get()
1594 validate({}, {}, {})
1595
1596 # Set in Adapter, unset in get()
1597 validate({'raise_exc': True}, {}, {'raise_exc': True})
1598 validate({'raise_exc': False}, {}, {'raise_exc': False})
1599
1600 # Unset in Adapter, set in get()
1601 validate({}, {'raise_exc': True}, {'raise_exc': True})
1602 validate({}, {'raise_exc': False}, {'raise_exc': False})
1603
1604 # Setting in get() overrides the one in Adapter
1605 validate({'raise_exc': True}, {'raise_exc': False},
1606 {'raise_exc': False})
1607 validate({'raise_exc': False}, {'raise_exc': True},
1608 {'raise_exc': True})
1609
1583 1610
1584class TCPKeepAliveAdapterTest(utils.TestCase): 1611class TCPKeepAliveAdapterTest(utils.TestCase):
1585 1612