From e989b2d2ef5435db4e4147e45cc9f4643eef176f Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 4 Feb 2014 14:06:59 -0500 Subject: [PATCH] Don't use shred for volume_clear=zero We should just call copy_volume unless volume_clear='shred' is specified. Change-Id: Id5e15b000cf0d6146ec13f42ff5bb611b6f18484 --- cinder/tests/test_volume_utils.py | 9 +++++---- cinder/volume/utils.py | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cinder/tests/test_volume_utils.py b/cinder/tests/test_volume_utils.py index e92e38178..4bb1464ea 100644 --- a/cinder/tests/test_volume_utils.py +++ b/cinder/tests/test_volume_utils.py @@ -165,12 +165,13 @@ class ClearVolumeTestCase(test.TestCase): self.mox.ReplayAll() volume_utils.clear_volume(1024, "volume_path") - def test_clear_volume_zero_and_shred(self): + def test_clear_volume_zero(self): CONF.volume_clear = 'zero' CONF.volume_clear_size = 1 - clear_cmd = ['shred', '-n0', '-z', '-s1MiB', "volume_path"] - self.mox.StubOutWithMock(utils, "execute") - utils.execute(*clear_cmd, run_as_root=True) + self.mox.StubOutWithMock(volume_utils, 'copy_volume') + volume_utils.copy_volume("/dev/zero", "volume_path", 1, + CONF.volume_dd_blocksize, sync=True, + execute=utils.execute) self.mox.ReplayAll() volume_utils.clear_volume(1024, "volume_path") diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 8f57509cf..6429d5590 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -193,15 +193,15 @@ def clear_volume(volume_size, volume_path, volume_clear=None, if volume_clear_size is None: volume_clear_size = CONF.volume_clear_size + if volume_clear_size == 0: + volume_clear_size = volume_size + LOG.info(_("Performing secure delete on volume: %s") % volume_path) if volume_clear == 'zero': - if volume_clear_size == 0: - return copy_volume('/dev/zero', volume_path, volume_size, - CONF.volume_dd_blocksize, - sync=True, execute=utils.execute) - else: - clear_cmd = ['shred', '-n0', '-z', '-s%dMiB' % volume_clear_size] + return copy_volume('/dev/zero', volume_path, volume_clear_size, + CONF.volume_dd_blocksize, + sync=True, execute=utils.execute) elif volume_clear == 'shred': clear_cmd = ['shred', '-n3'] if volume_clear_size: -- 2.45.2