From d0262065921cb3015619bdce8ca1cae596cde9b2 Mon Sep 17 00:00:00 2001 From: Thang Pham Date: Mon, 31 Mar 2014 15:22:47 -0400 Subject: [PATCH] GlusterFS: Delete volume-.info file when volume is deleted. glusterfs creates a file named volume-.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-.info (if one exists) when the volume is deleted. Change-Id: Iefc8bd4768b30a75c648c4689d935daeab3afe98 Closes-Bug: #1299182 (cherry picked from commit bf006ecb4a52db6300aa0fe1abe7df621e9f6174) --- cinder/tests/test_glusterfs.py | 27 +++++++++++++++++++++++++++ cinder/volume/drivers/glusterfs.py | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/cinder/tests/test_glusterfs.py b/cinder/tests/test_glusterfs.py index 94dbd8b1b36..7f1f7d1e35b 100644 --- a/cinder/tests/test_glusterfs.py +++ b/cinder/tests/test_glusterfs.py @@ -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 diff --git a/cinder/volume/drivers/glusterfs.py b/cinder/volume/drivers/glusterfs.py index d1e514d8d04..25000cfba63 100644 --- a/cinder/volume/drivers/glusterfs.py +++ b/cinder/volume/drivers/glusterfs.py @@ -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."""