From 0fde41a90c45972948299c4c852d9c2db527d032 Mon Sep 17 00:00:00 2001 From: Angus Lees Date: Thu, 31 Jul 2014 15:27:18 +1000 Subject: [PATCH] Ignore http_proxy while connecting to test WSGI server 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/test_wsgi.py index a6b3f3be74..d122913988 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/test_wsgi.py @@ -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()