Revision 23f41a3e

b/lib/utils.py
209 209
  else:
210 210
    strcmd = cmd
211 211
    shell = True
212
  new_env = dict([(key, val) for (key, val) in os.environ.items()
213
                  if not (key == "LANG" or key.startswith("LC_"))])
212
  env = os.environ.copy()
213
  env["LC_ALL"] = "C"
214 214
  child = subprocess.Popen(cmd, shell=shell,
215 215
                           stderr=subprocess.PIPE,
216 216
                           stdout=subprocess.PIPE,
217 217
                           stdin=subprocess.PIPE,
218
                           close_fds=True, env=new_env)
218
                           close_fds=True, env=env)
219 219

  
220 220
  child.stdin.close()
221 221
  out = child.stdout.read()
b/testing/ganeti.utils_unittest.py
151 151

  
152 152
  def testLang(self):
153 153
    """Test locale environment"""
154
    os.environ["LANG"] = "en_US.UTF-8"
155
    os.environ["LC_ALL"] = "en_US.UTF-8"
156
    result = RunCmd(["env"])
157
    for line in result.output.splitlines():
158
      key, val = line.split("=", 1)
159
      if key.startswith("LC_") or key == "LANG":
160
        self.fail("Unexpected language variable '%s' = '%s'" % (key, val))
154
    old_env = os.environ.copy()
155
    try:
156
      os.environ["LANG"] = "en_US.UTF-8"
157
      os.environ["LC_ALL"] = "en_US.UTF-8"
158
      result = RunCmd(["locale"])
159
      for line in result.output.splitlines():
160
        key, value = line.split("=", 1)
161
        # Ignore these variables, they're overridden by LC_ALL
162
        if key == "LANG" or key == "LANGUAGE":
163
          continue
164
        self.failIf(value and value != "C" and value != '"C"',
165
            "Variable %s is set to the invalid value '%s'" % (key, value))
166
    finally:
167
      os.environ = old_env
161 168

  
162 169

  
163 170
class TestRemoveFile(unittest.TestCase):

Also available in: Unified diff