From 06bdabcad93846f37f70fd868fdce421ef366f8c Mon Sep 17 00:00:00 2001 From: zigaSRC <65527456+zigaSRC@users.noreply.github.com> Date: Mon, 3 May 2021 21:25:52 +0200 Subject: [PATCH] lvol - bug fix - Convert units to lowercase when using LVS or VGS command (#2369) * Added lower call for units when checking lvs/vgs size * Changelog * Size roudning correction * Rounding * Changelog * Remove whitespace --- changelogs/fragments/2369-lvol_size_bug_fixes.yml | 3 +++ plugins/modules/system/lvol.py | 13 +++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/2369-lvol_size_bug_fixes.yml diff --git a/changelogs/fragments/2369-lvol_size_bug_fixes.yml b/changelogs/fragments/2369-lvol_size_bug_fixes.yml new file mode 100644 index 0000000000..fcd2f17b11 --- /dev/null +++ b/changelogs/fragments/2369-lvol_size_bug_fixes.yml @@ -0,0 +1,3 @@ +bugfixes: + - lvol - fixed size unit capitalization to match units used between different tools for comparison (https://github.com/ansible-collections/community.general/issues/2360). + - lvol - fixed rounding errors (https://github.com/ansible-collections/community.general/issues/2370). \ No newline at end of file diff --git a/plugins/modules/system/lvol.py b/plugins/modules/system/lvol.py index 8dc3fac7f5..fafa7db38a 100644 --- a/plugins/modules/system/lvol.py +++ b/plugins/modules/system/lvol.py @@ -389,7 +389,7 @@ def main(): # Get information on volume group requested vgs_cmd = module.get_bin_path("vgs", required=True) rc, current_vgs, err = module.run_command( - "%s --noheadings --nosuffix -o vg_name,size,free,vg_extent_size --units %s --separator ';' %s" % (vgs_cmd, unit, vg)) + "%s --noheadings --nosuffix -o vg_name,size,free,vg_extent_size --units %s --separator ';' %s" % (vgs_cmd, unit.lower(), vg)) if rc != 0: if state == 'absent': @@ -403,7 +403,7 @@ def main(): # Get information on logical volume requested lvs_cmd = module.get_bin_path("lvs", required=True) rc, current_lvs, err = module.run_command( - "%s -a --noheadings --nosuffix -o lv_name,size,lv_attr --units %s --separator ';' %s" % (lvs_cmd, unit, vg)) + "%s -a --noheadings --nosuffix -o lv_name,size,lv_attr --units %s --separator ';' %s" % (lvs_cmd, unit.lower(), vg)) if rc != 0: if state == 'absent': @@ -505,16 +505,13 @@ def main(): else: # size_whole == 'FREE': size_requested = size_percent * this_vg['free'] / 100 - # from LVEXTEND(8) - The resulting value is rounded upward. - # from LVREDUCE(8) - The resulting value for the substraction is rounded downward, for the absolute size it is rounded upward. if size_operator == '+': size_requested += this_lv['size'] - size_requested += this_vg['ext_size'] - (size_requested % this_vg['ext_size']) elif size_operator == '-': size_requested = this_lv['size'] - size_requested - size_requested -= (size_requested % this_vg['ext_size']) - else: - size_requested += this_vg['ext_size'] - (size_requested % this_vg['ext_size']) + + # According to latest documentation (LVM2-2.03.11) all tools round down + size_requested -= (size_requested % this_vg['ext_size']) if this_lv['size'] < size_requested: if (size_free > 0) and (size_free >= (size_requested - this_lv['size'])):