LeftHand Fix terminate_connection when failed over

Terminate connection will fail when a detach is called on a failed
over volume. This patch allows terminate_connection to succeed in
order to allow reattachments to secondary arrays.

Change-Id: I9057f1c5d6e5716a6283c3b08ddad7bfe4904234
Closes-Bug: #1580693
(cherry picked from commit 6ab5e5234b)
This commit is contained in:
Alex O'Rourke 2016-05-24 14:57:27 -07:00 committed by Kushal Wathore
parent 215d14220c
commit 22888c01ea
2 changed files with 40 additions and 1 deletions

View File

@ -617,6 +617,28 @@ class TestHPELeftHandISCSIDriver(HPELeftHandBaseDriver, test.TestCase):
self.volume,
self.connector)
def test_terminate_connection_from_primary_when_failed_over(self):
# setup drive with default configuration
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
mock_client.getServerByName.side_effect = hpeexceptions.HTTPNotFound(
"The host does not exist.")
with mock.patch.object(hpe_lefthand_iscsi.HPELeftHandISCSIDriver,
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
self.driver._active_backend_id = 'some_id'
# execute terminate_connection
self.driver.terminate_connection(self.volume, self.connector)
# When the volume is still attached to the primary array after a
# fail-over, there should be no call to delete the server.
# We can assert this method is not called to make sure
# the proper exceptions are being raised.
self.assertEqual(0, mock_client.removeServerAccess.call_count)
def test_terminate_connection_multiple_volumes_on_server(self):
# setup drive with default configuration

View File

@ -152,9 +152,10 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
2.0.6 - Update replication to version 2.1
2.0.7 - Fixed bug #1554746, Create clone volume with new size.
2.0.8 - Add defaults for creating a replication client, bug #1556331
2.0.9 - Fix terminate connection on failover
"""
VERSION = "2.0.8"
VERSION = "2.0.9"
device_stats = {}
@ -744,6 +745,22 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
if removeServer:
client.deleteServer(server_info['id'])
except hpeexceptions.HTTPNotFound as ex:
# If a host is failed-over, we want to allow the detach to
# to 'succeed' when it cannot find the host. We can simply
# return out of the terminate connection in order for things
# to be updated correctly.
if self._active_backend_id:
LOG.warning(_LW("Because the host is currently in a "
"failed-over state, the volume will not "
"be properly detached from the primary "
"array. The detach will be considered a "
"success as far as Cinder is concerned. "
"The volume can now be attached to the "
"secondary target."))
return
else:
raise exception.VolumeBackendAPIException(ex)
except Exception as ex:
raise exception.VolumeBackendAPIException(ex)
finally: