Remove usage of six
Remove six-library Replace the following items with Python 3 style code. - six.string_types - six.text_type Change-Id: I8d06743b7a21cfa4db88f9503e2ab9247f6685b8
This commit is contained in:
parent
0ea8f1b05d
commit
99d5dcc170
@ -10,7 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
|
||||
@ -21,7 +20,7 @@ def encode(value, encoding='utf-8'):
|
||||
|
||||
"""
|
||||
|
||||
if isinstance(value, six.text_type):
|
||||
if isinstance(value, str):
|
||||
return value.encode(encoding)
|
||||
else:
|
||||
return value
|
||||
|
@ -159,7 +159,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
self.fail('Command does not fail as required (%s)' % signature)
|
||||
except CommandException as e:
|
||||
self.assertIn(
|
||||
message, six.text_type(e),
|
||||
message, str(e),
|
||||
'Command "%s" fails with different message' % e.cmd)
|
||||
|
||||
def resource_provider_create(self,
|
||||
@ -178,7 +178,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
self.resource_provider_delete(res['uuid'])
|
||||
except CommandException as exc:
|
||||
# may have already been deleted by a test case
|
||||
err_message = six.text_type(exc).lower()
|
||||
err_message = str(exc).lower()
|
||||
if 'no resource provider' not in err_message:
|
||||
raise
|
||||
self.addCleanup(cleanup)
|
||||
@ -255,7 +255,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
self.openstack('resource provider allocation delete ' + uuid)
|
||||
except CommandException as exc:
|
||||
# may have already been deleted by a test case
|
||||
if 'not found' in six.text_type(exc).lower():
|
||||
if 'not found' in str(exc).lower():
|
||||
pass
|
||||
self.addCleanup(cleanup, consumer_uuid)
|
||||
|
||||
@ -272,7 +272,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
if provider:
|
||||
# --provider can be specified multiple times so if we only get
|
||||
# a single string value convert to a list.
|
||||
if isinstance(provider, six.string_types):
|
||||
if isinstance(provider, str):
|
||||
provider = [provider]
|
||||
cmd += ' ' + ' '.join(
|
||||
'--provider %s' % rp_uuid for rp_uuid in provider)
|
||||
@ -286,7 +286,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
self.openstack('resource provider allocation delete ' + uuid)
|
||||
except CommandException as exc:
|
||||
# may have already been deleted by a test case
|
||||
if 'not found' in six.text_type(exc).lower():
|
||||
if 'not found' in str(exc).lower():
|
||||
pass
|
||||
self.addCleanup(cleanup, consumer_uuid)
|
||||
|
||||
@ -406,7 +406,7 @@ class BaseTestCase(base.BaseTestCase):
|
||||
self.trait_delete(name)
|
||||
except CommandException as exc:
|
||||
# may have already been deleted by a test case
|
||||
err_message = six.text_type(exc).lower()
|
||||
err_message = str(exc).lower()
|
||||
if 'http 404' not in err_message:
|
||||
raise
|
||||
self.addCleanup(cleanup)
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from osc_placement.tests.functional import base
|
||||
|
||||
|
||||
@ -91,7 +89,7 @@ class TestAllocation(base.BaseTestCase):
|
||||
self.resource_allocation_set,
|
||||
consumer_uuid, [])
|
||||
self.assertIn('At least one resource allocation must be specified',
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_allocation_delete(self):
|
||||
consumer_uuid = str(uuid.uuid4())
|
||||
@ -112,7 +110,7 @@ class TestAllocation(base.BaseTestCase):
|
||||
msg = "No allocations for consumer '{}'".format(consumer_uuid)
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_allocation_delete, consumer_uuid)
|
||||
self.assertIn(msg, six.text_type(exc))
|
||||
self.assertIn(msg, str(exc))
|
||||
|
||||
|
||||
class TestAllocation18(base.BaseTestCase):
|
||||
|
@ -14,8 +14,6 @@ import collections
|
||||
import copy
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from osc_placement.tests.functional import base
|
||||
|
||||
|
||||
@ -53,7 +51,7 @@ class TestInventory(base.BaseTestCase):
|
||||
self.resource_inventory_show,
|
||||
rp_uuid, 'VCPU')
|
||||
self.assertIn('No inventory of class VCPU for {}'.format(rp_uuid),
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_inventory_list(self):
|
||||
rp_uuid = self.rp['uuid']
|
||||
@ -86,14 +84,14 @@ class TestInventory(base.BaseTestCase):
|
||||
self.resource_inventory_show,
|
||||
rp_uuid, 'VCPU')
|
||||
self.assertIn('No inventory of class VCPU for {}'.format(rp_uuid),
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_inventory_delete_not_found(self):
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_delete,
|
||||
self.rp['uuid'], 'VCPU')
|
||||
self.assertIn('No inventory of class VCPU found for delete',
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_delete_all_inventories(self):
|
||||
# Negative test to assert command failure because
|
||||
@ -109,7 +107,7 @@ class TestSetInventory(base.BaseTestCase):
|
||||
exc = self.assertRaises(
|
||||
base.CommandException,
|
||||
self.openstack, 'resource provider inventory set')
|
||||
self.assertIn(base.ARGUMENTS_MISSING, six.text_type(exc))
|
||||
self.assertIn(base.ARGUMENTS_MISSING, str(exc))
|
||||
|
||||
def test_set_empty_inventories(self):
|
||||
rp = self.resource_provider_create()
|
||||
@ -121,30 +119,30 @@ class TestSetInventory(base.BaseTestCase):
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'VCPU')
|
||||
self.assertIn('must have "name=value"', six.text_type(exc))
|
||||
self.assertIn('must have "name=value"', str(exc))
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'VCPU==')
|
||||
self.assertIn('must have "name=value"', six.text_type(exc))
|
||||
self.assertIn('must have "name=value"', str(exc))
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], '=10')
|
||||
self.assertIn('must be not empty', six.text_type(exc))
|
||||
self.assertIn('must be not empty', str(exc))
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'v=')
|
||||
self.assertIn('must be not empty', six.text_type(exc))
|
||||
self.assertIn('must be not empty', str(exc))
|
||||
|
||||
# unknown class
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'UNKNOWN_CPU=16')
|
||||
self.assertIn('Unknown resource class', six.text_type(exc))
|
||||
self.assertIn('Unknown resource class', str(exc))
|
||||
# unknown property
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'VCPU:fake=16')
|
||||
self.assertIn('Unknown inventory field', six.text_type(exc))
|
||||
self.assertIn('Unknown inventory field', str(exc))
|
||||
|
||||
def test_set_multiple_classes(self):
|
||||
rp = self.resource_provider_create()
|
||||
@ -178,7 +176,7 @@ class TestSetInventory(base.BaseTestCase):
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_inventory_set,
|
||||
rp['uuid'], 'VCPU=8', 'UNKNOWN=4')
|
||||
self.assertIn('Unknown resource class', six.text_type(exc))
|
||||
self.assertIn('Unknown resource class', str(exc))
|
||||
self.assertEqual([], self.resource_inventory_list(rp['uuid']))
|
||||
|
||||
def test_replace_previous_values(self):
|
||||
@ -205,24 +203,24 @@ class TestSetInventory(base.BaseTestCase):
|
||||
exc = self.assertRaises(
|
||||
base.CommandException,
|
||||
self.openstack, 'resource provider inventory class set')
|
||||
self.assertIn(base.ARGUMENTS_MISSING, six.text_type(exc))
|
||||
self.assertIn(base.ARGUMENTS_MISSING, str(exc))
|
||||
exc = self.assertRaises(
|
||||
base.CommandException,
|
||||
self.openstack, 'resource provider inventory class set fake_uuid')
|
||||
self.assertIn(base.ARGUMENTS_MISSING, six.text_type(exc))
|
||||
self.assertIn(base.ARGUMENTS_MISSING, str(exc))
|
||||
exc = self.assertRaises(
|
||||
base.CommandException,
|
||||
self.openstack,
|
||||
('resource provider inventory class set '
|
||||
'fake_uuid fake_class --total 5 --unknown 1'))
|
||||
self.assertIn('unrecognized arguments', six.text_type(exc))
|
||||
self.assertIn('unrecognized arguments', str(exc))
|
||||
# Valid RP UUID and resource class, but no inventory field.
|
||||
rp = self.resource_provider_create()
|
||||
exc = self.assertRaises(
|
||||
base.CommandException, self.openstack,
|
||||
'resource provider inventory class set %s VCPU' % rp['uuid'])
|
||||
self.assertIn(base.ARGUMENTS_REQUIRED % '--total',
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_set_inventory_for_resource_class(self):
|
||||
rp = self.resource_provider_create()
|
||||
@ -429,7 +427,7 @@ class TestAggregateInventory(base.BaseTestCase):
|
||||
'VCPU=8',
|
||||
aggregate=True)
|
||||
self.assertIn('No resource providers found in aggregate with uuid {}'
|
||||
.format(nonexistent_agg), six.text_type(exc))
|
||||
.format(nonexistent_agg), str(exc))
|
||||
|
||||
def test_with_aggregate_one_fails(self):
|
||||
# Set up some existing inventories with two resource providers
|
||||
@ -451,7 +449,7 @@ class TestAggregateInventory(base.BaseTestCase):
|
||||
self.resource_inventory_set,
|
||||
agg, *new_resources, aggregate=True)
|
||||
self.assertIn('Failed to set inventory for 1 of 2 resource providers.',
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
output = self.output.getvalue() + self.error.getvalue()
|
||||
self.assertIn('Failed to set inventory for resource provider %s:' %
|
||||
rp1_uuid, output)
|
||||
|
@ -13,8 +13,6 @@
|
||||
import operator
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from osc_placement.tests.functional import base
|
||||
|
||||
|
||||
@ -39,12 +37,12 @@ class TestResourceProvider(base.BaseTestCase):
|
||||
self.assertEqual([], after_delete)
|
||||
|
||||
def test_resource_provider_delete_not_found(self):
|
||||
rp_uuid = six.text_type(uuid.uuid4())
|
||||
rp_uuid = str(uuid.uuid4())
|
||||
msg = 'No resource provider with uuid ' + rp_uuid + ' found'
|
||||
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_provider_delete, rp_uuid)
|
||||
self.assertIn(msg, six.text_type(exc))
|
||||
self.assertIn(msg, str(exc))
|
||||
|
||||
def test_resource_provider_set(self):
|
||||
orig_name = self.rand_name('test_rp_orig_name')
|
||||
@ -61,12 +59,12 @@ class TestResourceProvider(base.BaseTestCase):
|
||||
self.assertEqual(0, after_update['generation'])
|
||||
|
||||
def test_resource_provider_set_not_found(self):
|
||||
rp_uuid = six.text_type(uuid.uuid4())
|
||||
rp_uuid = str(uuid.uuid4())
|
||||
msg = 'No resource provider with uuid ' + rp_uuid + ' found'
|
||||
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_provider_set, rp_uuid, 'test')
|
||||
self.assertIn(msg, six.text_type(exc))
|
||||
self.assertIn(msg, str(exc))
|
||||
|
||||
def test_resource_provider_show(self):
|
||||
created = self.resource_provider_create()
|
||||
@ -99,12 +97,12 @@ class TestResourceProvider(base.BaseTestCase):
|
||||
self.assertEqual(expected, retrieved)
|
||||
|
||||
def test_resource_provider_show_not_found(self):
|
||||
rp_uuid = six.text_type(uuid.uuid4())
|
||||
rp_uuid = str(uuid.uuid4())
|
||||
msg = 'No resource provider with uuid ' + rp_uuid + ' found'
|
||||
|
||||
exc = self.assertRaises(base.CommandException,
|
||||
self.resource_provider_show, rp_uuid)
|
||||
self.assertIn(msg, six.text_type(exc))
|
||||
self.assertIn(msg, str(exc))
|
||||
|
||||
def test_resource_provider_list(self):
|
||||
rp1 = self.resource_provider_create()
|
||||
@ -256,7 +254,7 @@ class TestResourceProvider114(base.BaseTestCase):
|
||||
child['uuid'],
|
||||
name='mandatory_name_2',
|
||||
parent_provider_uuid=parent2['uuid'])
|
||||
self.assertIn('HTTP 400', six.text_type(exc))
|
||||
self.assertIn('HTTP 400', str(exc))
|
||||
|
||||
def test_resource_provider_list_in_tree(self):
|
||||
rp1 = self.resource_provider_create()
|
||||
@ -278,7 +276,7 @@ class TestResourceProvider114(base.BaseTestCase):
|
||||
base.CommandException,
|
||||
self.resource_provider_delete,
|
||||
parent['uuid'])
|
||||
self.assertIn('HTTP 409', six.text_type(exc))
|
||||
self.assertIn('HTTP 409', str(exc))
|
||||
|
||||
|
||||
class TestResourceProvider118(base.BaseTestCase):
|
||||
|
@ -13,8 +13,6 @@
|
||||
import operator
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from osc_placement.tests.functional import base
|
||||
|
||||
|
||||
@ -52,7 +50,7 @@ class TestUsage(base.BaseTestCase):
|
||||
rp_uuid)
|
||||
self.assertIn(
|
||||
'No resource provider with uuid {} found'.format(rp_uuid),
|
||||
six.text_type(exc)
|
||||
str(exc)
|
||||
)
|
||||
|
||||
def test_usage_empty(self):
|
||||
|
@ -14,7 +14,6 @@ import uuid
|
||||
|
||||
from osc_lib import exceptions
|
||||
from oslotest import base
|
||||
import six
|
||||
|
||||
from osc_placement.resources import allocation
|
||||
|
||||
@ -51,7 +50,7 @@ class TestAllocation(base.BaseTestCase):
|
||||
exceptions.CommandError, allocation.parse_allocations, allocations)
|
||||
self.assertEqual(
|
||||
'Conflict detected for resource provider %s resource class VCPU' %
|
||||
rp1, six.text_type(ex))
|
||||
rp1, str(ex))
|
||||
|
||||
def test_fail_if_incorrect_format(self):
|
||||
allocations = ['incorrect_format']
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import six
|
||||
|
||||
import keystoneauth1.exceptions.http as ks_exceptions
|
||||
import osc_lib.exceptions as exceptions
|
||||
import oslotest.base as base
|
||||
@ -54,7 +52,7 @@ class TestSessionClient(base.BaseTestCase):
|
||||
exc = self.assertRaises(exceptions.NotFound, go)
|
||||
self.assertEqual(404, exc.http_status)
|
||||
self.assertIn('No resource provider with uuid 123 found',
|
||||
six.text_type(exc))
|
||||
str(exc))
|
||||
|
||||
def test_unexpected_response(self):
|
||||
def go():
|
||||
@ -63,7 +61,7 @@ class TestSessionClient(base.BaseTestCase):
|
||||
|
||||
exc = self.assertRaises(ks_exceptions.InternalServerError, go)
|
||||
self.assertEqual(500, exc.http_status)
|
||||
self.assertIn('Internal Server Error (HTTP 500)', six.text_type(exc))
|
||||
self.assertIn('Internal Server Error (HTTP 500)', str(exc))
|
||||
|
||||
def test_session_client_version(self):
|
||||
session = mock.Mock()
|
||||
|
@ -13,7 +13,6 @@
|
||||
from unittest import mock
|
||||
|
||||
import oslotest.base as base
|
||||
import six
|
||||
|
||||
from osc_placement import version
|
||||
|
||||
@ -57,13 +56,13 @@ class TestVersion(base.BaseTestCase):
|
||||
ValueError, version.compare, '1.0', version.ge('1.1'))
|
||||
self.assertEqual(
|
||||
'Operation or argument is not supported with version 1.0; '
|
||||
'requires at least version 1.1', six.text_type(ex))
|
||||
'requires at least version 1.1', str(ex))
|
||||
ex = self.assertRaises(
|
||||
ValueError, version.compare, '1.0',
|
||||
version.eq('1.1'), version.eq('1.5'), op=any)
|
||||
self.assertEqual(
|
||||
'Operation or argument is not supported with version 1.0; '
|
||||
'requires version 1.1, or requires version 1.5', six.text_type(ex))
|
||||
'requires version 1.1, or requires version 1.5', str(ex))
|
||||
|
||||
def test_compare_with_exc(self):
|
||||
self.assertTrue(version.compare('1.05', version.gt('1.4')))
|
||||
|
Loading…
x
Reference in New Issue
Block a user