From 030ca3236054f23abcb0e531c2dbb339ddc9bd33 Mon Sep 17 00:00:00 2001 From: Sawan Choudhary <sawchoud@cisco.com> Date: Fri, 12 Jun 2020 00:20:43 -0700 Subject: [PATCH] Port from Python2 to Python3 Switch to stestr Change-Id: I97b333785d631f56e70eafe568842e8de8e207a9 --- .gitignore | 2 +- .stestr.conf | 3 +++ .zuul.yaml | 2 ++ cloudpulseclient/common/httpclient.py | 6 +++--- cloudpulseclient/openstack/common/apiclient/base.py | 6 +++--- cloudpulseclient/openstack/common/apiclient/client.py | 2 +- cloudpulseclient/openstack/common/cliutils.py | 2 +- cloudpulseclient/shell.py | 10 +++++----- cloudpulseclient/v1/cloudpulseservices.py | 2 +- doc/source/conf.py | 8 ++++---- setup.cfg | 6 +----- test-requirements.txt | 2 +- tox.ini | 4 +++- 13 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 .stestr.conf diff --git a/.gitignore b/.gitignore index 8a3c704..344bf21 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ pip-log.txt .coverage .tox nosetests.xml -.testrepository +.stestr/ .venv # Translations diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 0000000..3d08e50 --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=${OS_TEST_PATH:-./cloudpulseclient/tests/} +top_dir=./ diff --git a/.zuul.yaml b/.zuul.yaml index 1fd1fe4..9ba9187 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,6 +2,8 @@ check: jobs: - openstack-tox-pep8 + - openstack-tox-py36 gate: jobs: - openstack-tox-pep8 + - openstack-tox-py36 diff --git a/cloudpulseclient/common/httpclient.py b/cloudpulseclient/common/httpclient.py index c6997d6..bda74a7 100644 --- a/cloudpulseclient/common/httpclient.py +++ b/cloudpulseclient/common/httpclient.py @@ -79,7 +79,7 @@ class HTTPClient(object): def log_curl_request(self, method, url, kwargs): 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) curl.append(header) @@ -343,9 +343,9 @@ class ResponseBodyIterator(object): def __iter__(self): while True: - yield self.next() + yield next(self) - def next(self): + def __next__(self): chunk = self.resp.read(CHUNKSIZE) if chunk: return chunk diff --git a/cloudpulseclient/openstack/common/apiclient/base.py b/cloudpulseclient/openstack/common/apiclient/base.py index b302ce6..3197658 100644 --- a/cloudpulseclient/openstack/common/apiclient/base.py +++ b/cloudpulseclient/openstack/common/apiclient/base.py @@ -258,7 +258,7 @@ class ManagerWithFind(BaseManager): the Python side. """ found = [] - searches = kwargs.items() + searches = list(kwargs.items()) for obj in self.list(): try: @@ -423,7 +423,7 @@ class Extension(HookableMixin): def _parse_extension_module(self): 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: self.add_hook(attr_name, attr_value) else: @@ -460,7 +460,7 @@ class Resource(object): def __repr__(self): reprkeys = sorted(k - for k in self.__dict__.keys() + for k in list(self.__dict__.keys()) if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) return "<%s %s>" % (self.__class__.__name__, info) diff --git a/cloudpulseclient/openstack/common/apiclient/client.py b/cloudpulseclient/openstack/common/apiclient/client.py index 3009a56..2657e32 100644 --- a/cloudpulseclient/openstack/common/apiclient/client.py +++ b/cloudpulseclient/openstack/common/apiclient/client.py @@ -382,7 +382,7 @@ class BaseClient(object): "Must be one of: %(version_map)s") % { 'api_name': api_name, 'version': version, - 'version_map': ', '.join(version_map.keys())} + 'version_map': ', '.join(list(version_map.keys()))} raise exceptions.UnsupportedVersion(msg) return importutils.import_class(client_path) diff --git a/cloudpulseclient/openstack/common/cliutils.py b/cloudpulseclient/openstack/common/cliutils.py index e633d70..24f47c3 100644 --- a/cloudpulseclient/openstack/common/cliutils.py +++ b/cloudpulseclient/openstack/common/cliutils.py @@ -16,7 +16,7 @@ # W0621: Redefining name %s from outer scope # pylint: disable=W0603,W0621 -from __future__ import print_function + import getpass import inspect diff --git a/cloudpulseclient/shell.py b/cloudpulseclient/shell.py index d175c6b..4fb59f8 100644 --- a/cloudpulseclient/shell.py +++ b/cloudpulseclient/shell.py @@ -22,7 +22,7 @@ Command-line interface to the OpenStack Cloudpulse API. """ -from __future__ import print_function + import argparse import getpass import logging @@ -561,9 +561,9 @@ class OpenStackCloudPulseShell(object): """ commands = set() options = set() - for sc_str, sc in self.subcommands.items(): + for sc_str, sc in list(self.subcommands.items()): 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) commands.remove('bash-completion') @@ -595,8 +595,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter): def main(): try: - OpenStackCloudPulseShell().main(map(encodeutils.safe_decode, - sys.argv[1:])) + OpenStackCloudPulseShell().main(list(map(encodeutils.safe_decode, + sys.argv[1:]))) except Exception as e: logger.debug(e, exc_info=1) diff --git a/cloudpulseclient/v1/cloudpulseservices.py b/cloudpulseclient/v1/cloudpulseservices.py index fc4a3bf..ff6318d 100644 --- a/cloudpulseclient/v1/cloudpulseservices.py +++ b/cloudpulseclient/v1/cloudpulseservices.py @@ -57,7 +57,7 @@ class HealthCheckManager(base.Manager): def create(self, **kwargs): new = {} - for (key, value) in kwargs.items(): + for (key, value) in list(kwargs.items()): new[key] = value return self._create(self._path(), new) diff --git a/doc/source/conf.py b/doc/source/conf.py index 43eadb9..69315a7 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -36,8 +36,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'python-cloudpulseclient' -copyright = u'2013, OpenStack Foundation' +project = 'python-cloudpulseclient' +copyright = '2013, OpenStack Foundation' # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True @@ -66,8 +66,8 @@ htmlhelp_basename = '%sdoc' % project latex_documents = [ ('index', '%s.tex' % project, - u'%s Documentation' % project, - u'OpenStack Foundation', 'manual'), + '%s Documentation' % project, + 'OpenStack Foundation', 'manual'), ] # Example configuration for intersphinx: refer to the Python standard library. diff --git a/setup.cfg b/setup.cfg index 50a0ab2..1c0a965 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,13 +13,9 @@ classifier = 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.3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 [files] packages = diff --git a/test-requirements.txt b/test-requirements.txt index 0c15a53..c4db64d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,6 +9,6 @@ python-subunit>=0.0.18 sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 oslosphinx>=2.5.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 -testrepository>=0.0.18 +stestr>=2.0.0 testscenarios>=0.4 testtools>=1.4.0 diff --git a/tox.ini b/tox.ini index 023cd60..42aa0e4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -minversion = 2.0 +minversion = 3.1.1 envlist = py36,pep8 skipsdist = True @@ -17,11 +17,13 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt passenv = TEMPEST_* OS_TEST_* +whitelist_externals = find, stestr commands = find . -type f -name "*.py[c|o]" -delete stestr run {posargs} [testenv:pep8] +whitelist_externals = bash commands = bash tools/flake8wrap.sh {posargs}