From d50d9671deff4dcf17af28320a890788021aedd5 Mon Sep 17 00:00:00 2001 From: Tom Barron Date: Thu, 28 Aug 2014 15:59:28 -0400 Subject: [PATCH] Fix confusing exception message in NetApp iscsi driver Fix confusing exception message when no target details are returned on volume attach. Change-Id: Ib5fe15a4a6be14a20b1ae446b8b57737b50e9aeb Closes-Bug: 1366816 --- cinder/tests/test_netapp.py | 19 ++++++++++++++++++- cinder/volume/drivers/netapp/iscsi.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cinder/tests/test_netapp.py b/cinder/tests/test_netapp.py index 74ff95047c2..1bdce7619e0 100644 --- a/cinder/tests/test_netapp.py +++ b/cinder/tests/test_netapp.py @@ -22,6 +22,7 @@ import BaseHTTPServer import httplib from lxml import etree +import mock import six from cinder import exception @@ -40,7 +41,6 @@ from cinder.volume.drivers.netapp.options import netapp_provisioning_opts from cinder.volume.drivers.netapp.options import netapp_transport_opts from cinder.volume.drivers.netapp import ssc_utils - LOG = logging.getLogger("cinder.volume.driver") @@ -658,6 +658,23 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase): self.driver.create_volume(self.volume) self.driver.extend_volume(self.volume, 4) + def test_initialize_connection_no_target_details_found(self): + fake_volume = {'name': 'mock-vol'} + fake_connector = {'initiator': 'iqn.mock'} + self.driver._map_lun = mock.Mock(return_value='mocked-lun-id') + self.driver._get_iscsi_service_details = mock.Mock( + return_value='mocked-iqn') + self.driver._get_target_details = mock.Mock(return_value=[]) + expected = (_('No iscsi target details were found for LUN %s') + % fake_volume['name']) + try: + self.driver.initialize_connection(fake_volume, fake_connector) + except exception.VolumeBackendAPIException as exc: + if expected not in str(exc): + self.fail(_('Expected exception message is missing')) + else: + self.fail(_('VolumeBackendAPIException not raised')) + class NetAppDriverNegativeTestCase(test.TestCase): """Test case for NetAppDriver""" diff --git a/cinder/volume/drivers/netapp/iscsi.py b/cinder/volume/drivers/netapp/iscsi.py index 761c79d46e9..7b930100df6 100644 --- a/cinder/volume/drivers/netapp/iscsi.py +++ b/cinder/volume/drivers/netapp/iscsi.py @@ -236,7 +236,7 @@ class NetAppDirectISCSIDriver(driver.ISCSIDriver): LOG.debug(msg % msg_fmt) if not target_details_list: - msg = _('Failed to get LUN target details for the LUN %s') + msg = _('No iscsi target details were found for LUN %s') raise exception.VolumeBackendAPIException(data=msg % name) target_details = None for tgt_detail in target_details_list: