Fix bypass_url and errors with no headers
When using bypass_url the endpoint_override needs to be set in the SessionClient. Don't assume all responses have a Content-Type Fixes Bug: 1532278 Change-Id: I5e1319aae28e16448e20dd2b41836341f3156c59
This commit is contained in:
parent
e9452a6e7c
commit
fcfbc40162
@ -295,6 +295,7 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
||||
|
||||
kwargs.setdefault('user_agent', self.user_agent)
|
||||
kwargs.setdefault('auth', self.auth)
|
||||
kwargs.setdefault('endpoint_override', self.endpoint_override)
|
||||
|
||||
endpoint_filter = kwargs.setdefault('endpoint_filter', {})
|
||||
endpoint_filter.setdefault('interface', self.interface)
|
||||
|
@ -61,7 +61,7 @@ def from_response(response, message=None, traceback=None, method=None,
|
||||
# NOTE(hongbin): This allows SessionClient to handle faultstring.
|
||||
response.json = lambda: {'error': error_body}
|
||||
|
||||
if (response.headers['Content-Type'].startswith('text/') and
|
||||
if (response.headers.get('Content-Type', '').startswith('text/') and
|
||||
not hasattr(response, 'text')):
|
||||
# NOTE(clif_h): There seems to be a case in the
|
||||
# openstack.common.apiclient.exceptions module where if the
|
||||
|
@ -15,10 +15,12 @@
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from magnumclient.common import httpclient as http
|
||||
from magnumclient import exceptions as exc
|
||||
from magnumclient.openstack.common.apiclient.exceptions import GatewayTimeout
|
||||
from magnumclient.tests import utils
|
||||
|
||||
|
||||
@ -269,3 +271,29 @@ class SessionClientTest(utils.BaseTestCase):
|
||||
'GET', '/v1/resources')
|
||||
|
||||
self.assertEqual('Internal Server Error (HTTP 500)', str(error))
|
||||
|
||||
def test_bypass_url(self):
|
||||
fake_response = utils.FakeSessionResponse(
|
||||
{}, content="", status_code=201)
|
||||
fake_session = mock.MagicMock()
|
||||
fake_session.request.side_effect = [fake_response]
|
||||
|
||||
client = http.SessionClient(
|
||||
session=fake_session, endpoint_override='http://magnum')
|
||||
|
||||
client.json_request('GET', '/v1/bays')
|
||||
self.assertEqual(
|
||||
fake_session.request.call_args[1]['endpoint_override'],
|
||||
'http://magnum'
|
||||
)
|
||||
|
||||
def test_exception(self):
|
||||
fake_response = utils.FakeSessionResponse(
|
||||
{}, content="", status_code=504)
|
||||
fake_session = mock.MagicMock()
|
||||
fake_session.request.side_effect = [fake_response]
|
||||
client = http.SessionClient(
|
||||
session=fake_session, endpoint_override='http://magnum')
|
||||
self.assertRaises(GatewayTimeout,
|
||||
client.json_request,
|
||||
'GET', '/v1/resources')
|
||||
|
Loading…
Reference in New Issue
Block a user