diff options
author | Tim Burke <tim.burke@gmail.com> | 2019-08-29 11:38:59 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2019-08-29 13:16:33 -0700 |
commit | f221632a82283f3e2d3c564e5baa2a083b4662ae (patch) | |
tree | 8fee026263a8bd7903f3a433ab330be736d3d9a0 | |
parent | 6e047b640db4eadd019762b199e4feaddcd3d4a0 (diff) | |
download | swift-bench-f221632a82283f3e2d3c564e5baa2a083b4662ae.tar.gz |
Port to py3
Change-Id: Ib86178259f854c15dd305dd39779a203cafb0451
-rw-r--r-- | .zuul.yaml | 2 | ||||
-rwxr-xr-x | bin/swift-bench | 4 | ||||
-rw-r--r-- | requirements.txt | 3 | ||||
-rw-r--r-- | setup.py | 4 | ||||
-rw-r--r-- | swiftbench/bench.py | 13 | ||||
-rw-r--r-- | swiftbench/utils.py | 18 | ||||
-rw-r--r-- | test-requirements.txt | 1 | ||||
-rw-r--r-- | tests/test_utils.py | 10 | ||||
-rw-r--r-- | tox.ini | 2 |
9 files changed, 34 insertions, 23 deletions
@@ -1,3 +1,5 @@ - project: templates: + - check-requirements - openstack-python-jobs + - openstack-python3-train-jobs diff --git a/bin/swift-bench b/bin/swift-bench index b516c24..c1b8997 100755 --- a/bin/swift-bench +++ b/bin/swift-bench @@ -21,6 +21,8 @@ import signal import uuid from optparse import OptionParser +from six.moves import range + from swiftbench.bench import (BenchController, DistributedBenchController, create_containers, delete_containers) from swiftbench.utils import readconf, config_true_value @@ -154,7 +156,7 @@ if __name__ == '__main__': options.get_concurrency = options.concurrency options.del_concurrency = options.concurrency options.containers = ['%s_%d' % (options.container_name, i) - for i in xrange(int(options.num_containers))] + for i in range(int(options.num_containers))] # Turn "yes"/"no"/etc. strings to booleans options.use_proxy = config_true_value(options.use_proxy) diff --git a/requirements.txt b/requirements.txt index 7b19353..695bb46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -python-swiftclient +python-swiftclient>=3.2.0 eventlet>=0.17.4 # MIT +six>=1.9.0 @@ -40,7 +40,11 @@ setup( 'License :: OSI Approved :: Apache Software License', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Environment :: No Input/Output (Daemon)', 'Environment :: OpenStack', ], 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): diff --git a/test-requirements.txt b/test-requirements.txt index a92184d..3add9f4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,6 +2,5 @@ hacking>=0.10.0,<0.11 coverage>=3.6 mock>=1.0 -sphinx>=1.1.2,<1.2 testrepository>=0.0.17 testtools>=0.9.32 diff --git a/tests/test_utils.py b/tests/test_utils.py index 3579458..9be68b5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -18,7 +18,7 @@ import os import tempfile import unittest -from StringIO import StringIO +from six.moves import cStringIO from swiftbench import utils @@ -42,11 +42,11 @@ foo = bar log_name = yarr''' # setup a real file fd, temppath = tempfile.mkstemp(dir='/tmp') - with os.fdopen(fd, 'wb') as f: + with os.fdopen(fd, 'w') as f: f.write(conf) make_filename = lambda: temppath # setup a file stream - make_fp = lambda: StringIO(conf) + make_fp = lambda: cStringIO(conf) for conf_object_maker in (make_filename, make_fp): conffile = conf_object_maker() result = utils.readconf(conffile) @@ -88,11 +88,11 @@ foo = bar log_name = %(yarr)s''' # setup a real file fd, temppath = tempfile.mkstemp(dir='/tmp') - with os.fdopen(fd, 'wb') as f: + with os.fdopen(fd, 'w') as f: f.write(conf) make_filename = lambda: temppath # setup a file stream - make_fp = lambda: StringIO(conf) + make_fp = lambda: cStringIO(conf) for conf_object_maker in (make_filename, make_fp): conffile = conf_object_maker() result = utils.readconf(conffile, raw=True) @@ -1,5 +1,5 @@ [tox] -envlist = py34,py27,pypy,pep8 +envlist = py37,py27,pypy,pep8 minversion = 1.6 [testenv] |