]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix various Python 3 issues
authorVictor Stinner <vstinner@redhat.com>
Fri, 2 Oct 2015 07:43:44 +0000 (09:43 +0200)
committerVictor Stinner <vstinner@redhat.com>
Fri, 2 Oct 2015 07:46:23 +0000 (09:46 +0200)
* 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
cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py
cinder/volume/drivers/netapp/eseries/utils.py
cinder/volume/drivers/srb.py

index 647cb21005d1bd84495e2101482087091c7aa362..2f3431d7370735913e998ff312826d28ef717781 100644 (file)
@@ -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)
index b2ff96d24a9357ea68e03b9117dae15a01e4a1e1..fb8ffc5ff0c8d1ef2959b49f98906a211162345a 100644 (file)
@@ -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"""
index 7e18b50837a8448fa6e5031d1c31f2a9171e01c0..2422d9779ae6c48f58d2030e960f5ac4f985bb3d 100644 (file)
@@ -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):
index cb79dd861e9e20207f098326a0f3d2f8844fe44c..e6a534b2779ee20967518ed7484d5dfbeca6a40e 100644 (file)
@@ -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):