diff --git a/lib/utils.py b/lib/utils.py index 253e2d8ef2d011d359aafebb53a2aacd14377d51..28f509a10306781e648933e0c796548b8893840f 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 71db83ae3fe3825790af358af1f9fd1e5f8b8d59..65a4eab9c0f6de7619d20266c1088d1c780e69a2 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"""