Fix failures when calling list operations using Python binding

This bug is caused because of the regression caused by
I1b719bed406b83c5f2deac06e127798a91f51ad7 . The original bug was
raised because check_max_uri was not working after the introduction
of sessionclient.  The change created a regression in which the
python bindings of the neutron client was not usable and causing
traces.

The fix is to revert the change id and add a new check_max_uri to
the sessionclient.  Now uri length will be checked in sessionclient
and  httpclient as well.  please see bug for further info.

Closes-Bug: #1431449

Change-Id: Ief2352a90bb75a76e8c671d51beb0fb7a53a22f9
This commit is contained in:
Anand Shanmugam
2015-03-14 23:47:13 +05:30
parent 942d821d9c
commit 5f0f2802a8
4 changed files with 21 additions and 17 deletions

View File

@@ -40,6 +40,7 @@ else:
_requests_log_level = logging.WARNING
logging.getLogger("requests").setLevel(_requests_log_level)
MAX_URI_LEN = 8192
class HTTPClient(object):
@@ -146,9 +147,16 @@ class HTTPClient(object):
return resp, resp.text
def _check_uri_length(self, action):
uri_len = len(self.endpoint_url) + len(action)
if uri_len > MAX_URI_LEN:
raise exceptions.RequestURITooLong(
excess=uri_len - MAX_URI_LEN)
def do_request(self, url, method, **kwargs):
# Ensure client always has correct uri - do not guesstimate anything
self.authenticate_and_fetch_endpoint_url()
self._check_uri_length(url)
# Perform the request once. If we get a 401 back then it
# might be because the auth token expired, so try to
@@ -286,8 +294,15 @@ class SessionClient(adapter.Adapter):
resp = super(SessionClient, self).request(*args, **kwargs)
return resp, resp.text
def _check_uri_length(self, url):
uri_len = len(self.endpoint_url) + len(url)
if uri_len > MAX_URI_LEN:
raise exceptions.RequestURITooLong(
excess=uri_len - MAX_URI_LEN)
def do_request(self, url, method, **kwargs):
kwargs.setdefault('authenticated', True)
self._check_uri_length(url)
return self.request(url, method, **kwargs)
@property

View File

@@ -551,14 +551,14 @@ class CLITestV20NetworkJSON(test_cli20.CLITestV20Base):
filters, response = self._build_test_data(data)
# 1 char of extra URI len will cause a split in 2 requests
self.mox.StubOutWithMock(self.client,
self.mox.StubOutWithMock(self.client.httpclient,
"_check_uri_length")
self.client._check_uri_length(mox.IgnoreArg()).AndRaise(
self.client.httpclient._check_uri_length(mox.IgnoreArg()).AndRaise(
exceptions.RequestURITooLong(excess=1))
for data in sub_data_lists:
filters, response = self._build_test_data(data)
self.client._check_uri_length(
self.client.httpclient._check_uri_length(
mox.IgnoreArg()).AndReturn(None)
self.client.httpclient.request(
test_cli20.MyUrlComparator(

View File

@@ -265,14 +265,14 @@ class CLITestV20SecurityGroupsJSON(test_cli20.CLITestV20Base):
def test_extend_list_exceed_max_uri_len(self):
def mox_calls(path, data):
# 1 char of extra URI len will cause a split in 2 requests
self.mox.StubOutWithMock(self.client,
self.mox.StubOutWithMock(self.client.httpclient,
'_check_uri_length')
self.client._check_uri_length(mox.IgnoreArg()).AndRaise(
self.client.httpclient._check_uri_length(mox.IgnoreArg()).AndRaise(
exceptions.RequestURITooLong(excess=1))
responses = self._build_test_data(data, excess=1)
for item in responses:
self.client._check_uri_length(
self.client.httpclient._check_uri_length(
mox.IgnoreArg()).AndReturn(None)
self.client.httpclient.request(
test_cli20.end_url(path, item['filter']),

View File

@@ -184,12 +184,6 @@ class ClientBase(object):
# Raise the appropriate exception
exception_handler_v20(status_code, des_error_body)
def _check_uri_length(self, action):
uri_len = len(self.httpclient.endpoint_url) + len(action)
if uri_len > self.MAX_URI_LEN:
raise exceptions.RequestURITooLong(
excess=uri_len - self.MAX_URI_LEN)
def do_request(self, method, action, body=None, headers=None, params=None):
# Add format and tenant_id
action += ".%s" % self.format
@@ -198,8 +192,6 @@ class ClientBase(object):
params = utils.safe_encode_dict(params)
action += '?' + urlparse.urlencode(params, doseq=1)
self._check_uri_length(action)
if body:
body = self.serialize(body)
@@ -464,9 +456,6 @@ class Client(ClientBase):
'healthmonitors': 'healthmonitor',
}
# 8192 Is the default max URI len for eventlet.wsgi.server
MAX_URI_LEN = 8192
@APIParamsCall
def list_ext(self, path, **_params):
"""Client extension hook for lists.