summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-05-20 11:41:43 -0400
committerBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-08-22 10:36:32 -0400
commit9b9d0567ef2d40c8f20f75a8240abb6fa07ae36c (patch)
tree353bd670a98c85f2ea1060911249960388c3454b
parent9657073262fd5ff264328312660ccbcfafba17cd (diff)
Use WebOb 1.8.1
The requirements/upper-constraints file was modified to allow WebOb 1.8.1 by commit 88bafa11deb9bd7595983d97ffabca338f073ba3. This patch simplifies some Glance code that could handle both WebOb 1.7.4 and 1.8.1 so that it now only handles the latter, and updates the glance/requirements.txt and glance/lower-constraints.txt to reflect that we support WebOb 1.8.1+ only. Change-Id: I03e03013927cc5434aa0d97657d5e7efd8223ee5 Closes-bug: #1770410
Notes
Notes (review): Code-Review+1: Piotr Bielak <piotr.bielak@corp.ovh.com> Code-Review+2: Abhishek Kekane <akekane@redhat.com> Code-Review+2: Sean McGinnis <sean.mcginnis@gmail.com> Workflow+1: Sean McGinnis <sean.mcginnis@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 09 Oct 2018 08:51:42 +0000 Reviewed-on: https://review.openstack.org/569644 Project: openstack/glance Branch: refs/heads/master
-rw-r--r--glance/common/wsgi.py25
-rw-r--r--glance/tests/unit/common/test_wsgi.py62
-rw-r--r--lower-constraints.txt2
-rw-r--r--releasenotes/notes/use-webob-1.8.1-5c3cd1b1382f063e.yaml12
-rw-r--r--requirements.txt2
5 files changed, 36 insertions, 67 deletions
diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py
index bc0bb08..95d772a 100644
--- a/glance/common/wsgi.py
+++ b/glance/common/wsgi.py
@@ -53,12 +53,6 @@ from glance import i18n
53from glance.i18n import _, _LE, _LI, _LW 53from glance.i18n import _, _LE, _LI, _LW
54 54
55 55
56try:
57 from webob.acceptparse import AcceptLanguageValidHeader # noqa
58 USING_WEBOB_1_8 = True
59except ImportError:
60 USING_WEBOB_1_8 = False
61
62bind_opts = [ 56bind_opts = [
63 cfg.HostAddressOpt('bind_host', 57 cfg.HostAddressOpt('bind_host',
64 default='0.0.0.0', 58 default='0.0.0.0',
@@ -1048,18 +1042,7 @@ class Request(webob.Request):
1048 else: 1042 else:
1049 return content_type 1043 return content_type
1050 1044
1051 def _best_match_language_1_7(self): 1045 def best_match_language(self):
1052 """Determines best available locale from the Accept-Language header.
1053
1054 :returns: the best language match or None if the 'Accept-Language'
1055 header was not available in the request.
1056 """
1057 if not self.accept_language:
1058 return None
1059 langs = i18n.get_available_languages('glance')
1060 return self.accept_language.best_match(langs)
1061
1062 def _best_match_language_1_8(self):
1063 """Determines best available locale from the Accept-Language header. 1046 """Determines best available locale from the Accept-Language header.
1064 1047
1065 :returns: the best language match or None if the 'Accept-Language' 1048 :returns: the best language match or None if the 'Accept-Language'
@@ -1076,12 +1059,6 @@ class Request(webob.Request):
1076 best_match = None 1059 best_match = None
1077 return best_match 1060 return best_match
1078 1061
1079 def best_match_language(self):
1080 if USING_WEBOB_1_8:
1081 return self._best_match_language_1_8()
1082 else:
1083 return self._best_match_language_1_7()
1084
1085 def get_range_from_request(self, image_size): 1062 def get_range_from_request(self, image_size):
1086 """Return the `Range` in a request.""" 1063 """Return the `Range` in a request."""
1087 1064
diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py
index adda23e..794873d 100644
--- a/glance/tests/unit/common/test_wsgi.py
+++ b/glance/tests/unit/common/test_wsgi.py
@@ -184,31 +184,20 @@ class RequestTest(test_utils.BaseTestCase):
184 req = wsgi.Request.blank('/', headers={'Accept-Language': 'unknown'}) 184 req = wsgi.Request.blank('/', headers={'Accept-Language': 'unknown'})
185 self.assertIsNone(req.best_match_language()) 185 self.assertIsNone(req.best_match_language())
186 186
187 def test_best_match_language_unknown(self): 187 @mock.patch.object(webob.acceptparse.AcceptLanguageValidHeader, 'lookup')
188 # Test that we are actually invoking language negotiation by webop 188 def test_best_match_language_unknown(self, mock_lookup):
189 # Test that we are actually invoking language negotiation by WebOb
189 request = wsgi.Request.blank('/') 190 request = wsgi.Request.blank('/')
190 accepted = 'unknown-lang' 191 accepted = 'unknown-lang'
191 request.headers = {'Accept-Language': accepted} 192 request.headers = {'Accept-Language': accepted}
192 193
193 # TODO(rosmaita): simplify when lower_constraints has webob >= 1.8.1 194 # Bug #1765748: see comment in code in the function under test
194 try: 195 # to understand why this is the correct return value for the
195 from webob.acceptparse import AcceptLanguageValidHeader # noqa 196 # webob 1.8.x mock
196 cls = webob.acceptparse.AcceptLanguageValidHeader 197 mock_lookup.return_value = 'fake_LANG'
197 funcname = 'lookup' 198
198 # Bug #1765748: see comment in code in the function under test 199 self.assertIsNone(request.best_match_language())
199 # to understand why this is the correct return value for the 200 mock_lookup.assert_called_once()
200 # webob 1.8.x mock
201 retval = 'fake_LANG'
202 except ImportError:
203 cls = webob.acceptparse.AcceptLanguage
204 funcname = 'best_match'
205 retval = None
206
207 with mock.patch.object(cls, funcname) as mocked_function:
208 mocked_function.return_value = retval
209
210 self.assertIsNone(request.best_match_language())
211 mocked_function.assert_called_once()
212 201
213 # If Accept-Language is missing or empty, match should be None 202 # If Accept-Language is missing or empty, match should be None
214 request.headers = {'Accept-Language': ''} 203 request.headers = {'Accept-Language': ''}
@@ -389,27 +378,18 @@ class ResourceTest(test_utils.BaseTestCase):
389 resource, request) 378 resource, request)
390 self.assertEqual(message_es, str(e)) 379 self.assertEqual(message_es, str(e))
391 380
381 @mock.patch.object(webob.acceptparse.AcceptLanguageValidHeader, 'lookup')
392 @mock.patch.object(i18n, 'translate') 382 @mock.patch.object(i18n, 'translate')
393 def test_translate_exception(self, mock_translate): 383 def test_translate_exception(self, mock_translate, mock_lookup):
394 # TODO(rosmaita): simplify when lower_constraints has webob >= 1.8.1 384 mock_translate.return_value = 'No Encontrado'
395 try: 385 mock_lookup.return_value = 'de'
396 from webob.acceptparse import AcceptLanguageValidHeader # noqa 386
397 cls = webob.acceptparse.AcceptLanguageValidHeader 387 req = wsgi.Request.blank('/tests/123')
398 funcname = 'lookup' 388 req.headers["Accept-Language"] = "de"
399 except ImportError: 389
400 cls = webob.acceptparse.AcceptLanguage 390 e = webob.exc.HTTPNotFound(explanation='Not Found')
401 funcname = 'best_match' 391 e = wsgi.translate_exception(req, e)
402 392 self.assertEqual('No Encontrado', e.explanation)
403 with mock.patch.object(cls, funcname) as mocked_function:
404 mock_translate.return_value = 'No Encontrado'
405 mocked_function.return_value = 'de'
406
407 req = wsgi.Request.blank('/tests/123')
408 req.headers["Accept-Language"] = "de"
409
410 e = webob.exc.HTTPNotFound(explanation='Not Found')
411 e = wsgi.translate_exception(req, e)
412 self.assertEqual('No Encontrado', e.explanation)
413 393
414 def test_response_headers_encoded(self): 394 def test_response_headers_encoded(self):
415 # prepare environment 395 # prepare environment
diff --git a/lower-constraints.txt b/lower-constraints.txt
index beac1f1..4e158cd 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -138,7 +138,7 @@ unittest2==1.1.0
138urllib3==1.22 138urllib3==1.22
139vine==1.1.4 139vine==1.1.4
140voluptuous==0.11.1 140voluptuous==0.11.1
141WebOb==1.7.1 141WebOb==1.8.1
142whereto===0.3.0 142whereto===0.3.0
143wrapt==1.10.11 143wrapt==1.10.11
144WSME==0.8.0 144WSME==0.8.0
diff --git a/releasenotes/notes/use-webob-1.8.1-5c3cd1b1382f063e.yaml b/releasenotes/notes/use-webob-1.8.1-5c3cd1b1382f063e.yaml
new file mode 100644
index 0000000..21d8d3e
--- /dev/null
+++ b/releasenotes/notes/use-webob-1.8.1-5c3cd1b1382f063e.yaml
@@ -0,0 +1,12 @@
1---
2other:
3 - |
4 Negotiation of the 'Accept-Language' header now follows the "Lookup"
5 matching scheme described in `RFC 4647, section 3.4
6 <https://tools.ietf.org/html/rfc4647.html#section-3.4>`_. The
7 "Lookup" scheme is one of the algorithms suggested in `RFC 7231,
8 section 5.3.5
9 <https://tools.ietf.org/html/rfc7231.html#section-5.3.5>`_. (This is
10 due to a change in an underlying library, which previously used a
11 matching scheme that did not conform to `RFC 7231
12 <https://tools.ietf.org/html/rfc7231.html>`_.)
diff --git a/requirements.txt b/requirements.txt
index 1b50271..349d731 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,7 +10,7 @@ SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT
10eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT 10eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
11PasteDeploy>=1.5.0 # MIT 11PasteDeploy>=1.5.0 # MIT
12Routes>=2.3.1 # MIT 12Routes>=2.3.1 # MIT
13WebOb>=1.7.1 # MIT 13WebOb>=1.8.1 # MIT
14sqlalchemy-migrate>=0.11.0 # Apache-2.0 14sqlalchemy-migrate>=0.11.0 # Apache-2.0
15sqlparse>=0.2.2 # BSD 15sqlparse>=0.2.2 # BSD
16alembic>=0.8.10 # MIT 16alembic>=0.8.10 # MIT