Port from Python2 to Python3

Switch to stestr

Change-Id: I97b333785d631f56e70eafe568842e8de8e207a9
This commit is contained in:
Sawan Choudhary 2020-06-12 00:20:43 -07:00
parent 748e85199f
commit 030ca32360
13 changed files with 29 additions and 26 deletions

2
.gitignore vendored

@ -25,7 +25,7 @@ pip-log.txt
.coverage .coverage
.tox .tox
nosetests.xml nosetests.xml
.testrepository .stestr/
.venv .venv
# Translations # Translations

3
.stestr.conf Normal file

@ -0,0 +1,3 @@
[DEFAULT]
test_path=${OS_TEST_PATH:-./cloudpulseclient/tests/}
top_dir=./

@ -2,6 +2,8 @@
check: check:
jobs: jobs:
- openstack-tox-pep8 - openstack-tox-pep8
- openstack-tox-py36
gate: gate:
jobs: jobs:
- openstack-tox-pep8 - openstack-tox-pep8
- openstack-tox-py36

@ -79,7 +79,7 @@ class HTTPClient(object):
def log_curl_request(self, method, url, kwargs): def log_curl_request(self, method, url, kwargs):
curl = ['curl -i -X %s' % method] curl = ['curl -i -X %s' % method]
for (key, value) in kwargs['headers'].items(): for (key, value) in list(kwargs['headers'].items()):
header = '-H \'%s: %s\'' % (key, value) header = '-H \'%s: %s\'' % (key, value)
curl.append(header) curl.append(header)
@ -343,9 +343,9 @@ class ResponseBodyIterator(object):
def __iter__(self): def __iter__(self):
while True: while True:
yield self.next() yield next(self)
def next(self): def __next__(self):
chunk = self.resp.read(CHUNKSIZE) chunk = self.resp.read(CHUNKSIZE)
if chunk: if chunk:
return chunk return chunk

@ -258,7 +258,7 @@ class ManagerWithFind(BaseManager):
the Python side. the Python side.
""" """
found = [] found = []
searches = kwargs.items() searches = list(kwargs.items())
for obj in self.list(): for obj in self.list():
try: try:
@ -423,7 +423,7 @@ class Extension(HookableMixin):
def _parse_extension_module(self): def _parse_extension_module(self):
self.manager_class = None self.manager_class = None
for attr_name, attr_value in self.module.__dict__.items(): for attr_name, attr_value in list(self.module.__dict__.items()):
if attr_name in self.SUPPORTED_HOOKS: if attr_name in self.SUPPORTED_HOOKS:
self.add_hook(attr_name, attr_value) self.add_hook(attr_name, attr_value)
else: else:
@ -460,7 +460,7 @@ class Resource(object):
def __repr__(self): def __repr__(self):
reprkeys = sorted(k reprkeys = sorted(k
for k in self.__dict__.keys() for k in list(self.__dict__.keys())
if k[0] != '_' and k != 'manager') if k[0] != '_' and k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info) return "<%s %s>" % (self.__class__.__name__, info)

@ -382,7 +382,7 @@ class BaseClient(object):
"Must be one of: %(version_map)s") % { "Must be one of: %(version_map)s") % {
'api_name': api_name, 'api_name': api_name,
'version': version, 'version': version,
'version_map': ', '.join(version_map.keys())} 'version_map': ', '.join(list(version_map.keys()))}
raise exceptions.UnsupportedVersion(msg) raise exceptions.UnsupportedVersion(msg)
return importutils.import_class(client_path) return importutils.import_class(client_path)

@ -16,7 +16,7 @@
# W0621: Redefining name %s from outer scope # W0621: Redefining name %s from outer scope
# pylint: disable=W0603,W0621 # pylint: disable=W0603,W0621
from __future__ import print_function
import getpass import getpass
import inspect import inspect

@ -22,7 +22,7 @@
Command-line interface to the OpenStack Cloudpulse API. Command-line interface to the OpenStack Cloudpulse API.
""" """
from __future__ import print_function
import argparse import argparse
import getpass import getpass
import logging import logging
@ -561,9 +561,9 @@ class OpenStackCloudPulseShell(object):
""" """
commands = set() commands = set()
options = set() options = set()
for sc_str, sc in self.subcommands.items(): for sc_str, sc in list(self.subcommands.items()):
commands.add(sc_str) commands.add(sc_str)
for option in sc._optionals._option_string_actions.keys(): for option in list(sc._optionals._option_string_actions.keys()):
options.add(option) options.add(option)
commands.remove('bash-completion') commands.remove('bash-completion')
@ -595,8 +595,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
def main(): def main():
try: try:
OpenStackCloudPulseShell().main(map(encodeutils.safe_decode, OpenStackCloudPulseShell().main(list(map(encodeutils.safe_decode,
sys.argv[1:])) sys.argv[1:])))
except Exception as e: except Exception as e:
logger.debug(e, exc_info=1) logger.debug(e, exc_info=1)

@ -57,7 +57,7 @@ class HealthCheckManager(base.Manager):
def create(self, **kwargs): def create(self, **kwargs):
new = {} new = {}
for (key, value) in kwargs.items(): for (key, value) in list(kwargs.items()):
new[key] = value new[key] = value
return self._create(self._path(), new) return self._create(self._path(), new)

@ -36,8 +36,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'python-cloudpulseclient' project = 'python-cloudpulseclient'
copyright = u'2013, OpenStack Foundation' copyright = '2013, OpenStack Foundation'
# If true, '()' will be appended to :func: etc. cross-reference text. # If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True add_function_parentheses = True
@ -66,8 +66,8 @@ htmlhelp_basename = '%sdoc' % project
latex_documents = [ latex_documents = [
('index', ('index',
'%s.tex' % project, '%s.tex' % project,
u'%s Documentation' % project, '%s Documentation' % project,
u'OpenStack Foundation', 'manual'), 'OpenStack Foundation', 'manual'),
] ]
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.

@ -13,13 +13,9 @@ classifier =
License :: OSI Approved :: Apache Software License License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux Operating System :: POSIX :: Linux
Programming Language :: Python Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3 Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
[files] [files]
packages = packages =

@ -9,6 +9,6 @@ python-subunit>=0.0.18
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
oslosphinx>=2.5.0 # Apache-2.0 oslosphinx>=2.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0
testrepository>=0.0.18 stestr>=2.0.0
testscenarios>=0.4 testscenarios>=0.4
testtools>=1.4.0 testtools>=1.4.0

@ -1,5 +1,5 @@
[tox] [tox]
minversion = 2.0 minversion = 3.1.1
envlist = py36,pep8 envlist = py36,pep8
skipsdist = True skipsdist = True
@ -17,11 +17,13 @@ deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
passenv = TEMPEST_* OS_TEST_* passenv = TEMPEST_* OS_TEST_*
whitelist_externals = find, stestr
commands = commands =
find . -type f -name "*.py[c|o]" -delete find . -type f -name "*.py[c|o]" -delete
stestr run {posargs} stestr run {posargs}
[testenv:pep8] [testenv:pep8]
whitelist_externals = bash
commands = commands =
bash tools/flake8wrap.sh {posargs} bash tools/flake8wrap.sh {posargs}