From f6441c7c1dbd1dbab2f751d87b02cfd9273f221c Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 11 Sep 2007 12:18:05 +0000 Subject: [PATCH] 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 --- lib/utils.py | 4 +++- testing/ganeti.utils_unittest.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/utils.py b/lib/utils.py index 253e2d8ef..28f509a10 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -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() diff --git a/testing/ganeti.utils_unittest.py b/testing/ganeti.utils_unittest.py index 71db83ae3..65a4eab9c 100755 --- a/testing/ganeti.utils_unittest.py +++ b/testing/ganeti.utils_unittest.py @@ -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""" -- GitLab