From: Mike Perez Date: Thu, 4 Sep 2014 04:05:53 +0000 (-0700) Subject: Destroy Datera export target after detach X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=804f5de841b410c3e6a2ff30756546f2a086b112;p=openstack-build%2Fcinder-build.git Destroy Datera export target after detach Since there is only one lun associated with each target export object in the Datera backend, we will destroy the target export object after detaching the volume so they don't build up. This patch also fixes some missing values for formatted strings. Closes-Bug: #1368381 Change-Id: Id44ac4bb385ab39af50865a295938861ca977fa3 --- diff --git a/cinder/tests/volume/drivers/datera.py b/cinder/tests/volume/drivers/datera.py index 928a37cb1..2ea56fed8 100644 --- a/cinder/tests/volume/drivers/datera.py +++ b/cinder/tests/volume/drivers/datera.py @@ -146,6 +146,25 @@ class DateraVolumeTestCase(test.TestCase): self.assertRaises(exception.DateraAPIException, self.driver.create_export, ctxt, self.volume) + def test_detach_volume_success(self): + self.mock_api.return_value = {} + ctxt = context.get_admin_context() + volume = _stub_volume(status='in-use') + self.assertIsNone(self.driver.detach_volume(ctxt, volume)) + + def test_detach_volume_fails(self): + self.mock_api.side_effect = exception.DateraAPIException + ctxt = context.get_admin_context() + volume = _stub_volume(status='in-use') + self.assertRaises(exception.DateraAPIException, + self.driver.detach_volume, ctxt, volume) + + def test_detach_volume_not_found(self): + self.mock_api.side_effect = exception.NotFound + ctxt = context.get_admin_context() + volume = _stub_volume(status='in-use') + self.assertIsNone(self.driver.detach_volume(ctxt, volume)) + def test_create_snapshot_success(self): self.mock_api.return_value = { u'uuid': u'0bb34f0c-fea4-48e0-bf96-591120ac7e3c', diff --git a/cinder/volume/drivers/datera.py b/cinder/volume/drivers/datera.py index 4fb08ad2b..04dd3f7ec 100644 --- a/cinder/volume/drivers/datera.py +++ b/cinder/volume/drivers/datera.py @@ -85,9 +85,9 @@ class DateraDriver(san.SanISCSIDriver): try: self._issue_api_request('volumes', 'delete', volume['id']) except exception.NotFound: - msg = _("Tried to delete volume %s, but was not found in Datera " - "cluster. Continuing with delete.") - LOG.info(msg) + msg = _("Tried to delete volume %s, but it was not found in the " + "Datera cluster. Continuing with delete.") + LOG.info(msg, volume['id']) def _do_export(self, context, volume): """Gets the associated account, retrieves CHAP info and updates.""" @@ -114,13 +114,23 @@ class DateraDriver(san.SanISCSIDriver): def create_export(self, context, volume): return self._do_export(context, volume) + def detach_volume(self, context, volume): + try: + self._issue_api_request('volumes', 'delete', resource=volume['id'], + action='export') + except exception.NotFound: + msg = _("Tried to delete export for volume %s, but it was not " + "found in the Datera cluster. Continuing with volume " + "detach") + LOG.info(msg, volume['id']) + def delete_snapshot(self, snapshot): try: self._issue_api_request('snapshots', 'delete', snapshot['id']) except exception.NotFound: msg = _("Tried to delete snapshot %s, but was not found in Datera " "cluster. Continuing with delete.") - LOG.info(msg) + LOG.info(msg, snapshot['id']) def create_snapshot(self, snapshot): data = {