]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Ignore http_proxy while connecting to test WSGI server
authorAngus Lees <gus@inodes.org>
Thu, 31 Jul 2014 05:27:18 +0000 (15:27 +1000)
committerAngus Lees <gus@inodes.org>
Thu, 14 Aug 2014 01:39:24 +0000 (11:39 +1000)
urllib2.urlopen uses $http_proxy/$HTTP_PROXY environment variables by
default.  If set (and pointing to a remote host), then the WSGI tests
that spin up a local server and connect to it using
http://127.0.0.1:$port/ instead connect to $port *on the proxy*,
and (hopefully) fail.

This change uses urllib2 in a way that ignores proxy settings.

Change-Id: I4d94fcc06925d0c947345a07ae20352e1898e46d
Closes-Bug: #1356665

neutron/tests/unit/test_wsgi.py

index a6b3f3be7442d1cdbb266934b1e1375bd6073ab1..d1229139886612bca00ab27259fcfa56d08a541e 100644 (file)
@@ -35,6 +35,11 @@ TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                '..', 'var'))
 
 
+def open_no_proxy(*args, **kwargs):
+    opener = urllib2.build_opener(urllib2.ProxyHandler({}))
+    return opener.open(*args, **kwargs)
+
+
 class TestWSGIServer(base.BaseTestCase):
     """WSGI server tests."""
 
@@ -120,7 +125,8 @@ class TestWSGIServer(base.BaseTestCase):
         server = wsgi.Server("test_app")
         server.start(hello_world, 0, host="127.0.0.1")
 
-        response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port)
+        response = open_no_proxy('http://127.0.0.1:%d/' % server.port)
+
         self.assertEqual(greetings, response.read())
 
         server.stop()
@@ -1088,7 +1094,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
         server = wsgi.Server("test_app")
         server.start(hello_world, 0, host="127.0.0.1")
 
-        response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port)
+        response = open_no_proxy('https://127.0.0.1:%d/' % server.port)
+
         self.assertEqual(greetings, response.read())
 
         server.stop()
@@ -1107,7 +1114,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
         server = wsgi.Server("test_app")
         server.start(hello_world, 0, host="127.0.0.1")
 
-        response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port)
+        response = open_no_proxy('https://127.0.0.1:%d/' % server.port)
+
         self.assertEqual(greetings, response.read())
 
         server.stop()
@@ -1128,7 +1136,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
         server = wsgi.Server("test_app")
         server.start(hello_world, 0, host="::1")
 
-        response = urllib2.urlopen('https://[::1]:%d/' % server.port)
+        response = open_no_proxy('https://[::1]:%d/' % server.port)
+
         self.assertEqual(greetings, response.read())
 
         server.stop()