]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add tests for LVM -cow clearing
authorEric Harney <eharney@redhat.com>
Tue, 29 Oct 2013 20:39:45 +0000 (16:39 -0400)
committerEric Harney <eharney@redhat.com>
Wed, 30 Oct 2013 14:42:00 +0000 (10:42 -0400)
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

index 6c6d0a7c2ccfc608054dddb813aedbbbcf6e3f89..86cff8bc5f82754dd926a23804bd2dd693a61986 100644 (file)
@@ -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"""