From: Victor Stinner Date: Wed, 7 Oct 2015 15:14:54 +0000 (+0200) Subject: Port targets test_iet_driver to Python 3 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7d849b5da48a4edb29db288c041b945cc34f667a;p=openstack-build%2Fcinder-build.git Port targets test_iet_driver to Python 3 * 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 --- diff --git a/cinder/tests/unit/targets/test_iet_driver.py b/cinder/tests/unit/targets/test_iet_driver.py index 04b749e9f..8dfc48242 100644 --- a/cinder/tests/unit/targets/test_iet_driver.py +++ b/cinder/tests/unit/targets/test_iet_driver.py @@ -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( diff --git a/tests-py3.txt b/tests-py3.txt index e933f6a31..e4b33dc67 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -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