Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvol: Fix pct of origin #7053

Merged
merged 4 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/lvol-pct-of-origin.yml
Original file line number Diff line number Diff line change
@@ -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).
14 changes: 7 additions & 7 deletions plugins/modules/lvol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
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:
Expand All @@ -73,7 +73,7 @@
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:
Expand Down Expand Up @@ -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 = ''

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/lvg/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/targets/lvg/tasks/test_active_change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/targets/lvg/tasks/test_pvresize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"