From 23e6e7db8501f628b2d7161c86d4cb578966a790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Knecht?= Date: Mon, 7 Dec 2020 18:12:04 +0100 Subject: [PATCH] lvol: Fix idempotency when size uses %VG or %PVS (#72569) Change the behavior when using %VG or %PVS to make the `size_requested` an even modulus of the VG's physical extents by rounding down. This makes the usage of %VG or %PVS idempotent when the calculated `size_requested` does not end on a physical extent boundary. Co-authored-by: Felix Fontein Co-authored-by: JuddTracy-DAS <38507478+JuddTracy-DAS@users.noreply.github.com> --- changelogs/fragments/72569-lvol_percentage_fix.yml | 2 ++ lib/ansible/modules/system/lvol.py | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 changelogs/fragments/72569-lvol_percentage_fix.yml diff --git a/changelogs/fragments/72569-lvol_percentage_fix.yml b/changelogs/fragments/72569-lvol_percentage_fix.yml new file mode 100644 index 00000000000..aaf98454ed4 --- /dev/null +++ b/changelogs/fragments/72569-lvol_percentage_fix.yml @@ -0,0 +1,2 @@ +minor_changes: + - lvol - fix idempotency issue when using lvol with ``%VG`` or ``%PVS`` size options and VG is fully allocated (https://github.com/ansible-collections/community.general/pull/229). diff --git a/lib/ansible/modules/system/lvol.py b/lib/ansible/modules/system/lvol.py index e16ad54783d..9bc4cb87680 100644 --- a/lib/ansible/modules/system/lvol.py +++ b/lib/ansible/modules/system/lvol.py @@ -477,6 +477,10 @@ def main(): size_requested = size_percent * this_vg['size'] / 100 else: # size_whole == 'FREE': size_requested = size_percent * this_vg['free'] / 100 + + # Round down to the next lowest whole physical extent + size_requested -= (size_requested % this_vg['ext_size']) + if '+' in size: size_requested += this_lv['size'] if this_lv['size'] < size_requested: