]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Ignore HTTP_PROXY during test requests
authorAngus Lees <gus@inodes.org>
Wed, 13 Aug 2014 02:13:48 +0000 (12:13 +1000)
committerAngus Lees <gus@inodes.org>
Wed, 13 Aug 2014 02:13:48 +0000 (12:13 +1000)
urllib2 follows http_proxy/HTTP_PROXY by default.  If a (non-local)
proxy is set and a test tries to connect to localhost:$port, it will
instead attempt to connect to $port on the proxy and (presumably) fail.

This change forces the two tests that failed in the presence of
HTTP_PROXY to connect directly.

Change-Id: Ia12c91b356f0ccebf874933ff459aa2faa190655

cinder/tests/integrated/integrated_helpers.py
cinder/tests/test_wsgi.py

index 1677060620edf8ad09c39f3e861176ac80fa1c59..873b428bc569f286576887cddd0de0651e433615 100644 (file)
@@ -21,6 +21,8 @@ import random
 import string
 import uuid
 
+import fixtures
+
 from cinder.openstack.common import log as logging
 from cinder import service
 from cinder import test  # For the flags
@@ -62,6 +64,9 @@ class _IntegratedTestBase(test.TestCase):
         self.flags(**f)
         self.flags(verbose=True)
 
+        for var in ('http_proxy', 'HTTP_PROXY'):
+            self.useFixture(fixtures.EnvironmentVariable(var))
+
         # set up services
         self.volume = self.start_service('volume')
         self.scheduler = self.start_service('scheduler')
index 214e5c5566c0d6a1ea69c6a6bc05ccbb3e1abea8..63256926c485ed3d1cead1115c70c072a8024175 100644 (file)
@@ -39,6 +39,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 TestLoaderNothingExists(test.TestCase):
     """Loader tests where os.path.exists always returns False."""
 
@@ -134,7 +139,7 @@ class TestWSGIServer(test.TestCase):
                                     host="127.0.0.1", port=0)
         server.start()
 
-        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()
@@ -156,7 +161,7 @@ class TestWSGIServer(test.TestCase):
 
         server.start()
 
-        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()
@@ -181,7 +186,7 @@ class TestWSGIServer(test.TestCase):
                                     port=0)
         server.start()
 
-        response = urllib2.urlopen('https://[::1]:%d/' % server.port)
+        response = open_no_proxy('https://[::1]:%d/' % server.port)
         self.assertEqual(greetings, response.read())
 
         server.stop()