Specialise zap_disk for lvm usage
This commit is contained in:
@@ -319,6 +319,16 @@ def configure_lvm_storage(block_devices, volume_group, overwrite=False):
|
||||
extend_lvm_volume_group(volume_group, new_device)
|
||||
|
||||
|
||||
def lvm_zap_disk(block_device):
|
||||
'''
|
||||
Clear a block device of partition table. Relies on sgdisk, which is
|
||||
installed as pat of the 'gdisk' package in Ubuntu.
|
||||
|
||||
:param block_device: str: Full path of block device to clean.
|
||||
'''
|
||||
subprocess.check_call(['sgdisk', '--zap-all', block_device])
|
||||
|
||||
|
||||
def clean_storage(block_device):
|
||||
'''Ensures a block device is clean. That is:
|
||||
- unmounted
|
||||
@@ -338,7 +348,7 @@ def clean_storage(block_device):
|
||||
deactivate_lvm_volume_group(block_device)
|
||||
remove_lvm_physical_volume(block_device)
|
||||
|
||||
zap_disk(block_device)
|
||||
lvm_zap_disk(block_device)
|
||||
|
||||
|
||||
def _parse_block_device(block_device):
|
||||
|
||||
@@ -172,29 +172,32 @@ class TestCinderUtils(CharmTestCase):
|
||||
])
|
||||
self.assertEquals(cinder_utils.restart_map(), ex_map)
|
||||
|
||||
def test_clean_storage_unmount(self):
|
||||
@patch.object(cinder_utils, 'lvm_zap_disk')
|
||||
def test_clean_storage_unmount(self, zap_disk):
|
||||
'It unmounts block device when cleaning storage'
|
||||
self.is_lvm_physical_volume.return_value = False
|
||||
self.zap_disk.return_value = True
|
||||
self.mounts.return_value = MOUNTS
|
||||
cinder_utils.clean_storage('/dev/vdb')
|
||||
self.umount.called_with('/dev/vdb', True)
|
||||
zap_disk.assert_called_with('/dev/vdb')
|
||||
|
||||
def test_clean_storage_lvm_wipe(self):
|
||||
@patch.object(cinder_utils, 'lvm_zap_disk')
|
||||
def test_clean_storage_lvm_wipe(self, zap_disk):
|
||||
'It removes traces of LVM when cleaning storage'
|
||||
self.mounts.return_value = []
|
||||
self.is_lvm_physical_volume.return_value = True
|
||||
cinder_utils.clean_storage('/dev/vdb')
|
||||
self.remove_lvm_physical_volume.assert_called_with('/dev/vdb')
|
||||
self.deactivate_lvm_volume_group.assert_called_with('/dev/vdb')
|
||||
self.zap_disk.assert_called_with('/dev/vdb')
|
||||
zap_disk.assert_called_with('/dev/vdb')
|
||||
|
||||
def test_clean_storage_zap_disk(self):
|
||||
@patch.object(cinder_utils, 'lvm_zap_disk')
|
||||
def test_clean_storage_zap_disk(self, zap_disk):
|
||||
'It removes traces of LVM when cleaning storage'
|
||||
self.mounts.return_value = []
|
||||
self.is_lvm_physical_volume.return_value = False
|
||||
cinder_utils.clean_storage('/dev/vdb')
|
||||
self.zap_disk.assert_called_with('/dev/vdb')
|
||||
zap_disk.assert_called_with('/dev/vdb')
|
||||
|
||||
def test_parse_block_device(self):
|
||||
self.assertTrue(cinder_utils._parse_block_device(None),
|
||||
|
||||
Reference in New Issue
Block a user