]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
GlusterFS: Delete volume-<uuid>.info file when volume is deleted.
authorThang Pham <thang.g.pham@gmail.com>
Mon, 31 Mar 2014 19:22:47 +0000 (15:22 -0400)
committerThang Pham <thang.g.pham@gmail.com>
Mon, 31 Mar 2014 20:31:24 +0000 (16:31 -0400)
glusterfs creates a file named volume-<uuid>.info to hold volume
data, mapping cinder snapshot UUIDs and filenames. When the
volume and its associated snapshots are both deleted, this file
remains. This patch deletes the volume-<uuid>.info (if one exists)
when the volume is deleted.

Change-Id: Iefc8bd4768b30a75c648c4689d935daeab3afe98
Closes-Bug: #1299182

cinder/tests/test_glusterfs.py
cinder/volume/drivers/glusterfs.py

index 94dbd8b1b363d9a0dc153819853d09959548fd29..7f1f7d1e35b2ebd961cb765107b20af06b3e0bcd 100644 (file)
@@ -14,7 +14,9 @@
 #    under the License.
 """Unit tests for the GlusterFS driver module."""
 
+import contextlib
 import errno
+import mock
 import os
 import tempfile
 
@@ -745,6 +747,31 @@ class GlusterFsDriverTestCase(test.TestCase):
 
         mox.VerifyAll()
 
+    @mock.patch('os.remove')
+    @mock.patch('os.path.exists')
+    def test_delete_volume_with_info_file(self, mock_path_exists, mock_remove):
+        mock_path_exists.return_value = True
+        info_file = self.TEST_LOCAL_PATH + '.info'
+        volume = self._simple_volume()
+
+        with contextlib.nested(
+                mock.patch.object(self._driver, '_ensure_share_mounted'),
+                mock.patch.object(self._driver, 'local_path'),
+                mock.patch.object(self._driver, '_execute')
+        ) as (mock_ensure_share_mounted, mock_local_path, mock_execute):
+            mock_local_path.return_value = self.TEST_LOCAL_PATH
+
+            self._driver.delete_volume(volume)
+
+            mock_ensure_share_mounted.assert_called_once_with(
+                volume['provider_location'])
+            mock_local_path.assert_called_once_with(volume)
+            mock_execute.assert_called_once_with('rm', '-f',
+                                                 self.TEST_LOCAL_PATH,
+                                                 run_as_root=True)
+            mock_path_exists.assert_called_once_with(info_file)
+            mock_remove.assert_called_once_with(info_file)
+
     def test_create_snapshot(self):
         (mox, drv) = self._mox, self._driver
 
index d1e514d8d041bb832269944b29e9f89a7573e9c1..25000cfba63d3df7b96b2f561f8b3d260f0f0207 100644 (file)
@@ -297,6 +297,10 @@ class GlusterfsDriver(nfs.RemoteFsDriver):
 
         self._execute('rm', '-f', mounted_path, run_as_root=True)
 
+        info_path = mounted_path + '.info'
+        if os.path.exists(info_path):
+            os.remove(info_path)
+
     @utils.synchronized('glusterfs', external=False)
     def create_snapshot(self, snapshot):
         """Apply locking to the create snapshot operation."""