Commit f6441c7c authored by Iustin Pop's avatar Iustin Pop

Filters out LANG and LC_* on RunCmd

This filters out the LANG and LC_ variables from the environment of programs
executed by RunCmd, in order to get consistent output of execute programs like
lvs, etc.

Reviewed-by: imsnah
parent 8e587e52
......@@ -209,11 +209,13 @@ def RunCmd(cmd):
else:
strcmd = cmd
shell = True
new_env = dict([(key, val) for (key, val) in os.environ.items()
if not (key == "LANG" or key.startswith("LC_"))])
child = subprocess.Popen(cmd, shell=shell,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
close_fds=True)
close_fds=True, env=new_env)
child.stdin.close()
out = child.stdout.read()
......
......@@ -149,6 +149,16 @@ class TestRunCmd(unittest.TestCase):
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, self.magic)
def testLang(self):
"""Test locale environment"""
os.environ["LANG"] = "en_US.UTF-8"
os.environ["LC_ALL"] = "en_US.UTF-8"
result = RunCmd(["env"])
for line in result.output.splitlines():
key, val = line.split("=", 1)
if key.startswith("LC_") or key == "LANG":
self.fail("Unexpected language variable '%s' = '%s'" % (key, val))
class TestRemoveFile(unittest.TestCase):
"""Test case for the RemoveFile function"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment