filesystem: use LANG=C when cmd output is parsed

This commit is contained in:
Pierre-Louis Bonicoli 2018-06-22 01:29:19 +02:00 committed by Michael Scherer
parent ff68b197e2
commit 93a4269957

View file

@ -110,6 +110,8 @@ class Filesystem(object):
MKFS = None
MKFS_FORCE_FLAGS = ''
LANG_ENV = {'LANG': 'C', 'LC_ALL': 'C', 'LC_MESSAGES': 'C'}
def __init__(self, module):
self.module = module
@ -161,7 +163,7 @@ class Ext(Filesystem):
def get_fs_size(self, dev):
cmd = self.module.get_bin_path('tune2fs', required=True)
# Get Block count and Block size
_, size, _ = self.module.run_command([cmd, '-l', str(dev)], check_rc=True)
_, size, _ = self.module.run_command([cmd, '-l', str(dev)], check_rc=True, environ_update=self.LANG_ENV)
for line in size.splitlines():
if 'Block count:' in line:
block_count = int(line.split(':')[1].strip())
@ -189,7 +191,7 @@ class XFS(Filesystem):
def get_fs_size(self, dev):
cmd = self.module.get_bin_path('xfs_growfs', required=True)
_, size, _ = self.module.run_command([cmd, '-n', str(dev)], check_rc=True)
_, size, _ = self.module.run_command([cmd, '-n', str(dev)], check_rc=True, environ_update=self.LANG_ENV)
for line in size.splitlines():
col = line.split('=')
if col[0].strip() == 'data':
@ -242,7 +244,7 @@ class F2fs(Filesystem):
def MKFS_FORCE_FLAGS(self):
mkfs = self.module.get_bin_path(self.MKFS, required=True)
cmd = "%s %s" % (mkfs, os.devnull)
_, out, _ = self.module.run_command(cmd, check_rc=False)
_, out, _ = self.module.run_command(cmd, check_rc=False, environ_update=self.LANG_ENV)
# Looking for " F2FS-tools: mkfs.f2fs Ver: 1.10.0 (2018-01-30)"
# mkfs.f2fs displays version since v1.2.0
match = re.search(r"F2FS-tools: mkfs.f2fs Ver: ([0-9.]+) \(", out)
@ -257,7 +259,7 @@ class F2fs(Filesystem):
def get_fs_size(self, dev):
cmd = self.module.get_bin_path('dump.f2fs', required=True)
# Get sector count and sector size
_, dump, _ = self.module.run_command([cmd, str(dev)], check_rc=True)
_, dump, _ = self.module.run_command([cmd, str(dev)], check_rc=True, environ_update=self.LANG_ENV)
sector_size = None
sector_count = None
for line in dump.splitlines():
@ -286,7 +288,7 @@ class VFAT(Filesystem):
def get_fs_size(self, dev):
cmd = self.module.get_bin_path(self.GROW, required=True)
_, output, _ = self.module.run_command([cmd, '--info', str(dev)], check_rc=True)
_, output, _ = self.module.run_command([cmd, '--info', str(dev)], check_rc=True, environ_update=self.LANG_ENV)
for line in output.splitlines()[1:]:
param, value = line.split(':', 1)
if param.strip() == 'Size':