commit d2346f8c670df6bcf7aa80a1ded0c2fae518d1a4 Author: xuanyandong Date: Thu Oct 8 10:37:49 2020 +0800 Remove six of dir cinder/tests/unit/backup/* Replace the following items with Python 3 style code. - six.PY2 - six.PY3 - six.moves - six.text_type Change-Id: I262e5156ee730faefe55b8b25bf7541643e6df39 Implements: blueprint six-removal diff --git a/cinder/tests/unit/backup/drivers/test_backup_ceph.py b/cinder/tests/unit/backup/drivers/test_backup_ceph.py index f3b871f..bc5dacc 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_ceph.py +++ b/cinder/tests/unit/backup/drivers/test_backup_ceph.py @@ -27,8 +27,6 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import units -import six -from six.moves import range from cinder.backup import driver from cinder.backup.drivers import ceph @@ -1342,7 +1340,7 @@ class BackupCephTestCase(test.TestCase): self.service._restore_metadata(self.backup, self.volume_id) except exception.BackupOperationError as exc: msg = _("Metadata restore failed due to incompatible version") - self.assertEqual(msg, six.text_type(exc)) + self.assertEqual(msg, str(exc)) else: # Force a test failure self.assertFalse(True) @@ -1368,7 +1366,7 @@ class BackupCephTestCase(test.TestCase): msg = (_("Failed to backup volume metadata - Metadata backup " "object 'backup.%s.meta' already exists") % (self.backup_id)) - self.assertEqual(msg, six.text_type(e)) + self.assertEqual(msg, str(e)) else: # Make the test fail self.assertFalse(True) diff --git a/cinder/tests/unit/backup/drivers/test_backup_nfs.py b/cinder/tests/unit/backup/drivers/test_backup_nfs.py index 6920174..b9d764b 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_nfs.py +++ b/cinder/tests/unit/backup/drivers/test_backup_nfs.py @@ -30,7 +30,6 @@ from eventlet import tpool from os_brick import exception as brick_exception from os_brick.remotefs import remotefs as remotefs_brick from oslo_config import cfg -import six import zstd from cinder.backup.drivers import nfs @@ -920,13 +919,7 @@ class BackupNFSTestCase(test.TestCase): def create_buffer(self, size): # Set up buffer of zeroed bytes - fake_data = bytearray(size) - if six.PY2: - # On Python 2, zlib.compressor() accepts buffer, but not bytearray - # NOTE(jsbryant): Pep8 fails on py3 based installations as buffer() - # was removed. 'noqa' used here to avoid that failure. - fake_data = buffer(fake_data) # noqa - return fake_data + return bytearray(size) def test_prepare_output_data_effective_compression(self): """Test compression works on a native thread.""" diff --git a/cinder/tests/unit/backup/drivers/test_backup_posix.py b/cinder/tests/unit/backup/drivers/test_backup_posix.py index aea73d3..794c1e5 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_posix.py +++ b/cinder/tests/unit/backup/drivers/test_backup_posix.py @@ -14,11 +14,10 @@ # under the License. """Tests for Posix backup driver.""" +import builtins import os from unittest import mock -from six.moves import builtins - from cinder.backup.drivers import posix from cinder import context from cinder import objects diff --git a/cinder/tests/unit/backup/fake_google_client.py b/cinder/tests/unit/backup/fake_google_client.py index 9c074a1..5d3c294 100644 --- a/cinder/tests/unit/backup/fake_google_client.py +++ b/cinder/tests/unit/backup/fake_google_client.py @@ -21,7 +21,6 @@ import zlib from googleapiclient import errors from oauth2client import client from oslo_utils import units -import six class FakeGoogleObjectInsertExecute(object): @@ -144,8 +143,7 @@ class FakeGoogleMediaIoBaseDownload(object): 'offset': 20} }] metadata_json = json.dumps(metadata, sort_keys=True, indent=2) - if six.PY3: - metadata_json = metadata_json.encode('utf-8') + metadata_json = metadata_json.encode('utf-8') fh.write(metadata_json) else: fh.write(zlib.compress(os.urandom(units.Mi))) diff --git a/cinder/tests/unit/backup/fake_swift_client.py b/cinder/tests/unit/backup/fake_swift_client.py index cc98877..4602b43 100644 --- a/cinder/tests/unit/backup/fake_swift_client.py +++ b/cinder/tests/unit/backup/fake_swift_client.py @@ -13,13 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +from http import client as http_client import json import os import socket import zlib -import six -from six.moves import http_client from swiftclient import client as swift @@ -86,8 +85,7 @@ class FakeSwiftConnection(object): 'offset': 20} }] metadata_json = json.dumps(metadata, sort_keys=True, indent=2) - if six.PY3: - metadata_json = metadata_json.encode('utf-8') + metadata_json = metadata_json.encode('utf-8') fake_object_body = metadata_json return (fake_object_header, fake_object_body) diff --git a/cinder/tests/unit/backup/fake_swift_client2.py b/cinder/tests/unit/backup/fake_swift_client2.py index efb1d0a..1e63fed 100644 --- a/cinder/tests/unit/backup/fake_swift_client2.py +++ b/cinder/tests/unit/backup/fake_swift_client2.py @@ -15,11 +15,11 @@ # under the License. import hashlib +from http import client as http_client import os import socket import tempfile -from six.moves import http_client from swiftclient import client as swift diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index 413bdb8..a2e49df 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -688,7 +688,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open', wraps=open) + @mock.patch('builtins.open', wraps=open) @mock.patch.object(os.path, 'isdir', return_value=False) def test_create_backup(self, mock_isdir, mock_open, mock_temporary_chown, mock_get_backup_device, mock_get_conn): @@ -738,7 +738,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch.object(os.path, 'isdir', return_value=True) def test_create_backup_set_parent_id_to_none(self, mock_isdir, mock_open, mock_chown, @@ -774,7 +774,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch.object(os.path, 'isdir', return_value=True) def test_create_backup_set_parent_id(self, mock_isdir, mock_open, mock_chown, mock_backup_device, @@ -809,7 +809,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch.object(os.path, 'isdir', return_value=True) def test_create_backup_fail_with_excep(self, mock_isdir, mock_open, mock_chown, mock_backup_device, @@ -846,7 +846,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch.object(os.path, 'isdir', return_value=True) def test_run_backup_with_dir_device_path(self, mock_isdir, mock_open, @@ -904,7 +904,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch.object(os.path, 'isdir', return_value=False) def test_create_backup_with_temp_snapshot(self, mock_isdir, mock_open, @@ -1219,7 +1219,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open', wraps=open) + @mock.patch('builtins.open', wraps=open) @mock.patch.object(os.path, 'isdir', return_value=False) @ddt.data({'os_name': 'nt', 'exp_open_mode': 'rb+'}, {'os_name': 'posix', 'exp_open_mode': 'wb'}) @@ -1269,7 +1269,7 @@ class BackupTestCase(BaseBackupTest): @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open', wraps=open) + @mock.patch('builtins.open', wraps=open) @mock.patch.object(os.path, 'isdir', return_value=False) @ddt.data({'os_name': 'nt', 'exp_open_mode': 'rb+'}, {'os_name': 'posix', 'exp_open_mode': 'wb'})