Merge "Remove all usage of six library"

This commit is contained in:
Zuul 2020-09-11 09:09:10 +00:00 committed by Gerrit Code Review
commit 4a283fe3b2
17 changed files with 24 additions and 61 deletions

View File

@ -75,7 +75,6 @@ requests==2.14.2
requestsexceptions==1.4.0
rfc3986==0.3.1
Routes==2.3.1
six==1.10.0
smmap2==2.0.3
SQLAlchemy==1.2.19
setuptools==21.0.0

View File

@ -13,7 +13,6 @@
import collections
import functools
import prettytable
import six
import sys
from oslo_config import cfg
@ -173,8 +172,7 @@ def add_db_command_parsers(subparsers, config):
subparsers.required = False
parser = subparsers.add_parser('db')
# Avoid https://bugs.python.org/issue9351 with cpython < 2.7.9
if not six.PY2:
parser.set_defaults(func=parser.print_help)
parser.set_defaults(func=parser.print_help)
db_parser = parser.add_subparsers(description='database commands')
help = 'Sync the datatabse to the current version.'

View File

@ -16,7 +16,6 @@
# FaultWrapper, which does more than placement needs.
from oslo_log import log as logging
import six
from webob import exc
from placement import util
@ -42,7 +41,7 @@ class FaultWrapper(object):
LOG.exception('Placement API unexpected error: %s',
unexpected_exception)
formatted_exception = exc.HTTPInternalServerError(
six.text_type(unexpected_exception))
str(unexpected_exception))
formatted_exception.json_formatter = util.json_error_formatter
return formatted_exception.generate_response(
environ, start_response)

View File

@ -17,7 +17,6 @@ import collections
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from oslo_utils import timeutils
import six
import webob
from placement import exception
@ -292,7 +291,7 @@ def list_allocation_candidates(req):
'Invalid resource class in resources parameter: %(error)s' %
{'error': exc})
except exception.TraitNotFound as exc:
raise webob.exc.HTTPBadRequest(six.text_type(exc))
raise webob.exc.HTTPBadRequest(str(exc))
response = req.response
trx_cands = _transform_allocation_candidates(cands, groups, want_version)

View File

@ -16,8 +16,6 @@ import itertools
import os_traits
from oslo_log import log as logging
from oslo_utils import encodeutils
import six
import sqlalchemy as sa
from placement.db.sqlalchemy import models
@ -202,8 +200,6 @@ class AllocationRequest(object):
'resource_requests=[%s])' %
(self.__class__.__name__, anchor, usp,
', '.join([str(arr) for arr in self.resource_requests])))
if six.PY2:
repr_str = encodeutils.safe_encode(repr_str, incoming='utf-8')
return repr_str
def __eq__(self, other):

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import sqlalchemy as sa
from placement.db.sqlalchemy import models
@ -56,7 +55,7 @@ def find(inventories, res_class):
looks up the resource class identifier from the
string.
"""
if not isinstance(res_class, six.string_types):
if not isinstance(res_class, str):
raise ValueError
for inv_rec in inventories:

View File

@ -16,7 +16,6 @@ from oslo_concurrency import lockutils
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
from oslo_log import log as logging
import six
import sqlalchemy as sa
from sqlalchemy import func
@ -229,7 +228,7 @@ def _resource_classes_sync(ctx):
LOG.debug("Found existing resource classes in db: %s", db_classes)
# Determine those resource clases which are in os_resource_classes but not
# currently in the database, and insert them.
batch_args = [{'name': six.text_type(name), 'id': index}
batch_args = [{'name': str(name), 'id': index}
for index, name in enumerate(orc.STANDARDS)
if name not in db_classes]
ins = _RC_TBL.insert()

View File

@ -17,7 +17,6 @@ from oslo_concurrency import lockutils
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
from oslo_log import log as logging
import six
import sqlalchemy as sa
from placement.db.sqlalchemy import models
@ -229,11 +228,11 @@ def _get_all_filtered_from_db(context, filters):
query = context.session.query(models.Trait)
if 'name_in' in filters:
query = query.filter(models.Trait.name.in_(
[six.text_type(n) for n in filters['name_in']]
[str(n) for n in filters['name_in']]
))
if 'prefix' in filters:
query = query.filter(
models.Trait.name.like(six.text_type(filters['prefix'] + '%')))
models.Trait.name.like(str(filters['prefix'] + '%')))
if 'associated' in filters:
if filters['associated']:
query = query.join(
@ -278,7 +277,7 @@ def _trait_sync(ctx):
need_sync = std_traits - db_traits
ins = _TRAIT_TBL.insert()
batch_args = [
{'name': six.text_type(trait)}
{'name': str(trait)}
for trait in need_sync
]
if batch_args:

View File

@ -15,7 +15,6 @@ import collections
import os_resource_classes as orc
import os_traits
from oslo_utils.fixture import uuidsentinel as uuids
import six
import sqlalchemy as sa
from placement import exception
@ -400,7 +399,7 @@ class ProviderTreeDBHelperTestCase(tb.PlacementDbBaseTestCase):
"""Utility function to look up resource provider IDs from a set of
supplied provider names directly from the API DB.
"""
names = map(six.text_type, names)
names = map(str, names)
sel = sa.select([rp_obj._RP_TBL.c.id])
sel = sel.where(rp_obj._RP_TBL.c.name.in_(names))
with self.placement_db.get_engine().connect() as conn:

View File

@ -33,7 +33,6 @@ from oslo_db.sqlalchemy import utils as db_utils
from oslo_log import log as logging
from oslo_utils.fixture import uuidsentinel as uuids
from oslotest import base as test_base
import six
import testtools
from placement.db.sqlalchemy import migration
@ -186,7 +185,7 @@ class MigrationCheckersMixin(object):
# Make sure it's the error we expect.
self.assertIn('There is at least one resource provider table '
'record which is missing its root provider id.',
six.text_type(ex))
str(ex))
# Now update the resource provider with a root_provider_id.
rps.update(
values={'root_provider_id': rp_id}).where(
@ -219,7 +218,7 @@ class MigrationCheckersMixin(object):
# Make sure it's the error we expect.
self.assertIn('There is at least one allocation record which is '
'missing a consumer record.',
six.text_type(ex))
str(ex))
# Add a (faked) consumer record and try again
consumers = db_utils.get_table(self.engine, 'consumers')
consumers.insert(values={

View File

@ -16,7 +16,6 @@ from unittest import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslotest import output
import six
import testtools
from placement.cmd import manage
@ -68,20 +67,14 @@ class TestCommandParsers(testtools.TestCase):
def test_empty_command(self):
"""An empty command should create no func."""
# Python 2.7 and 3.x behave differently here, but the result is
# satisfactory. Both result in some help output, but the Python 3
# help is better.
def parse_conf():
self.conf([], default_config_files=[])
def get_func():
return self.conf.command.func
if six.PY2:
self.assertRaises(SystemExit, parse_conf)
else:
parse_conf()
self.assertRaises(cfg.NoSuchOptError, get_func)
parse_conf()
self.assertRaises(cfg.NoSuchOptError, get_func)
def test_too_many_args(self):
self.assertRaises(SystemExit,
@ -91,24 +84,14 @@ class TestCommandParsers(testtools.TestCase):
def test_help_message(self):
"""Test that help output for sub commands shows right commands."""
# This is noisy because we have different 'help' behaviors in
# Python 2 and 3.
if six.PY2:
self.assertRaises(SystemExit, self.conf, ['db'],
default_config_files=[])
else:
self.conf(['db'], default_config_files=[])
self.conf.command.func()
self.conf(['db'], default_config_files=[])
self.conf.command.func()
self.output.stdout.seek(0)
self.output.stderr.seek(0)
if six.PY2:
self.assertIn('{sync,version,stamp,online_data_migrations}',
self.output.stderr.read())
else:
self.assertIn('{sync,version,stamp,online_data_migrations}',
self.output.stdout.read())
self.assertIn('{sync,version,stamp,online_data_migrations}',
self.output.stdout.read())
class TestDBCommands(base.ContextTestCase):

View File

@ -13,7 +13,6 @@
from unittest import mock
import six
import webob
from placement import context
@ -38,4 +37,4 @@ class TestAggregateHandlerErrors(base.ContextTestCase):
side_effect=exception.ConcurrentUpdateDetected):
exc = self.assertRaises(webob.exc.HTTPConflict,
aggregate._set_aggregates, rp, [])
self.assertIn(expected_message, six.text_type(exc))
self.assertIn(expected_message, str(exc))

View File

@ -15,7 +15,6 @@ from unittest import mock
from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import timeutils
import six
from placement.objects import allocation as alloc_obj
from placement.objects import resource_provider as rp_obj
@ -24,7 +23,7 @@ from placement.tests.unit.objects import base
_RESOURCE_PROVIDER_ID = 1
_RESOURCE_PROVIDER_UUID = uuids.resource_provider
_RESOURCE_PROVIDER_NAME = six.text_type(uuids.resource_name)
_RESOURCE_PROVIDER_NAME = str(uuids.resource_name)
_RESOURCE_CLASS_ID = 2
_ALLOCATION_ID = 2
_ALLOCATION_DB = {

View File

@ -12,7 +12,6 @@
from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import timeutils
import six
from placement import exception
from placement.objects import resource_provider
@ -23,7 +22,7 @@ _RESOURCE_CLASS_ID = 2
_RESOURCE_PROVIDER_ID = 1
_RESOURCE_PROVIDER_UUID = uuids.resource_provider
_RESOURCE_PROVIDER_NAME = six.text_type(uuids.resource_name)
_RESOURCE_PROVIDER_NAME = str(uuids.resource_name)
_RESOURCE_PROVIDER_DB = {
'id': _RESOURCE_PROVIDER_ID,
'uuid': _RESOURCE_PROVIDER_UUID,

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import testtools
from oslo_config import cfg
@ -35,4 +34,4 @@ class TestPlacementDBConf(testtools.TestCase):
[], default_config_files=[])
self.assertIn(
'option connection in group [placement_database]',
six.text_type(exc))
str(exc))

View File

@ -21,7 +21,6 @@ import microversion_parse
from oslo_middleware import request_id
from oslo_utils.fixture import uuidsentinel
from oslo_utils import timeutils
import six
import testtools
import webob
@ -162,7 +161,7 @@ class QueryParamsSchemaTestCase(testtools.TestCase):
error = self.assertRaises(webob.exc.HTTPBadRequest,
util.validate_query_params,
req, schema)
self.assertIn('Invalid query string parameters', six.text_type(error))
self.assertIn('Invalid query string parameters', str(error))
class TestJSONErrorFormatter(testtools.TestCase):
@ -831,7 +830,7 @@ class TestParseQsRequestGroups(testtools.TestCase):
"value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. Got: "
"CUSTOM_PHYSNET1,!CUSTOM_SWITCH_BIG")
exc = self.assertRaises(webob.exc.HTTPBadRequest, self.do_parse, qs)
self.assertEqual(expected_message, six.text_type(exc))
self.assertEqual(expected_message, str(exc))
self.assertRequestGroupsEqual(
expected_forbidden, self.do_parse(qs, version=(1, 22)))
@ -845,7 +844,7 @@ class TestParseQsRequestGroups(testtools.TestCase):
exc = self.assertRaises(
webob.exc.HTTPBadRequest, self.do_parse, qs, version=(1, 22))
self.assertEqual(expected_message, six.text_type(exc))
self.assertEqual(expected_message, str(exc))
def test_forbidden_two_groups(self):
qs = ('resources=VCPU:2,MEMORY_MB:2048&resources1=CUSTOM_MAGIC:1'

View File

@ -9,7 +9,6 @@ Routes>=2.3.1 # MIT
WebOb>=1.8.2 # MIT
jsonschema>=2.6.0 # MIT
requests>=2.14.2 # Apache-2.0
six>=1.10.0 # MIT
setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=21.0.0 # PSF/ZPL
oslo.concurrency>=3.26.0 # Apache-2.0
oslo.config>=6.7.0 # Apache-2.0