From 7cb54266294145c3b625dda1a66cd8686be4ccb6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 2 Oct 2015 09:43:44 +0200 Subject: [PATCH] Fix various Python 3 issues * Drop exceptions import. Replace exceptions.OSError with OSError. The exceptions module was removed in Python 3. * Replace 8l with 8 * Replace generator.next() with next(generator) * convert_uuid_to_es_fmt(): use bytes * Replace function.func_name with function.__name__ This change helps to run tests using "testr run" instead of testtools.run. Blueprint cinder-python3 Change-Id: I36476199ef336069669c5bc6cb5c285b21d8116b --- cinder/tests/unit/backup/drivers/test_backup_posix.py | 9 ++++----- .../volume/drivers/netapp/dataontap/client/test_api.py | 4 ++-- cinder/volume/drivers/netapp/eseries/utils.py | 2 +- cinder/volume/drivers/srb.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cinder/tests/unit/backup/drivers/test_backup_posix.py b/cinder/tests/unit/backup/drivers/test_backup_posix.py index 647cb2100..2f3431d73 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_posix.py +++ b/cinder/tests/unit/backup/drivers/test_backup_posix.py @@ -17,7 +17,6 @@ Tests for Posix backup driver. """ -import exceptions import os import mock @@ -118,11 +117,11 @@ class PosixBackupDriverTestCase(test.TestCase): def test_put_container_exception(self): self.mock_object(os.path, 'exists', mock.Mock(return_value=False)) self.mock_object(os, 'makedirs', mock.Mock( - side_effect=exceptions.OSError)) + side_effect=OSError)) self.mock_object(os, 'chmod') path = os.path.join(self.driver.backup_path, FAKE_CONTAINER) - self.assertRaises(exceptions.OSError, self.driver.put_container, + self.assertRaises(OSError, self.driver.put_container, FAKE_CONTAINER) os.path.exists.assert_called_once_with(path) os.makedirs.called_once_with(path) @@ -176,8 +175,8 @@ class PosixBackupDriverTestCase(test.TestCase): def test_delete_nonexistent_object(self): self.mock_object(os, 'remove', mock.Mock( - side_effect=exceptions.OSError)) + side_effect=OSError)) - self.assertRaises(exceptions.OSError, + self.assertRaises(OSError, self.driver.delete_object, FAKE_CONTAINER, FAKE_OBJECT_NAME) diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py index b2ff96d24..fb8ffc5ff 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py @@ -299,7 +299,7 @@ class NetAppApiElementTransTests(test.TestCase): root['e1'] = 'v1' root['e2'] = 1 root['e3'] = 2.0 - root['e4'] = 8l + root['e4'] = 8 self.assertEqual(4, len(root.get_children())) self.assertEqual('v1', root.get_child_content('e1')) self.assertEqual('1', root.get_child_content('e2')) @@ -491,7 +491,7 @@ class NetAppApiInvokeTests(test.TestCase): invoke_generator = netapp_api.invoke_api(**params) self.assertEqual(netapp_api.NaElement('success').to_string(), - invoke_generator.next().to_string()) + next(invoke_generator).to_string()) def test_create_api_request(self): """"Tests creating api request""" diff --git a/cinder/volume/drivers/netapp/eseries/utils.py b/cinder/volume/drivers/netapp/eseries/utils.py index 7e18b5083..2422d9779 100644 --- a/cinder/volume/drivers/netapp/eseries/utils.py +++ b/cinder/volume/drivers/netapp/eseries/utils.py @@ -47,7 +47,7 @@ def decode_base32_to_hex(base32_string): def convert_uuid_to_es_fmt(uuid_str): """Converts uuid to e-series compatible name format.""" uuid_base32 = encode_hex_to_base32(uuid.UUID(six.text_type(uuid_str)).hex) - return uuid_base32.strip('=') + return uuid_base32.strip(b'=') def convert_es_fmt_to_uuid(es_label): diff --git a/cinder/volume/drivers/srb.py b/cinder/volume/drivers/srb.py index cb79dd861..e6a534b27 100644 --- a/cinder/volume/drivers/srb.py +++ b/cinder/volume/drivers/srb.py @@ -78,7 +78,7 @@ class retry(object): self._sleep_factor = sleep_factor def __call__(self, fun): - func_name = fun.func_name + func_name = fun.__name__ @functools.wraps(fun) def wrapped(*args, **kwargs): -- 2.45.2