From 4fe87879ff0108b6975b26934771da8d043d431e Mon Sep 17 00:00:00 2001 From: JuddTracy-DAS <38507478+JuddTracy-DAS@users.noreply.github.com> Date: Mon, 9 Nov 2020 02:39:34 -0500 Subject: [PATCH] Fix idempotent issue when using lvol with %VG or %PVS size options and VG is fully allocated (#229) * Fix rounding issues with percentages Changed the behavior when using %VG or %PVS to make the size_requested an even modulus with the VGs physical extents by rounding down. This makes the usage of %VG or $PVE idempotent when the calculated size_requested does not end on a physical extent boundary. * Added ansible changelog fragment. * Forgot the module in the changelog fragment. * Added URL to the PR to the changelog fragment. * Update changelogs/fragments/229_lvol_percentage_fix.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- changelogs/fragments/229_lvol_percentage_fix.yml | 2 ++ plugins/modules/system/lvol.py | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 changelogs/fragments/229_lvol_percentage_fix.yml diff --git a/changelogs/fragments/229_lvol_percentage_fix.yml b/changelogs/fragments/229_lvol_percentage_fix.yml new file mode 100644 index 0000000000..aaf98454ed --- /dev/null +++ b/changelogs/fragments/229_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/plugins/modules/system/lvol.py b/plugins/modules/system/lvol.py index 4f67fe0f77..fa50007ebf 100644 --- a/plugins/modules/system/lvol.py +++ b/plugins/modules/system/lvol.py @@ -473,6 +473,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: