From 0c34a4901df8b92aa461969387cb19ea391e8ccd Mon Sep 17 00:00:00 2001 From: junboli Date: Thu, 25 Oct 2018 04:01:24 +0800 Subject: [PATCH] Fix pep8 error when running tox openstack-tox-pep8 now is failure, this patch is to fix this. Closes-bug: #1799930 Change-Id: Ia1b7f3395e92014e0f5373d81788dc55f7815002 --- .zuul.yaml | 4 ++-- dcmanager/common/exceptions.py | 3 ++- dcorch/common/exceptions.py | 3 ++- dcorch/drivers/openstack/sysinv_v1.py | 3 ++- setup_ddt_tests.py | 24 +++++++++++++----------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 3904b10e4..d23bca5da 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -6,12 +6,12 @@ jobs: - build-openstack-releasenotes - openstack-tox-linters - - openstack-tox-pep8: - voting: false + - openstack-tox-pep8 gate: jobs: - build-openstack-releasenotes - openstack-tox-linters + - openstack-tox-pep8 post: jobs: - publish-stx-api-ref diff --git a/dcmanager/common/exceptions.py b/dcmanager/common/exceptions.py index a9bfc0a15..fb603943d 100644 --- a/dcmanager/common/exceptions.py +++ b/dcmanager/common/exceptions.py @@ -26,6 +26,7 @@ DC Manager base exception handling. """ import six +from oslo_utils import encodeutils from oslo_utils import excutils from dcmanager.common.i18n import _ @@ -54,7 +55,7 @@ class DCManagerException(Exception): if six.PY2: def __unicode__(self): - return unicode(self.msg) + return encodeutils.exception_to_unicode(self.msg) def use_fatal_exceptions(self): return False diff --git a/dcorch/common/exceptions.py b/dcorch/common/exceptions.py index a8dd0f87a..73f66b9b5 100644 --- a/dcorch/common/exceptions.py +++ b/dcorch/common/exceptions.py @@ -19,6 +19,7 @@ DC Orchestrator base exception handling. """ import six +from oslo_utils import encodeutils from oslo_utils import excutils from dcorch.common.i18n import _ @@ -47,7 +48,7 @@ class OrchestratorException(Exception): if six.PY2: def __unicode__(self): - return unicode(self.msg) + return encodeutils.exception_to_unicode(self.msg) def use_fatal_exceptions(self): return False diff --git a/dcorch/drivers/openstack/sysinv_v1.py b/dcorch/drivers/openstack/sysinv_v1.py index a0f1c5cf4..5dd7c87dd 100644 --- a/dcorch/drivers/openstack/sysinv_v1.py +++ b/dcorch/drivers/openstack/sysinv_v1.py @@ -12,6 +12,7 @@ import hashlib import os +import six import tsconfig.tsconfig as tsc from cgtsclient import client as cgts_client @@ -402,7 +403,7 @@ class SysinvClient(base.DriverBase): if k in self.REMOTELOGGING_PATCH_ATTRS: if k == 'action': action_found = True - elif k == 'enabled' and not isinstance(v, basestring): + elif k == 'enabled' and not isinstance(v, six.string_types): # api requires a string for enabled if not v: patch[k] = 'false' diff --git a/setup_ddt_tests.py b/setup_ddt_tests.py index b6b5e8e10..d84c9afcd 100644 --- a/setup_ddt_tests.py +++ b/setup_ddt_tests.py @@ -66,8 +66,11 @@ def set_current_test_data(cfg): def print_divider(width, txt): - width_new = (int(width) - len(txt)) / 2 - print '%s%s%s' % ('_' * width_new, txt, '_' * width_new) + width_new = (int(width) - len(txt)) // 2 + width_dash = '_' * width_new + print('%(width_dash)s%(txt)s%(width_dash)s', {'width_dash': width_dash, + 'txt': txt, + 'width_dash': width_dash}) def get_divider_size(): @@ -80,29 +83,28 @@ def get_divider_size(): # Get all repository information data_dir = get_data_repo() -print 'Using %s as data directory' % data_dir +print('Using %(data_dir)s as data directory', {'data_dir': data_dir}) cfgs = get_cfgs() cfgs_usable = filter_cfgs(cfgs) -print 'Required repo databases: %s' % os.environ.get('REQUIRED_REPOS') -print "Test data folder(s) found: %s" % cfgs +repo = os.environ.get('REQUIRED_REPOS') +print('Required repo databases: %(repo)s', {'repo': repo}) +print("Test data folder(s) found: %(cfgs)s", {'cfgs': cfgs}) if len(cfgs_usable) == 0: - print 'No usable data sets found' + print('No usable data sets found') exit -print 'Usable data folder(s): %s' % cfgs_usable +print('Usable data folder(s): %(cfgs_usable)s', {'cfgs_usable': cfgs_usable}) if os.environ.get('SINGLE_REPO') == 'True': cfgs_usable = [cfgs_usable[0]] - print 'Restricting to single data set: %s' % cfgs_usable[0] -print '' + print('Restricting to single data set: %(cfgs)s', {'cfgs': cfgs_usable}) # Loop through all configurations and run unit tests with each columns = get_divider_size() for cfg in cfgs_usable: print_divider(columns, cfg) - print 'Running unit tests with test data: %s' % cfg + print('Running unit tests with test data: %(cfg)s', {'cfg': cfg}) set_current_test_data(cfg) setuptools.setup( setup_requires=['pbr>=1.8.0'], pbr=True) - print ''