From 40e7f19a67070af762743b883eeb49e3aca0c379 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanino Date: Wed, 14 Jan 2015 12:40:51 -0500 Subject: [PATCH] Raise correct exception if deleting of LIO iSCSI target is failed When using LVM driver and LIO target, terminate_connection in LIO target raises ISCSITargetAttachFailed if deleting of iSCSI target is failed. This should raise ISCSITargetDetachFailed. Closes-Bug: #1414207 Change-Id: I98060d5a0bcd720df15434305ab8d3e31bdb1a43 --- cinder/exception.py | 4 ++++ cinder/tests/targets/test_lio_driver.py | 24 ++++++++++++++++++++++++ cinder/volume/targets/lio.py | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cinder/exception.py b/cinder/exception.py index a82b34ed1..2e2f852ab 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -917,6 +917,10 @@ class ISCSITargetAttachFailed(CinderException): message = _("Failed to attach iSCSI target for volume %(volume_id)s.") +class ISCSITargetDetachFailed(CinderException): + message = _("Failed to detach iSCSI target for volume %(volume_id)s.") + + # X-IO driver exception. class XIODriverException(VolumeDriverException): message = _("X-IO Volume Driver exception!") diff --git a/cinder/tests/targets/test_lio_driver.py b/cinder/tests/targets/test_lio_driver.py index 837c4fd79..818ce7e56 100644 --- a/cinder/tests/targets/test_lio_driver.py +++ b/cinder/tests/targets/test_lio_driver.py @@ -91,3 +91,27 @@ class TestLioAdmDriver(test_tgt.TestTgtAdmDriver): 'iqn.2010-10.org.openstack:testvol', 1, 0, self.fake_volumes_dir, 'IncomingUser foo bar', check_exit_code=False) + + @mock.patch.object(utils, 'execute') + def test_terminate_connection(self, _mock_execute): + + connector = {'initiator': 'fake_init'} + self.target.terminate_connection(self.testvol_1, + connector) + _mock_execute.assert_called_once_with( + 'cinder-rtstool', 'delete-initiator', + 'iqn.2010-10.org.openstack:' + 'volume-ed2c2222-5fc0-11e4-aa15-123b93f75cba', + connector['initiator'], + run_as_root=True) + + @mock.patch.object(utils, 'execute') + def test_terminate_connection_fail(self, _mock_execute): + + _mock_execute.side_effect = \ + exception.ISCSITargetDetachFailed(self.testvol_1['id']) + connector = {'initiator': 'fake_init'} + self.assertRaises(exception.ISCSITargetDetachFailed, + self.target.terminate_connection, + self.testvol_1, + connector) diff --git a/cinder/volume/targets/lio.py b/cinder/volume/targets/lio.py index ebe193264..b99ccda16 100644 --- a/cinder/volume/targets/lio.py +++ b/cinder/volume/targets/lio.py @@ -195,4 +195,4 @@ class LioAdm(TgtAdm): except putils.ProcessExecutionError: LOG.error(_LE("Failed to delete initiator iqn %s to target.") % connector['initiator']) - raise exception.ISCSITargetAttachFailed(volume_id=volume['id']) + raise exception.ISCSITargetDetachFailed(volume_id=volume['id']) -- 2.45.2