Merge "Extend the cinder lvm thin pool with new devices"

This commit is contained in:
Zuul 2017-12-11 10:33:34 +00:00 committed by Gerrit Code Review
commit 174c8ea758
2 changed files with 24 additions and 3 deletions

View File

@ -80,9 +80,11 @@ from charmhelpers.contrib.storage.linux.lvm import (
create_lvm_physical_volume,
create_lvm_volume_group,
deactivate_lvm_volume_group,
extend_logical_volume_by_device,
is_lvm_physical_volume,
list_lvm_volume_group,
list_thin_logical_volume_pools,
remove_lvm_physical_volume,
list_lvm_volume_group
)
from charmhelpers.contrib.storage.linux.loopback import (
@ -565,7 +567,19 @@ def configure_lvm_storage(block_devices, volume_group, overwrite=False,
# Extend the volume group as required
for new_device in new_devices:
extend_lvm_volume_group(volume_group, new_device)
thin_pools = list_thin_logical_volume_pools(path_mode=True)
if len(thin_pools) == 0:
juju_log("No thin pools found")
elif len(thin_pools) == 1:
juju_log("Thin pool {} found, extending with {}".format(
thin_pools[0],
new_device))
extend_logical_volume_by_device(thin_pools[0], new_device)
else:
juju_log("Multiple thin pools ({}) found, "
"skipping auto extending with {}".format(
','.join(thin_pools),
new_device))
log_lvm_info()

View File

@ -446,12 +446,17 @@ class TestCinderUtils(CharmTestCase):
@patch.object(cinder_utils, 'clean_storage')
@patch.object(cinder_utils, 'reduce_lvm_volume_group_missing')
@patch.object(cinder_utils, 'extend_lvm_volume_group')
def test_configure_lvm_storage_unused_dev(self, extend_lvm, reduce_lvm,
@patch.object(cinder_utils, 'list_thin_logical_volume_pools')
@patch.object(cinder_utils, 'extend_logical_volume_by_device')
def test_configure_lvm_storage_unused_dev(self, extend_lv_by_dev,
list_thin_pools,
extend_lvm, reduce_lvm,
clean_storage, has_part):
devices = ['/dev/fakevbd', '/dev/fakevdc']
self.is_lvm_physical_volume.return_value = False
has_part.return_value = False
self.ensure_loopback_device.side_effect = lambda x, y: x
list_thin_pools.return_value = ['vg/thinpool']
cinder_utils.configure_lvm_storage(devices, 'test', False, True)
clean_storage.assert_has_calls(
[call('/dev/fakevbd'),
@ -464,6 +469,8 @@ class TestCinderUtils(CharmTestCase):
self.create_lvm_volume_group.assert_called_with('test', '/dev/fakevbd')
reduce_lvm.assert_called_with('test')
extend_lvm.assert_called_with('test', '/dev/fakevdc')
extend_lv_by_dev.assert_called_once_with('vg/thinpool',
'/dev/fakevdc')
@patch('cinder_utils.log_lvm_info', Mock())
@patch.object(cinder_utils, 'has_partition_table')