self.stubs.Set(self.volume.driver, '_volume_not_present',
lambda x: False)
self.stubs.Set(self.volume.driver, '_delete_volume',
- lambda x, y: False)
+ lambda x: False)
# Want DriverTestCase._fake_execute to return 'o' so that
# volume.driver.delete_volume() raises the VolumeIsBusy exception.
self.output = 'o'
self.assertEquals(bs, '1M')
self.assertEquals(count, 1024)
+ def test_clear_volume(self):
+ configuration = conf.Configuration(fake_opt, 'fake_group')
+ configuration.volume_clear = 'zero'
+ configuration.volume_clear_size = 0
+ lvm_driver = lvm.LVMVolumeDriver(configuration=configuration)
+ self.stubs.Set(lvm_driver, '_copy_volume', lambda *a, **kw: True)
+
+ fake_volume = {'name': 'test1',
+ 'volume_name': 'test1',
+ 'id': 'test1'}
+
+ # Test volume has 'size' field
+ volume = dict(fake_volume, size='123')
+ self.assertEquals(True, lvm_driver.clear_volume(volume))
+
+ # Test volume has 'volume_size' field
+ volume = dict(fake_volume, volume_size='123')
+ self.assertEquals(True, lvm_driver.clear_volume(volume))
+
+ # Test volume without 'size' field and 'volume_size' field
+ volume = dict(fake_volume)
+ self.assertEquals(None, lvm_driver.clear_volume(volume))
+
class ISCSITestCase(DriverTestCase):
"""Test Case for ISCSIDriver"""
return True
return False
- def _delete_volume(self, volume, size_in_g):
+ def _delete_volume(self, volume):
"""Deletes a logical volume."""
# zero out old volumes to prevent data leaking between users
# TODO(ja): reclaiming space should be done lazy and low priority
if (out[0] == 'o') or (out[0] == 'O'):
raise exception.VolumeIsBusy(volume_name=volume['name'])
- self._delete_volume(volume, volume['size'])
+ self._delete_volume(volume)
def clear_volume(self, volume):
"""unprovision old volumes to prevent data leaking between users."""
vol_path = self.local_path(volume)
- size_in_g = volume.get('size')
- size_in_m = self.configuration.volume_clear_size
-
- if not size_in_g:
+ size_in_g = volume.get('size', volume.get('volume_size', None))
+ if size_in_g is None:
LOG.warning(_("Size for volume: %s not found, "
- "skipping secure delete.") % volume['name'])
+ "skipping secure delete.") % volume['id'])
return
+ size_in_m = self.configuration.volume_clear_size
if self.configuration.volume_clear == 'none':
return
# TODO(yamahata): zeroing out the whole snapshot triggers COW.
# it's quite slow.
- self._delete_volume(snapshot, snapshot['volume_size'])
+ self._delete_volume(snapshot)
def local_path(self, volume):
# NOTE(vish): stops deprecation warning