From 2b49b3670aa2dbc55f777f875dbdb80788ca696e Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 29 Oct 2013 16:39:45 -0400 Subject: [PATCH] Add tests for LVM -cow clearing Ensure that volume_clear for Thick LVM snapshot deletion references the -cow device, and that it uses the LV instead of the -cow device for ThinLVM. These tests were written for a change to stable/grizzly -- but are applicable for general use here as well. Related-Bug: #1245529 Change-Id: I380ad7832d558d9aa73a701cbf3acc35229e70ab --- cinder/tests/test_volume.py | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 6c6d0a7c2..86cff8bc5 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -22,6 +22,7 @@ Tests for Volume Code. import datetime import os +import re import shutil import socket import tempfile @@ -2229,6 +2230,50 @@ class LVMVolumeDriverTestCase(DriverTestCase): lvm_driver.clear_volume, volume) + def test_clear_volume_thinlvm_snap(self): + configuration = conf.Configuration(fake_opt, 'fake_group') + configuration.volume_clear = 'zero' + configuration.volume_clear_size = 0 + configuration.lvm_type = 'thin' + lvm_driver = lvm.LVMISCSIDriver(configuration=configuration) + + # Ensures that copy_volume is not called for ThinLVM + self.mox.StubOutWithMock(volutils, 'copy_volume') + self.mox.StubOutWithMock(lvm_driver, '_execute') + + uuid = '00000000-0000-0000-0000-c3aa7ee01536' + + fake_snapshot = {'name': 'volume-' + uuid, + 'id': uuid, + 'size': 123} + + lvm_driver.clear_volume(fake_snapshot, is_snapshot=True) + + def test_clear_volume_lvm_snap(self): + self.stubs.Set(os.path, 'exists', lambda x: True) + configuration = conf.Configuration(fake_opt, 'fake_group') + configuration.volume_clear = 'zero' + configuration.volume_clear_size = 0 + lvm_driver = lvm.LVMISCSIDriver(configuration=configuration) + + uuid = '00000000-0000-0000-0000-90ed32cdeed3' + name = 'snapshot-' + uuid + mangle_name = '_' + re.sub(r'-', r'--', name) + + def fake_copy_volume(srcstr, deststr, size, **kwargs): + self.assertEqual(deststr, + '/dev/mapper/cinder--volumes-%s-cow' % + mangle_name) + return True + + self.stubs.Set(volutils, 'copy_volume', fake_copy_volume) + + fake_snapshot = {'name': 'snapshot-' + uuid, + 'id': uuid, + 'size': 123} + + lvm_driver.clear_volume(fake_snapshot, is_snapshot=True) + class ISCSITestCase(DriverTestCase): """Test Case for ISCSIDriver""" -- 2.45.2