Try to detect HTTP proxy and warn about it.
swift-bench test results could be altered when using HTTP proxy server. This patch add warning when HTTP proxy has been detected. Change-Id: Id818203345914efee37852e96541c259de6ae555
This commit is contained in:
@@ -30,7 +30,7 @@ from eventlet.green.httplib import CannotSendRequest
|
|||||||
|
|
||||||
import swiftclient as client
|
import swiftclient as client
|
||||||
|
|
||||||
from swiftbench.utils import config_true_value
|
from swiftbench.utils import config_true_value, using_http_proxy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
@@ -199,6 +199,9 @@ class Bench(object):
|
|||||||
self.auth_version = conf.auth_version
|
self.auth_version = conf.auth_version
|
||||||
self.logger.info("Auth version: %s" % self.auth_version)
|
self.logger.info("Auth version: %s" % self.auth_version)
|
||||||
if self.use_proxy:
|
if self.use_proxy:
|
||||||
|
if using_http_proxy(self.auth_url):
|
||||||
|
logger.warn("Auth is going through HTTP proxy server. This "
|
||||||
|
"could affect test result")
|
||||||
url, token = client.get_auth(self.auth_url, self.user, self.key,
|
url, token = client.get_auth(self.auth_url, self.user, self.key,
|
||||||
auth_version=self.auth_version)
|
auth_version=self.auth_version)
|
||||||
self.token = token
|
self.token = token
|
||||||
@@ -213,6 +216,10 @@ class Bench(object):
|
|||||||
self.url = conf.url
|
self.url = conf.url
|
||||||
self.ip, self.port = self.url.split('/')[2].split(':')
|
self.ip, self.port = self.url.split('/')[2].split(':')
|
||||||
|
|
||||||
|
if using_http_proxy(self.url):
|
||||||
|
logger.warn("Communication with Swift server is going through "
|
||||||
|
"HTTP proxy server. This could affect test result")
|
||||||
|
|
||||||
self.object_size = int(conf.object_size)
|
self.object_size = int(conf.object_size)
|
||||||
self.object_sources = conf.object_sources
|
self.object_sources = conf.object_sources
|
||||||
self.lower_object_size = int(conf.lower_object_size)
|
self.lower_object_size = int(conf.lower_object_size)
|
||||||
|
@@ -15,6 +15,11 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from ConfigParser import ConfigParser, RawConfigParser
|
from ConfigParser import ConfigParser, RawConfigParser
|
||||||
|
try:
|
||||||
|
from urllib import getproxies, proxy_bypass
|
||||||
|
except ImportError:
|
||||||
|
from urllib.request import getproxies, proxy_bypass
|
||||||
|
from urlparse import urlparse
|
||||||
|
|
||||||
# Used when reading config values
|
# Used when reading config values
|
||||||
TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
|
TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
|
||||||
@@ -77,3 +82,12 @@ def config_true_value(value):
|
|||||||
"""
|
"""
|
||||||
return value is True or \
|
return value is True or \
|
||||||
(isinstance(value, basestring) and value.lower() in TRUE_VALUES)
|
(isinstance(value, basestring) and value.lower() in TRUE_VALUES)
|
||||||
|
|
||||||
|
|
||||||
|
def using_http_proxy(url):
|
||||||
|
"""
|
||||||
|
Return True if the url will use HTTP proxy.
|
||||||
|
Returns False otherwise.
|
||||||
|
"""
|
||||||
|
up = urlparse(url)
|
||||||
|
return up.scheme.lower() in getproxies() and not proxy_bypass(up.netloc)
|
||||||
|
@@ -104,6 +104,21 @@ log_name = %(yarr)s'''
|
|||||||
os.unlink(temppath)
|
os.unlink(temppath)
|
||||||
self.assertRaises(SystemExit, utils.readconf, temppath)
|
self.assertRaises(SystemExit, utils.readconf, temppath)
|
||||||
|
|
||||||
|
@mock.patch("swiftbench.utils.getproxies")
|
||||||
|
@mock.patch("swiftbench.utils.proxy_bypass")
|
||||||
|
def test_using_http_proxy(self, mock_proxy_bypass, mock_getproxies):
|
||||||
|
mock_getproxies.return_value = {'http': 'proxy', 'https': 'proxy'}
|
||||||
|
|
||||||
|
def fake_proxy_bypass(url):
|
||||||
|
return url == "localhost"
|
||||||
|
mock_proxy_bypass.side_effect = fake_proxy_bypass
|
||||||
|
|
||||||
|
self.assertTrue(utils.using_http_proxy("http://host1/"))
|
||||||
|
self.assertFalse(utils.using_http_proxy("http://localhost/"))
|
||||||
|
self.assertTrue(utils.using_http_proxy("https://host1/"))
|
||||||
|
self.assertFalse(utils.using_http_proxy("https://localhost/"))
|
||||||
|
self.assertFalse(utils.using_http_proxy("dummy://localhost/"))
|
||||||
|
self.assertFalse(utils.using_http_proxy("dummy://host1/"))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user