def test_ensure_lun_available(self, mock_get_iscsi_target_sessions, mock_get_iscsi_device_from_session): expected_try_count = 5 mock_get_iscsi_target_sessions.return_value = [ mock.Mock(SessionId=mock.sentinel.session_id)] fake_exc = exceptions.ISCSIInitiatorAPIException( message='fake_message', error_code=1, func_name='fake_func') dev_num_side_eff = [None, -1, fake_exc, mock.sentinel.dev_num] fake_device = mock.Mock() type(fake_device.StorageDeviceNumber).DeviceNumber = ( mock.PropertyMock(side_effect=dev_num_side_eff)) mock_get_dev_side_eff = [None] + [fake_device] * 4 mock_get_iscsi_device_from_session.side_effect = mock_get_dev_side_eff self._initiator.ensure_lun_available( mock.sentinel.target_iqn, mock.sentinel.target_lun, rescan_attempts=6) mock_get_iscsi_target_sessions.assert_has_calls( [mock.call(mock.sentinel.target_iqn)] * expected_try_count) mock_get_iscsi_device_from_session.assert_has_calls( [mock.call(mock.sentinel.session_id, mock.sentinel.target_lun)] * 4) self.assertEqual( 4, self._initiator._diskutils.rescan_disks.call_count)
def test_ensure_lun_available(self, mock_sleep, mock_get_iscsi_target_sessions, mock_get_iscsi_device_from_session, rescan_disks=False, retry_interval=0): retry_count = 6 mock_get_iscsi_target_sessions.return_value = [ mock.Mock(SessionId=mock.sentinel.session_id) ] fake_exc = exceptions.ISCSIInitiatorAPIException( message='fake_message', error_code=1, func_name='fake_func') dev_num_side_eff = [None, -1] + [mock.sentinel.dev_num] * 3 dev_path_side_eff = ([mock.sentinel.dev_path] * 2 + [None] + [mock.sentinel.dev_path] * 2) fake_device = mock.Mock() type( fake_device.StorageDeviceNumber).DeviceNumber = (mock.PropertyMock( side_effect=dev_num_side_eff)) type(fake_device).LegacyName = (mock.PropertyMock( side_effect=dev_path_side_eff)) mock_get_dev_side_eff = [None, fake_exc] + [fake_device] * 5 mock_get_iscsi_device_from_session.side_effect = mock_get_dev_side_eff self._diskutils.is_mpio_disk.side_effect = [False, True] dev_num, dev_path = self._initiator.ensure_lun_available( mock.sentinel.target_iqn, mock.sentinel.target_lun, rescan_attempts=retry_count, retry_interval=retry_interval, rescan_disks=rescan_disks, ensure_mpio_claimed=True) self.assertEqual(mock.sentinel.dev_num, dev_num) self.assertEqual(mock.sentinel.dev_path, dev_path) mock_get_iscsi_target_sessions.assert_has_calls( [mock.call(mock.sentinel.target_iqn)] * (retry_count + 1)) mock_get_iscsi_device_from_session.assert_has_calls( [mock.call(mock.sentinel.session_id, mock.sentinel.target_lun)] * retry_count) self._diskutils.is_mpio_disk.assert_has_calls( [mock.call(mock.sentinel.dev_num)] * 2) expected_rescan_count = retry_count if rescan_disks else 0 self.assertEqual(expected_rescan_count, self._diskutils.rescan_disks.call_count) if retry_interval: mock_sleep.assert_has_calls([mock.call(retry_interval)] * retry_count) else: self.assertFalse(mock_sleep.called)
def test_get_iscsi_initiator_exception(self, mock_get_fqdn): fake_fqdn = 'fakehost.FAKE-DOMAIN.com' fake_exc = exceptions.ISCSIInitiatorAPIException( message='fake_message', error_code=1, func_name='fake_func') self._mock_run.side_effect = fake_exc mock_get_fqdn.return_value = fake_fqdn resulted_iqn = self._initiator.get_iscsi_initiator() expected_iqn = "%s:%s" % (self._initiator._MS_IQN_PREFIX, fake_fqdn.lower()) self.assertEqual(expected_iqn, resulted_iqn)