1
From 5f0f2802a83646dc4cad29078e2c8e82c69dc041 Mon Sep 17 00:00:00 2001
2
From: Anand Shanmugam <anand1712@gmail.com>
3
Date: Sat, 14 Mar 2015 23:47:13 +0530
4
Subject: [PATCH] Fix failures when calling list operations using Python
7
This bug is caused because of the regression caused by
8
I1b719bed406b83c5f2deac06e127798a91f51ad7 . The original bug was
9
raised because check_max_uri was not working after the introduction
10
of sessionclient. The change created a regression in which the
11
python bindings of the neutron client was not usable and causing
14
The fix is to revert the change id and add a new check_max_uri to
15
the sessionclient. Now uri length will be checked in sessionclient
16
and httpclient as well. please see bug for further info.
20
Change-Id: Ief2352a90bb75a76e8c671d51beb0fb7a53a22f9
22
neutronclient/client.py | 15 +++++++++++++++
23
neutronclient/tests/unit/test_cli20_network.py | 6 +++---
24
neutronclient/tests/unit/test_cli20_securitygroup.py | 6 +++---
25
neutronclient/v2_0/client.py | 11 -----------
26
4 files changed, 21 insertions(+), 17 deletions(-)
28
--- a/neutronclient/client.py
29
+++ b/neutronclient/client.py
31
_requests_log_level = logging.WARNING
33
logging.getLogger("requests").setLevel(_requests_log_level)
37
class HTTPClient(object):
40
return resp, resp.text
42
+ def _check_uri_length(self, action):
43
+ uri_len = len(self.endpoint_url) + len(action)
44
+ if uri_len > MAX_URI_LEN:
45
+ raise exceptions.RequestURITooLong(
46
+ excess=uri_len - MAX_URI_LEN)
48
def do_request(self, url, method, **kwargs):
49
# Ensure client always has correct uri - do not guesstimate anything
50
self.authenticate_and_fetch_endpoint_url()
51
+ self._check_uri_length(url)
53
# Perform the request once. If we get a 401 back then it
54
# might be because the auth token expired, so try to
56
resp = super(SessionClient, self).request(*args, **kwargs)
57
return resp, resp.text
59
+ def _check_uri_length(self, url):
60
+ uri_len = len(self.endpoint_url) + len(url)
61
+ if uri_len > MAX_URI_LEN:
62
+ raise exceptions.RequestURITooLong(
63
+ excess=uri_len - MAX_URI_LEN)
65
def do_request(self, url, method, **kwargs):
66
kwargs.setdefault('authenticated', True)
67
+ self._check_uri_length(url)
68
return self.request(url, method, **kwargs)
71
--- a/neutronclient/tests/unit/test_cli20_network.py
72
+++ b/neutronclient/tests/unit/test_cli20_network.py
74
filters, response = self._build_test_data(data)
76
# 1 char of extra URI len will cause a split in 2 requests
77
- self.mox.StubOutWithMock(self.client,
78
+ self.mox.StubOutWithMock(self.client.httpclient,
80
- self.client._check_uri_length(mox.IgnoreArg()).AndRaise(
81
+ self.client.httpclient._check_uri_length(mox.IgnoreArg()).AndRaise(
82
exceptions.RequestURITooLong(excess=1))
84
for data in sub_data_lists:
85
filters, response = self._build_test_data(data)
86
- self.client._check_uri_length(
87
+ self.client.httpclient._check_uri_length(
88
mox.IgnoreArg()).AndReturn(None)
89
self.client.httpclient.request(
90
test_cli20.MyUrlComparator(
91
--- a/neutronclient/tests/unit/test_cli20_securitygroup.py
92
+++ b/neutronclient/tests/unit/test_cli20_securitygroup.py
94
def test_extend_list_exceed_max_uri_len(self):
95
def mox_calls(path, data):
96
# 1 char of extra URI len will cause a split in 2 requests
97
- self.mox.StubOutWithMock(self.client,
98
+ self.mox.StubOutWithMock(self.client.httpclient,
100
- self.client._check_uri_length(mox.IgnoreArg()).AndRaise(
101
+ self.client.httpclient._check_uri_length(mox.IgnoreArg()).AndRaise(
102
exceptions.RequestURITooLong(excess=1))
103
responses = self._build_test_data(data, excess=1)
105
for item in responses:
106
- self.client._check_uri_length(
107
+ self.client.httpclient._check_uri_length(
108
mox.IgnoreArg()).AndReturn(None)
109
self.client.httpclient.request(
110
test_cli20.end_url(path, item['filter']),
111
--- a/neutronclient/v2_0/client.py
112
+++ b/neutronclient/v2_0/client.py
114
# Raise the appropriate exception
115
exception_handler_v20(status_code, des_error_body)
117
- def _check_uri_length(self, action):
118
- uri_len = len(self.httpclient.endpoint_url) + len(action)
119
- if uri_len > self.MAX_URI_LEN:
120
- raise exceptions.RequestURITooLong(
121
- excess=uri_len - self.MAX_URI_LEN)
123
def do_request(self, method, action, body=None, headers=None, params=None):
124
# Add format and tenant_id
125
action += ".%s" % self.format
127
params = utils.safe_encode_dict(params)
128
action += '?' + urlparse.urlencode(params, doseq=1)
130
- self._check_uri_length(action)
133
body = self.serialize(body)
136
'healthmonitors': 'healthmonitor',
139
- # 8192 Is the default max URI len for eventlet.wsgi.server
143
def get_quotas_tenant(self, **_params):
144
"""Fetch tenant info in server's context for following quota operation.