Port to py3

Change-Id: Ib86178259f854c15dd305dd39779a203cafb0451
This commit is contained in:
Tim Burke
2019-08-29 11:38:59 -07:00
parent 6e047b640d
commit f221632a82
9 changed files with 34 additions and 23 deletions

View File

@@ -1,3 +1,5 @@
- project:
templates:
- check-requirements
- openstack-python-jobs
- openstack-python3-train-jobs

View File

@@ -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)

View File

@@ -1,2 +1,3 @@
python-swiftclient
python-swiftclient>=3.2.0
eventlet>=0.17.4 # MIT
six>=1.9.0

View File

@@ -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',
],

View File

@@ -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)

View File

@@ -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):

View File

@@ -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

View File

@@ -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)

View File

@@ -1,5 +1,5 @@
[tox]
envlist = py34,py27,pypy,pep8
envlist = py37,py27,pypy,pep8
minversion = 1.6
[testenv]