summaryrefslogtreecommitdiff
path: root/swiftbench
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2019-08-29 11:38:59 -0700
committerTim Burke <tim.burke@gmail.com>2019-08-29 13:16:33 -0700
commitf221632a82283f3e2d3c564e5baa2a083b4662ae (patch)
tree8fee026263a8bd7903f3a433ab330be736d3d9a0 /swiftbench
parent6e047b640db4eadd019762b199e4feaddcd3d4a0 (diff)
downloadswift-bench-f221632a82283f3e2d3c564e5baa2a083b4662ae.tar.gz
Port to py3
Change-Id: Ib86178259f854c15dd305dd39779a203cafb0451
Diffstat (limited to 'swiftbench')
-rw-r--r--swiftbench/bench.py13
-rw-r--r--swiftbench/utils.py18
2 files changed, 17 insertions, 14 deletions
diff --git a/swiftbench/bench.py b/swiftbench/bench.py
index 696b6ad..b7f35a1 100644
--- a/swiftbench/bench.py
+++ b/swiftbench/bench.py
@@ -29,6 +29,8 @@ import eventlet
import eventlet.pools
from eventlet.green.httplib import CannotSendRequest
+from six.moves import range
+
import swiftclient as client
from swiftbench.utils import config_true_value, using_http_proxy
@@ -107,12 +109,12 @@ class SourceFile(object):
raise StopIteration
chunk_size = min(self.size - self.pos, self.chunk_size)
self.pos += chunk_size
- return '0' * chunk_size
+ return b'0' * chunk_size
def read(self, desired_size):
chunk_size = min(self.size - self.pos, desired_size)
self.pos += chunk_size
- return '0' * chunk_size
+ return b'0' * chunk_size
class ConnectionPool(eventlet.pools.Pool):
@@ -224,7 +226,10 @@ class Bench(object):
self.files = []
if self.object_sources:
self.object_sources = self.object_sources.split()
- self.files = [file(f, 'rb').read() for f in self.object_sources]
+ self.files = []
+ for f in self.object_sources:
+ with open(f, 'rb') as fp:
+ self.files.append(fp.read())
self.put_concurrency = int(conf.put_concurrency)
self.get_concurrency = int(conf.get_concurrency)
@@ -270,7 +275,7 @@ class Bench(object):
self.heartbeat -= 13 # just to get the first report quicker
self.failures = 0
self.complete = 0
- for i in xrange(self.total):
+ for i in range(self.total):
if self.aborted:
break
pool.spawn_n(self._run, i)
diff --git a/swiftbench/utils.py b/swiftbench/utils.py
index 1916ac9..df39bab 100644
--- a/swiftbench/utils.py
+++ b/swiftbench/utils.py
@@ -13,13 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import six
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
+from six.moves.configparser import ConfigParser, RawConfigParser
+from six.moves.urllib.parse import urlparse
+from six.moves.urllib.request import getproxies, proxy_bypass
# Used when reading config values
TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
@@ -51,14 +49,14 @@ def readconf(conf_path, section_name=None, log_name=None, defaults=None,
else:
success = c.read(conf_path)
if not success:
- print "Unable to read config from %s" % conf_path
+ print("Unable to read config from %s" % conf_path)
sys.exit(1)
if section_name:
if c.has_section(section_name):
conf = dict(c.items(section_name))
else:
- print "Unable to find %s config section in %s" % \
- (section_name, conf_path)
+ print("Unable to find %s config section in %s" %
+ (section_name, conf_path))
sys.exit(1)
if "log_name" not in conf:
if log_name is not None:
@@ -81,7 +79,7 @@ def config_true_value(value):
Returns False otherwise.
"""
return value is True or \
- (isinstance(value, basestring) and value.lower() in TRUE_VALUES)
+ (isinstance(value, six.string_types) and value.lower() in TRUE_VALUES)
def using_http_proxy(url):