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
This commit is contained in:
Mike Perez 2014-09-03 21:05:53 -07:00
parent 69b4cfd09c
commit 804f5de841
2 changed files with 33 additions and 4 deletions

View File

@ -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',

View File

@ -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 = {