]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Raise correct exception if deleting of LIO iSCSI target is failed
authorMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Wed, 14 Jan 2015 17:40:51 +0000 (12:40 -0500)
committerMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Fri, 23 Jan 2015 22:44:24 +0000 (17:44 -0500)
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
cinder/tests/targets/test_lio_driver.py
cinder/volume/targets/lio.py

index a82b34ed10bfdc78ad52494555939ae8afc29f06..2e2f852ab76f28c5c0efce2bd1bf675303597b23 100644 (file)
@@ -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!")
index 837c4fd79832e14912102c9fc834926f5766c805..818ce7e5604696f18b76b2adb681e80f8c166ca9 100644 (file)
@@ -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)
index ebe1932645d37194ddcba3b070bb1f91c3da6d16..b99ccda16f961dcbece9596a73068df5e79aab67 100644 (file)
@@ -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'])