summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Novy <ondrej.novy@firma.seznam.cz>2015-08-08 16:09:22 +0200
committerOndřej Nový <ondrej.novy@firma.seznam.cz>2015-10-05 21:57:06 +0200
commitc0f473d9757afa680e6b6883cbd16d45ec3551fa (patch)
tree5181c7c090c3a61ec3f7492ddc76d705c8ef50ef
parentd64b007deb99e3ac65034623993961f23351b78d (diff)
downloadswift-bench-c0f473d9757afa680e6b6883cbd16d45ec3551fa.tar.gz
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
-rw-r--r--swiftbench/bench.py9
-rw-r--r--swiftbench/utils.py14
-rw-r--r--tests/test_utils.py15
3 files changed, 37 insertions, 1 deletions
diff --git a/swiftbench/bench.py b/swiftbench/bench.py
index 65f3f87..fc972f7 100644
--- a/swiftbench/bench.py
+++ b/swiftbench/bench.py
@@ -30,7 +30,7 @@ from eventlet.green.httplib import CannotSendRequest
import swiftclient as client
-from swiftbench.utils import config_true_value
+from swiftbench.utils import config_true_value, using_http_proxy
try:
import simplejson as json
@@ -199,6 +199,9 @@ class Bench(object):
self.auth_version = conf.auth_version
self.logger.info("Auth version: %s" % self.auth_version)
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,
auth_version=self.auth_version)
self.token = token
@@ -213,6 +216,10 @@ class Bench(object):
self.url = conf.url
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_sources = conf.object_sources
self.lower_object_size = int(conf.lower_object_size)
diff --git a/swiftbench/utils.py b/swiftbench/utils.py
index 14611d9..1916ac9 100644
--- a/swiftbench/utils.py
+++ b/swiftbench/utils.py
@@ -15,6 +15,11 @@
import sys
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
TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
@@ -77,3 +82,12 @@ def config_true_value(value):
"""
return value is True or \
(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)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 295d795..c31d5af 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -104,6 +104,21 @@ log_name = %(yarr)s'''
os.unlink(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__':
unittest.main()