[PR #11888/5b409fac backport][stable-12] filesystem - migrate LVM.get_fs_size() to use CmdRunner (#11889)

filesystem - migrate LVM.get_fs_size() to use CmdRunner (#11888)

* filesystem - migrate LVM.get_fs_size() to use CmdRunner



* filesystem - add changelog fragment for #11888



---------


(cherry picked from commit 5b409facbe)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
patchback[bot]
2026-04-20 09:35:55 +02:00
committed by GitHub
parent d99b778fa1
commit 03da9164d1
2 changed files with 10 additions and 6 deletions

View File

@@ -0,0 +1,2 @@
minor_changes:
- filesystem - migrate ``LVM.get_fs_size()`` to use ``CmdRunner``, ensuring locale-independent output parsing (https://github.com/ansible-collections/community.general/pull/11888).

View File

@@ -154,6 +154,7 @@ import stat
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils._lvm import pvs_runner
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
@@ -569,14 +570,15 @@ class LVM(Filesystem):
CHANGE_UUID_OPTION = "-u"
CHANGE_UUID_OPTION_HAS_ARG = False
def __init__(self, module):
super().__init__(module)
self._pvs = pvs_runner(module)
def get_fs_size(self, dev):
"""Get and return PV size, in bytes."""
cmd = self.module.get_bin_path(self.INFO, required=True)
dummy, size, dummy = self.module.run_command(
[cmd, "--noheadings", "-o", "pv_size", "--units", "b", "--nosuffix", str(dev)], check_rc=True
)
pv_size = int(size)
return pv_size
with self._pvs("noheadings nosuffix units fields devices") as ctx:
dummy, size, dummy = ctx.run(units="b", fields="pv_size", devices=[str(dev)])
return int(size.strip())
class Swap(Filesystem):