Revision bf4daac9

b/lib/utils.py
118 118
  output = property(_GetOutput, None, None, "Return full output")
119 119

  
120 120

  
121
def RunCmd(cmd, env=None, output=None, cwd='/'):
121
def RunCmd(cmd, env=None, output=None, cwd='/', reset_env=False):
122 122
  """Execute a (shell) command.
123 123

  
124 124
  The command should not read from its standard input, as it will be
125 125
  closed.
126 126

  
127
  @type  cmd: string or list
127
  @type cmd: string or list
128 128
  @param cmd: Command to run
129 129
  @type env: dict
130 130
  @param env: Additional environment
......
135 135
  @type cwd: string
136 136
  @param cwd: if specified, will be used as the working
137 137
      directory for the command; the default will be /
138
  @type reset_env: boolean
139
  @param reset_env: whether to reset or keep the default os environment
138 140
  @rtype: L{RunResult}
139 141
  @return: RunResult instance
140 142
  @raise errors.ProgrammerError: if we call this when forks are disabled
......
152 154
    shell = True
153 155
  logging.debug("RunCmd '%s'", strcmd)
154 156

  
155
  cmd_env = os.environ.copy()
156
  cmd_env["LC_ALL"] = "C"
157
  if not reset_env:
158
    cmd_env = os.environ.copy()
159
    cmd_env["LC_ALL"] = "C"
160
  else:
161
    cmd_env = {}
162

  
157 163
  if env is not None:
158 164
    cmd_env.update(env)
159 165

  
b/test/ganeti.utils_unittest.py
231 231
    cwd = os.getcwd()
232 232
    self.failUnlessEqual(RunCmd(["pwd"], cwd=cwd).stdout.strip(), cwd)
233 233

  
234
  def testResetEnv(self):
235
    """Test environment reset functionality"""
236
    self.failUnlessEqual(RunCmd(["env"], reset_env=True).stdout.strip(), "")
237

  
234 238

  
235 239
class TestRemoveFile(unittest.TestCase):
236 240
  """Test case for the RemoveFile function"""

Also available in: Unified diff