]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Destroy Datera export target after detach
authorMike Perez <thingee@gmail.com>
Thu, 4 Sep 2014 04:05:53 +0000 (21:05 -0700)
committerMike Perez <thingee@gmail.com>
Thu, 11 Sep 2014 19:04:25 +0000 (12:04 -0700)
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

cinder/tests/volume/drivers/datera.py
cinder/volume/drivers/datera.py

index 928a37cb1b70782bdc13290ff0e28e28d7a4770d..2ea56fed89b19016740538f4e15f3af02a282758 100644 (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',
index 4fb08ad2b7c71b72f769be4ceac2d1c5c438663d..04dd3f7ec21f30519f0906abcab19f952424d60f 100644 (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 = {