]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port targets test_iet_driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 15:14:54 +0000 (17:14 +0200)
committerVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 15:20:56 +0000 (17:20 +0200)
* Replace StandardError with MemoryError: StandardError was removed
  in Python 3
* Replace __builtin__ with six.moves.builtins to mock open()
* Mock the logger in test_create_iscsi_target() because the test
  injects errors in open() and the logger uses open() to format the
  traceback
* tox.ini: add cinder.tests.unit.targets.test_iet_driver to Python 3.4

Partial-Implements: blueprint cinder-python3
Change-Id: I7c83da7374ef78cc98bd6c0c5596b7a7adb70303

cinder/tests/unit/targets/test_iet_driver.py
tests-py3.txt

index 04b749e9f82027653e217f7e83d0836ef4a81995..8dfc48242410d5edfc46d8b092a89c5414f2cde8 100644 (file)
@@ -38,7 +38,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
             '        sid:844427031282176 initiator:iqn.1994-05.com.redhat:5a6894679665\n'  # noqa
             '               cid:0 ip:10.9.8.7 state:active hd:none dd:none')
         tmp_file.seek(0)
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             mock_open.return_value = contextlib.closing(tmp_file)
             self.assertEqual('1',
                              self.target._get_target(
@@ -46,8 +46,8 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
                                                     ))
 
             # Test the failure case: Failed to handle the config file
-            mock_open.side_effect = StandardError()
-            self.assertRaises(StandardError,
+            mock_open.side_effect = MemoryError()
+            self.assertRaises(MemoryError,
                               self.target._get_target,
                               '')
 
@@ -56,11 +56,12 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
     @mock.patch('cinder.utils.execute')
     @mock.patch('os.path.exists', return_value=True)
     @mock.patch('cinder.utils.temporary_chown')
-    def test_create_iscsi_target(self, mock_chown, mock_exists,
+    @mock.patch.object(iet, 'LOG')
+    def test_create_iscsi_target(self, mock_log, mock_chown, mock_exists,
                                  mock_execute, mock_get_targ):
         mock_execute.return_value = ('', '')
         tmp_file = six.StringIO()
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             mock_open.return_value = contextlib.closing(tmp_file)
             self.assertEqual(
                 0,
@@ -153,7 +154,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
             '        sid:844427031282176 initiator:iqn.1994-05.com.redhat:5a6894679665\n'  # noqa
             '               cid:0 ip:10.9.8.7 state:active hd:none dd:none')
         tmp_file.seek(0)
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             mock_open.return_value = contextlib.closing(tmp_file)
             self.assertEqual(('844427031282176', '0'),
                              self.target._find_sid_cid_for_target(
index e933f6a316be8899b3b6293e357bafaf33932538..e4b33dc67bb4ee8f1bb0eb7b1e54d5f46f198741 100644 (file)
@@ -13,6 +13,7 @@ cinder.tests.unit.scheduler.test_scheduler_options
 cinder.tests.unit.scheduler.test_volume_number_weigher
 cinder.tests.unit.targets.test_base_iscsi_driver
 cinder.tests.unit.targets.test_cxt_driver
+cinder.tests.unit.targets.test_iet_driver
 cinder.tests.unit.targets.test_iser_driver
 cinder.tests.unit.targets.test_lio_driver
 cinder.tests.unit.targets.test_scst_driver