diff --git a/config.yaml b/config.yaml index 280bb8ed..7bc625e2 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/hooks/cinder_hooks.py b/hooks/cinder_hooks.py index 6e706257..780f0860 100755 --- a/hooks/cinder_hooks.py +++ b/hooks/cinder_hooks.py @@ -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'): diff --git a/hooks/cinder_utils.py b/hooks/cinder_utils.py index 198e945d..1a3f8a47 100644 --- a/hooks/cinder_utils.py +++ b/hooks/cinder_utils.py @@ -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 diff --git a/unit_tests/test_cinder_hooks.py b/unit_tests/test_cinder_hooks.py index 5cde693d..0a278750 100644 --- a/unit_tests/test_cinder_hooks.py +++ b/unit_tests/test_cinder_hooks.py @@ -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')