From 85c2902acd449acc90f1255c62b2b0bb488bda36 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Thu, 28 May 2020 11:30:54 -0400 Subject: [PATCH 1/3] Account for formatting when preparing to resize a volume. This collects information such as the minimum size for the file system and verifies that the required tools are present. --- library/blivet.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/blivet.py b/library/blivet.py index 56ea4699..0984006b 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -366,7 +366,15 @@ def _resize(self): except Exception: raise BlivetAnsibleError("invalid size specification for volume '%s': '%s'" % (self._volume['name'], self._volume['size'])) - if size and self._device.resizable and self._device.size != size: + if size and self._device.size != size: + try: + self._device.format.update_size_info() + except AttributeError: + pass + + if not self._device.resizable: + return + if self._device.format.resizable: self._device.format.update_size_info() From a205fe836192f03079ea40b71aff20528e58204d Mon Sep 17 00:00:00 2001 From: David Lehman Date: Thu, 28 May 2020 11:31:39 -0400 Subject: [PATCH 2/3] Deactivate formatting prior to volume resize. --- library/blivet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/blivet.py b/library/blivet.py index 0984006b..c9065b6e 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -1186,7 +1186,7 @@ def action_dict(action): result['packages'] = b.packages[:] for action in scheduled: - if action.is_destroy and action.is_format and action.format.exists and \ + if (action.is_destroy or action.is_resize) and action.is_format and action.format.exists and \ (action.format.mountable or action.format.type == "swap"): action.format.teardown() From 9a28aa2039771bd39fae2a7708a833d655da4147 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Thu, 13 Aug 2020 21:53:29 +0200 Subject: [PATCH 3/3] Add test for volume/filesystem resize Based on @yizhanglinux's code in #139. Remove a disabled resize test from tests_lvm_errors where it does not belong anymore. --- tests/tests_lvm_errors.yml | 22 ------------- tests/tests_resize.yml | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 tests/tests_resize.yml diff --git a/tests/tests_lvm_errors.yml b/tests/tests_lvm_errors.yml index 0a8ff726..d04eac4e 100644 --- a/tests/tests_lvm_errors.yml +++ b/tests/tests_lvm_errors.yml @@ -341,28 +341,6 @@ not blivet_output.changed }}" msg: "Unexpected behavior w/ existing data on specified disks" - - name: Test for correct handling of safe_mode with resize - block: - - name: Try to resize in safe mode - include_role: - name: storage - vars: - storage_pools: - - name: testpool1 - type: lvm - disks: "{{ unused_disks }}" - volumes: - - name: testvol1 - fs_type: 'ext4' - size: '2g' - - - name: Verify the output - assert: - that: "{{ not blivet_output.failed and blivet_output.changed }}" - msg: "Unexpected behavior w/ existing data on specified disks" - - when: false - - name: Test for correct handling of safe_mode with existing pool block: - name: Try to create LVM pool on disks that already belong to an existing pool diff --git a/tests/tests_resize.yml b/tests/tests_resize.yml new file mode 100644 index 00000000..b58f76fd --- /dev/null +++ b/tests/tests_resize.yml @@ -0,0 +1,63 @@ +- hosts: all + vars: + mount_location: '/opt/test1' + volume_group_size: '10g' + volume_size_before: '5g' + volume_size_after: '9g' + + tasks: + - include_role: + name: storage + + - include_tasks: get_unused_disk.yml + vars: + min_size: "{{ volume_group_size }}" + max_return: 1 + + - name: Create one LVM logical volume with "{{ volume_size_before }}" under one volume group + include_role: + name: storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks }}" + type: lvm + volumes: + - name: test1 + # resizing is currently supported only for ext2/3/4 + fs_type: 'ext4' + size: "{{ volume_size_before }}" + mount_point: "{{ mount_location }}" + + - include_tasks: verify-role-results.yml + + - name: Change volume_size to "{{ volume_size_after }}" + include_role: + name: storage + vars: + storage_pools: + - name: foo + type: lvm + disks: "{{ unused_disks }}" + volumes: + - name: test1 + fs_type: 'ext4' + size: "{{ volume_size_after }}" + mount_point: "{{ mount_location }}" + + - include_tasks: verify-role-results.yml + + - name: Clean up + include_role: + name: storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks }}" + state: absent + volumes: + - name: test1 + size: "{{ volume_size_after }}" + mount_point: "{{ mount_location }}" + + - include_tasks: verify-role-results.yml