diff --git a/cinder/tests/unit/test_hpelefthand.py b/cinder/tests/unit/test_hpelefthand.py index 0262b67e4..c8b9ebaa5 100644 --- a/cinder/tests/unit/test_hpelefthand.py +++ b/cinder/tests/unit/test_hpelefthand.py @@ -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 diff --git a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py index d062da256..134485378 100644 --- a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py +++ b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py @@ -155,9 +155,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 = {} @@ -747,6 +748,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: