Remove usage of six

Remove six-library Replace the following items with Python 3 style code.
- six.reraise
- six.assertCountEqual
- six.iteritems
- six.next
- six.itervalues

Change-Id: Id5d7e1e75498af7e0551a52a5b2836339748b064
This commit is contained in:
songwenping 2021-02-22 14:47:34 +08:00 committed by Martin Kopec
parent a6ee2d1912
commit e662307b81
10 changed files with 17 additions and 31 deletions

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.compute import base
from tempest.common import utils
from tempest.lib.common.utils import data_utils
@ -84,11 +82,11 @@ class ServerTagsTestJSON(base.BaseV2ComputeTest):
new_tags = [data_utils.rand_name('tag'), data_utils.rand_name('tag')]
replaced_tags = self.client.update_all_tags(
self.server['id'], new_tags)['tags']
six.assertCountEqual(self, new_tags, replaced_tags)
self.assertCountEqual(new_tags, replaced_tags)
# List the tags and check that the tags were replaced.
fetched_tags = self.client.list_tags(self.server['id'])['tags']
six.assertCountEqual(self, new_tags, fetched_tags)
self.assertCountEqual(new_tags, fetched_tags)
@decorators.idempotent_id('a63b2a74-e918-4b7c-bcab-10c855f3a57e')
def test_delete_all_tags(self):

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.network import base
from tempest.common import utils
from tempest.lib.common.utils import data_utils
@ -99,8 +97,7 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest):
body = self.ports_client.update_port(
port_id, allowed_address_pairs=allowed_address_pairs)
allowed_address_pair = body['port']['allowed_address_pairs']
six.assertCountEqual(self, allowed_address_pair,
allowed_address_pairs)
self.assertCountEqual(allowed_address_pair, allowed_address_pairs)
@decorators.idempotent_id('9599b337-272c-47fd-b3cf-509414414ac4')
def test_update_port_with_address_pair(self):

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import netaddr
import six
import testtools
from tempest.api.network import base
@ -595,9 +594,9 @@ class NetworksIpV6Test(NetworksTest):
subnets = [sub['id'] for sub in body['subnets']
if sub['network_id'] == network['id']]
test_subnet_ids = [sub['id'] for sub in (subnet1, subnet2)]
six.assertCountEqual(self, subnets,
test_subnet_ids,
'Subnet are not in the same network')
self.assertCountEqual(subnets,
test_subnet_ids,
'Subnet are not in the same network')
class NetworksIpV6TestAttrs(BaseNetworkTestResources):

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.volume import base
from tempest.common import waiters
from tempest import config
@ -149,4 +148,4 @@ class VolumeMultiBackendTest(base.BaseVolumeAdminTest):
# assert that volumes are each created on separate hosts:
msg = ("volumes %s were created in the same backend" % ", "
.join(volume_hosts))
six.assertCountEqual(self, volume_hosts, set(volume_hosts), msg)
self.assertCountEqual(volume_hosts, set(volume_hosts), msg)

View File

@ -16,7 +16,6 @@ import ipaddress
import netaddr
from oslo_log import log as logging
import six
from tempest.lib.common import cred_client
from tempest.lib.common import cred_provider
@ -556,7 +555,7 @@ class DynamicCredentialProvider(cred_provider.CredentialProvider):
if not self._creds:
return
self._clear_isolated_net_resources()
for creds in six.itervalues(self._creds):
for creds in self._creds.values():
try:
self.creds_client.delete_user(creds.user_id)
except lib_exc.NotFound:

View File

@ -24,7 +24,6 @@ import jsonschema
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_serialization import jsonutils as json
import six
from tempest.lib.common import http
from tempest.lib.common import jsonschema_validator
@ -509,7 +508,7 @@ class RestClient(object):
if not hasattr(body, "keys") or len(body.keys()) != 1:
return body
# Just return the "wrapped" element
_, first_item = six.next(six.iteritems(body))
_, first_item = tuple(body.items())[0]
if isinstance(first_item, (dict, list)):
return first_item
except (ValueError, IndexError):

View File

@ -15,7 +15,6 @@ import sys
import netaddr
from oslo_log import log as logging
import six
from tempest.lib.common import ssh
from tempest.lib.common.utils import test_utils
@ -55,8 +54,8 @@ def debug_ssh(function):
except Exception:
msg = 'Could not get console_log for server %s'
LOG.debug(msg, self.server['id'])
# re-raise the original ssh timeout exception
six.reraise(*original_exception)
# raise the original ssh timeout exception
raise
finally:
# Delete the traceback to avoid circular references
_, _, trace = original_exception

View File

@ -20,7 +20,6 @@ import sys
import debtcollector.moves
import fixtures
from oslo_log import log as logging
import six
import testtools
from tempest import clients
@ -179,7 +178,7 @@ class BaseTestCase(testtools.testcase.WithAttributes,
etype, cls.__name__)
cls.tearDownClass()
try:
six.reraise(etype, value, trace)
raise value.with_traceback(trace)
finally:
del trace # to avoid circular refs
finally:
@ -233,7 +232,7 @@ class BaseTestCase(testtools.testcase.WithAttributes,
# the first one
if re_raise and etype is not None:
try:
six.reraise(etype, value, trace)
raise value.with_traceback(trace)
finally:
del trace # to avoid circular refs

View File

@ -17,7 +17,6 @@ import copy
import fixtures
import jsonschema
from oslo_serialization import jsonutils as json
import six
from tempest.lib.common import http
from tempest.lib.common import rest_client
@ -93,7 +92,7 @@ class TestRestClientNotFoundHandling(BaseRestClientTestClass):
class TestRestClientHeadersJSON(TestRestClientHTTPMethods):
def _verify_headers(self, resp):
resp = dict((k.lower(), v) for k, v in six.iteritems(resp))
resp = dict((k.lower(), v) for k, v in resp.items())
self.assertEqual(self.header_value, resp['accept'])
self.assertEqual(self.header_value, resp['content-type'])

View File

@ -16,7 +16,6 @@ import types
from unittest import mock
import fixtures
import six
import testtools
from tempest.lib import auth
@ -270,8 +269,7 @@ class TestServiceClients(base.TestCase):
'module_path': 'This neither',
'client_names': ['SomeClient1']}]}
msg = "(?=.*{0})(?=.*{1})".format(
*[x[1][0]['module_path'] for x in six.iteritems(
fake_service_clients)])
*[x[1][0]['module_path'] for x in fake_service_clients.items()])
self.useFixture(fixtures.MockPatchObject(
clients.ClientsRegistry(), 'get_service_clients',
return_value=fake_service_clients))
@ -300,8 +298,8 @@ class TestServiceClients(base.TestCase):
'module_path': 'fake_path_2',
'client_names': ['SomeClient2']}]}
msg = "(?=.*{0})(?=.*{1})".format(
*[x[1][0]['service_version'] for x in six.iteritems(
fake_service_clients)])
*[x[1][0]['service_version'] for x in
fake_service_clients.items()])
self.useFixture(fixtures.MockPatchObject(
clients.ClientsRegistry(), 'get_service_clients',
return_value=fake_service_clients))