~ubuntu-server-dev/python-neutronclient/kilo

« back to all changes in this revision

Viewing changes to debian/patches/long-request-uri-regression.patch

  • Committer: Corey Bryant
  • Date: 2015-08-28 16:10:07 UTC
  • Revision ID: corey.bryant@canonical.com-20150828161007-mstmlrmqi121plkr
d/p/long-request-uri-regression.patch: Cherry pick fix from
upstream VCS that fixes an upstream regression in the
long-request-uri.patch. (LP: #1489677).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 binding
 
6
 
 
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
 
12
traces.
 
13
 
 
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.
 
17
 
 
18
Closes-Bug: #1431449
 
19
 
 
20
Change-Id: Ief2352a90bb75a76e8c671d51beb0fb7a53a22f9
 
21
---
 
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(-)
 
27
 
 
28
--- a/neutronclient/client.py
 
29
+++ b/neutronclient/client.py
 
30
@@ -40,6 +40,7 @@
 
31
     _requests_log_level = logging.WARNING
 
32
 
 
33
 logging.getLogger("requests").setLevel(_requests_log_level)
 
34
+MAX_URI_LEN = 8192
 
35
 
 
36
 
 
37
 class HTTPClient(object):
 
38
@@ -146,9 +147,16 @@
 
39
 
 
40
         return resp, resp.text
 
41
 
 
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)
 
47
+
 
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)
 
52
 
 
53
         # Perform the request once. If we get a 401 back then it
 
54
         # might be because the auth token expired, so try to
 
55
@@ -286,8 +294,15 @@
 
56
         resp = super(SessionClient, self).request(*args, **kwargs)
 
57
         return resp, resp.text
 
58
 
 
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)
 
64
+
 
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)
 
69
 
 
70
     @property
 
71
--- a/neutronclient/tests/unit/test_cli20_network.py
 
72
+++ b/neutronclient/tests/unit/test_cli20_network.py
 
73
@@ -551,14 +551,14 @@
 
74
             filters, response = self._build_test_data(data)
 
75
 
 
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,
 
79
                                      "_check_uri_length")
 
80
-            self.client._check_uri_length(mox.IgnoreArg()).AndRaise(
 
81
+            self.client.httpclient._check_uri_length(mox.IgnoreArg()).AndRaise(
 
82
                 exceptions.RequestURITooLong(excess=1))
 
83
 
 
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
 
93
@@ -265,14 +265,14 @@
 
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,
 
99
                                      '_check_uri_length')
 
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)
 
104
 
 
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
 
113
@@ -181,12 +181,6 @@
 
114
         # Raise the appropriate exception
 
115
         exception_handler_v20(status_code, des_error_body)
 
116
 
 
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)
 
122
-
 
123
     def do_request(self, method, action, body=None, headers=None, params=None):
 
124
         # Add format and tenant_id
 
125
         action += ".%s" % self.format
 
126
@@ -195,8 +189,6 @@
 
127
             params = utils.safe_encode_dict(params)
 
128
             action += '?' + urlparse.urlencode(params, doseq=1)
 
129
 
 
130
-        self._check_uri_length(action)
 
131
-
 
132
         if body:
 
133
             body = self.serialize(body)
 
134
 
 
135
@@ -461,9 +453,6 @@
 
136
                      'healthmonitors': 'healthmonitor',
 
137
                      }
 
138
 
 
139
-    # 8192 Is the default max URI len for eventlet.wsgi.server
 
140
-    MAX_URI_LEN = 8192
 
141
-
 
142
     @APIParamsCall
 
143
     def get_quotas_tenant(self, **_params):
 
144
         """Fetch tenant info in server's context for following quota operation.