From 10f4e9796ddbbbbdee5d387e8101f8f952288f63 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 21:42:57 +0200 Subject: [PATCH] [PR #11925/d0f0e9d0 backport][stable-12] lvol: fix thin-pool creation with percentage size (#11930) lvol: fix thin-pool creation with percentage size (#11925) * fix(lvol): use --extents (-l) for thin-pool creation with percentage size Fixes #11923 * chore(lvol): add changelog fragment for #11925 * test(lvol): add integration tests for thin-pool creation with percentage sizes * test(lvol): use extent-aligned size for thin-pool absolute-size idempotency test * test(lvol): reduce thin-pool sizes to leave space for test_pvs.yml * test(lvol): add shrink=false to thin-pool absolute-size idempotency check * test(lvol): add shrink: false to thin volume idempotency test LVM reports thin volume size slightly above requested (metadata overhead), triggering spurious shrink attempts. Disable shrink for idempotency checks to avoid false failures. --------- (cherry picked from commit d0f0e9d00f38179e8ddc2df309df1b2d7578c8eb) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- .../11925-lvol-thinpool-percentage-size.yml | 2 + plugins/modules/lvol.py | 29 +++-- tests/integration/targets/lvol/tasks/main.yml | 2 + .../targets/lvol/tasks/test_thinpool.yml | 101 ++++++++++++++++++ 4 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/11925-lvol-thinpool-percentage-size.yml create mode 100644 tests/integration/targets/lvol/tasks/test_thinpool.yml diff --git a/changelogs/fragments/11925-lvol-thinpool-percentage-size.yml b/changelogs/fragments/11925-lvol-thinpool-percentage-size.yml new file mode 100644 index 0000000000..8963831ceb --- /dev/null +++ b/changelogs/fragments/11925-lvol-thinpool-percentage-size.yml @@ -0,0 +1,2 @@ +bugfixes: + - lvol - fix thin-pool creation when ``size`` is a percentage (https://github.com/ansible-collections/community.general/issues/11923, https://github.com/ansible-collections/community.general/pull/11925). diff --git a/plugins/modules/lvol.py b/plugins/modules/lvol.py index 22085a1ced..e7bdd5bbf8 100644 --- a/plugins/modules/lvol.py +++ b/plugins/modules/lvol.py @@ -505,15 +505,26 @@ def main(): vg=[f"{vg}/{thinpool}"], ) else: - with lvcreate("test yes size_L opts thin vg pvs") as ctx: - rc, dummy, err = ctx.run( - test=module.check_mode, - yes=use_yes, - size_L=size_value, - opts=opts, - vg=[f"{vg}/{thinpool}"], - pvs=pvs, - ) + if size_opt == "l": + with lvcreate("test yes size_l opts thin vg pvs") as ctx: + rc, dummy, err = ctx.run( + test=module.check_mode, + yes=use_yes, + size_l=size_value, + opts=opts, + vg=[f"{vg}/{thinpool}"], + pvs=pvs, + ) + else: + with lvcreate("test yes size_L opts thin vg pvs") as ctx: + rc, dummy, err = ctx.run( + test=module.check_mode, + yes=use_yes, + size_L=size_value, + opts=opts, + vg=[f"{vg}/{thinpool}"], + pvs=pvs, + ) else: if size_opt == "l": with lvcreate("test yes lv size_l opts vg pvs") as ctx: diff --git a/tests/integration/targets/lvol/tasks/main.yml b/tests/integration/targets/lvol/tasks/main.yml index c3360b8fbf..6e2d93ec06 100644 --- a/tests/integration/targets/lvol/tasks/main.yml +++ b/tests/integration/targets/lvol/tasks/main.yml @@ -18,6 +18,8 @@ block: - import_tasks: setup.yml + - import_tasks: test_thinpool.yml + - import_tasks: test_pvs.yml always: diff --git a/tests/integration/targets/lvol/tasks/test_thinpool.yml b/tests/integration/targets/lvol/tasks/test_thinpool.yml new file mode 100644 index 0000000000..3aff3d8fcc --- /dev/null +++ b/tests/integration/targets/lvol/tasks/test_thinpool.yml @@ -0,0 +1,101 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +# Regression tests for thin-pool creation with percentage-based sizes (GH-11923) + +- name: Create thin pool with percentage of VG size + community.general.lvol: + vg: testvg1 + thinpool: testthinpool1 + size: 20%VG + register: thinpool_pct_vg_create + +- name: Assert thin pool with percentage of VG created + assert: + that: + - thinpool_pct_vg_create is success + - thinpool_pct_vg_create is changed + +- name: Create thin pool with percentage of VG size - idempotency + community.general.lvol: + vg: testvg1 + thinpool: testthinpool1 + size: 20%VG + register: thinpool_pct_vg_idempotent + +- name: Assert thin pool with percentage of VG creation is idempotent + assert: + that: + - thinpool_pct_vg_idempotent is success + - thinpool_pct_vg_idempotent is not changed + +- name: Create thin pool with percentage of free space + community.general.lvol: + vg: testvg2 + thinpool: testthinpool2 + size: 20%FREE + register: thinpool_pct_free_create + +- name: Assert thin pool with percentage of free space created + assert: + that: + - thinpool_pct_free_create is success + - thinpool_pct_free_create is changed + +- name: Create thin pool with absolute size + community.general.lvol: + vg: testvg2 + thinpool: testthinpool3 + size: 4m + register: thinpool_abs_create + +- name: Assert thin pool with absolute size created + assert: + that: + - thinpool_abs_create is success + - thinpool_abs_create is changed + +- name: Create thin pool with absolute size - idempotency + community.general.lvol: + vg: testvg2 + thinpool: testthinpool3 + size: 4m + shrink: false + register: thinpool_abs_idempotent + +- name: Assert thin pool with absolute size creation is idempotent + assert: + that: + - thinpool_abs_idempotent is success + - thinpool_abs_idempotent is not changed + +- name: Create thin volume inside thin pool + community.general.lvol: + vg: testvg1 + lv: testthinvol1 + thinpool: testthinpool1 + size: 5m + register: thinvol_create + +- name: Assert thin volume created + assert: + that: + - thinvol_create is success + - thinvol_create is changed + +- name: Create thin volume inside thin pool - idempotency + community.general.lvol: + vg: testvg1 + lv: testthinvol1 + thinpool: testthinpool1 + size: 5m + shrink: false + register: thinvol_idempotent + +- name: Assert thin volume creation is idempotent + assert: + that: + - thinvol_idempotent is success + - thinvol_idempotent is not changed