From: Angus Lees Date: Wed, 13 Aug 2014 02:13:48 +0000 (+1000) Subject: Ignore HTTP_PROXY during test requests X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b0ebfb90958afac39be24b5157763d479256ab8c;p=openstack-build%2Fcinder-build.git Ignore HTTP_PROXY during test requests 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 --- diff --git a/cinder/tests/integrated/integrated_helpers.py b/cinder/tests/integrated/integrated_helpers.py index 167706062..873b428bc 100644 --- a/cinder/tests/integrated/integrated_helpers.py +++ b/cinder/tests/integrated/integrated_helpers.py @@ -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') diff --git a/cinder/tests/test_wsgi.py b/cinder/tests/test_wsgi.py index 214e5c556..63256926c 100644 --- a/cinder/tests/test_wsgi.py +++ b/cinder/tests/test_wsgi.py @@ -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()