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
This commit is contained in:
Victor Stinner 2015-10-07 17:14:54 +02:00
parent a37618f55b
commit 7d849b5da4
2 changed files with 8 additions and 6 deletions

View 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(

View 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