Add remove-missing-force config option.

This commit is contained in:
Jason Hobbs 2015-07-21 14:28:23 -05:00
parent e9404f6d75
commit 50368a21f0
4 changed files with 30 additions and 5 deletions

View File

@ -101,6 +101,13 @@ options:
description: |
If True, charm will attempt to remove missing physical volumes from
volume group, if logical volumes are not allocated on them.
remove-missing-force:
default: False
type: boolean
description: |
If True, charm will attempt to remove missing physical volumes from
volume group, even when logical volumes are allocated on them. The
'remove-missing' option must also be set to True.
database-user:
default: cinder
type: string

View File

@ -129,7 +129,8 @@ def config_changed():
configure_lvm_storage(block_devices,
conf['volume-group'],
conf['overwrite'] in ['true', 'True', True],
conf['remove-missing'])
conf['remove-missing'],
conf['remove-missing-force'])
if git_install_requested():
if config_value_changed('openstack-origin-git'):

View File

@ -343,6 +343,17 @@ def reduce_lvm_volume_group_missing(volume_group):
subprocess.check_call(['vgreduce', '--removemissing', volume_group])
def force_reduce_lvm_volume_group_missing(volume_group):
'''
Remove all missing physical volumes from the volume group, even if
logical volumes are allocated on them.
:param volume_group: str: Name of volume group to reduce.
'''
command = ['vgreduce', '--removemissing', '--force', volume_group]
subprocess.check_call(command)
def extend_lvm_volume_group(volume_group, block_device):
'''
Extend an LVM volume group onto a given block device.
@ -362,7 +373,7 @@ def log_lvm_info():
def configure_lvm_storage(block_devices, volume_group, overwrite=False,
remove_missing=False):
remove_missing=False, remove_missing_force=False):
''' Configure LVM storage on the list of block devices provided
:param block_devices: list: List of whitelisted block devices to detect
@ -371,6 +382,9 @@ def configure_lvm_storage(block_devices, volume_group, overwrite=False,
not already in-use
:param remove_missing: bool: Remove missing physical volumes from volume
group if logical volume not allocated on them
:param remove_missing_force: bool: Remove missing physical volumes from
volume group even if logical volumes are allocated
on them. 'remove_missing' must also be True.
'''
log_lvm_info()
devices = []
@ -413,7 +427,10 @@ def configure_lvm_storage(block_devices, volume_group, overwrite=False,
# Remove missing physical volumes from volume group
if remove_missing:
reduce_lvm_volume_group_missing(volume_group)
if remove_missing_force:
force_reduce_lvm_volume_group_missing(volume_group)
else:
reduce_lvm_volume_group_missing(volume_group)
if len(new_devices) > 0:
# Extend the volume group as required

View File

@ -156,7 +156,7 @@ class TestChangedHooks(CharmTestCase):
self.assertTrue(conf_https.called)
self.configure_lvm_storage.assert_called_with(['sdb'],
'cinder-volumes',
False, False)
False, False, False)
@patch.object(hooks, 'configure_https')
@patch.object(hooks, 'git_install_requested')
@ -174,7 +174,7 @@ class TestChangedHooks(CharmTestCase):
self.configure_lvm_storage.assert_called_with(
['sdb', '/dev/sdc', 'sde'],
'cinder-new',
True, True)
True, True, False)
@patch.object(hooks, 'configure_https')
@patch.object(hooks, 'git_install_requested')