diff --git a/changelogs/fragments/lvol-pct-of-origin.yml b/changelogs/fragments/lvol-pct-of-origin.yml new file mode 100644 index 0000000000..5236892897 --- /dev/null +++ b/changelogs/fragments/lvol-pct-of-origin.yml @@ -0,0 +1,2 @@ +bugfixes: + - lvol - add support for percentage of origin size specification when creating snapshot volumes (https://github.com/ansible-collections/community.general/issues/1630, https://github.com/ansible-collections/community.general/pull/7053). diff --git a/plugins/modules/lvol.py b/plugins/modules/lvol.py index 8445348a58..043dbb5928 100644 --- a/plugins/modules/lvol.py +++ b/plugins/modules/lvol.py @@ -41,13 +41,13 @@ options: description: - The size of the logical volume, according to lvcreate(8) --size, by default in megabytes or optionally with one of [bBsSkKmMgGtTpPeE] units; or - according to lvcreate(8) --extents as a percentage of [VG|PVS|FREE]; + according to lvcreate(8) --extents as a percentage of [VG|PVS|FREE|ORIGIN]; Float values must begin with a digit. - When resizing, apart from specifying an absolute size you may, according to lvextend(8)|lvreduce(8) C(--size), specify the amount to extend the logical volume with the prefix V(+) or the amount to reduce the logical volume by with prefix V(-). - Resizing using V(+) or V(-) was not supported prior to community.general 3.0.0. - - Please note that when using V(+) or V(-), the module is B(not idempotent). + - Please note that when using V(+), V(-), or percentage of FREE, the module is B(not idempotent). state: type: str description: @@ -73,7 +73,7 @@ options: snapshot: type: str description: - - The name of the snapshot volume + - The name of a snapshot volume to be configured. When creating a snapshot volume, the O(lv) parameter specifies the origin volume. pvs: type: str description: @@ -368,10 +368,10 @@ def main(): if size_percent > 100: module.fail_json(msg="Size percentage cannot be larger than 100%") size_whole = size_parts[1] - if size_whole == 'ORIGIN': - module.fail_json(msg="Snapshot Volumes are not supported") - elif size_whole not in ['VG', 'PVS', 'FREE']: - module.fail_json(msg="Specify extents as a percentage of VG|PVS|FREE") + if size_whole == 'ORIGIN' and snapshot is None: + module.fail_json(msg="Percentage of ORIGIN supported only for snapshot volumes") + elif size_whole not in ['VG', 'PVS', 'FREE', 'ORIGIN']: + module.fail_json(msg="Specify extents as a percentage of VG|PVS|FREE|ORIGIN") size_opt = 'l' size_unit = '' diff --git a/tests/integration/targets/lvg/tasks/setup.yml b/tests/integration/targets/lvg/tasks/setup.yml index 466501438b..45209c6a60 100644 --- a/tests/integration/targets/lvg/tasks/setup.yml +++ b/tests/integration/targets/lvg/tasks/setup.yml @@ -4,7 +4,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later - name: "Create files to use as a disk devices" - command: "dd if=/dev/zero of={{ remote_tmp_dir }}/img{{ item }} bs=1M count=10" + command: "dd if=/dev/zero of={{ remote_tmp_dir }}/img{{ item }} bs=1M count=36" with_sequence: 'count=4' - name: "Show next free loop device" diff --git a/tests/integration/targets/lvg/tasks/test_active_change.yml b/tests/integration/targets/lvg/tasks/test_active_change.yml index 99a2e23bd7..1b31693269 100644 --- a/tests/integration/targets/lvg/tasks/test_active_change.yml +++ b/tests/integration/targets/lvg/tasks/test_active_change.yml @@ -17,6 +17,16 @@ lv: "{{ item }}" size: 2m +- name: Create snapshot volumes of origin logical volumes + loop: + - lv1 + - lv2 + lvol: + vg: testvg + lv: "{{ item }}" + snapshot: "{{ item }}_snap" + size: 50%ORIGIN + - name: Collect all lv active status in testvg shell: vgs -olv_active --noheadings testvg | xargs -n1 register: initial_lv_status_result diff --git a/tests/integration/targets/lvg/tasks/test_pvresize.yml b/tests/integration/targets/lvg/tasks/test_pvresize.yml index f15add91cb..3f3b9dbddb 100644 --- a/tests/integration/targets/lvg/tasks/test_pvresize.yml +++ b/tests/integration/targets/lvg/tasks/test_pvresize.yml @@ -12,10 +12,10 @@ shell: vgs -v testvg -o pv_size --noheading --units b | xargs register: cmd_result -- name: Assert the testvg size is 8388608B +- name: Assert the testvg size is 33554432B assert: that: - - "'8388608B' == cmd_result.stdout" + - "'33554432B' == cmd_result.stdout" - name: Increases size in file command: "dd if=/dev/zero bs=8MiB count=1 of={{ remote_tmp_dir }}/img1 conv=notrunc oflag=append" @@ -38,10 +38,10 @@ shell: vgs -v testvg -o pv_size --noheading --units b | xargs register: cmd_result -- name: Assert the testvg size is still 8388608B +- name: Assert the testvg size is still 33554432B assert: that: - - "'8388608B' == cmd_result.stdout" + - "'33554432B' == cmd_result.stdout" - name: "Reruns lvg with pvresize:yes and check_mode:yes" lvg: @@ -60,10 +60,10 @@ shell: vgs -v testvg -o pv_size --noheading --units b | xargs register: cmd_result -- name: Assert the testvg size is still 8388608B +- name: Assert the testvg size is still 33554432B assert: that: - - "'8388608B' == cmd_result.stdout" + - "'33554432B' == cmd_result.stdout" - name: "Reruns lvg with pvresize:yes" lvg: @@ -75,7 +75,7 @@ shell: vgs -v testvg -o pv_size --noheading --units b | xargs register: cmd_result -- name: Assert the testvg size is now 16777216B +- name: Assert the testvg size is now 41943040B assert: that: - - "'16777216B' == cmd_result.stdout" + - "'41943040B' == cmd_result.stdout"