Skip to content

Commit

Permalink
Add tests for LVM -cow clearing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eharney committed Oct 30, 2013
1 parent 75bcf70 commit 2b49b36
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cinder/tests/test_volume.py
Expand Up @@ -22,6 +22,7 @@

import datetime
import os
import re
import shutil
import socket
import tempfile
Expand Down Expand Up @@ -2229,6 +2230,50 @@ def test_clear_volume_badopt(self):
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"""
Expand Down

0 comments on commit 2b49b36

Please sign in to comment.