Commit e4d513f3 authored by Marco Mariani's avatar Marco Mariani

grid: allow overriding of variables like USER in buildout context

parent 3aa3a2c4
...@@ -465,8 +465,8 @@ class Partition(object): ...@@ -465,8 +465,8 @@ class Partition(object):
process_handler = SlapPopen(invocation_list, process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger), preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
cwd=self.instance_path, cwd=self.instance_path,
env=getCleanEnvironment(logger=self.logger, env=getCleanEnvironment(self.logger,
home_path=pwd.getpwuid(uid).pw_dir), {'HOME': pwd.getpwuid(uid).pw_dir}),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
logger=self.logger) logger=self.logger)
...@@ -571,8 +571,8 @@ class Partition(object): ...@@ -571,8 +571,8 @@ class Partition(object):
process_handler = SlapPopen([destroy_executable_location], process_handler = SlapPopen([destroy_executable_location],
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger), preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
cwd=self.instance_path, cwd=self.instance_path,
env=getCleanEnvironment(logger=self.logger, env=getCleanEnvironment(self.logger,
home_path=pwd.getpwuid(uid).pw_dir), {'HOME': pwd.getpwuid(uid).pw_dir}),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
logger=self.logger) logger=self.logger)
......
...@@ -118,20 +118,27 @@ def md5digest(url): ...@@ -118,20 +118,27 @@ def md5digest(url):
return hashlib.md5(url).hexdigest() return hashlib.md5(url).hexdigest()
def getCleanEnvironment(logger, home_path='/tmp'): def getCleanEnvironment(logger, override=None):
changed_env = {} if override is None:
removed_env = [] override = {}
if not 'HOME' in override:
raise KeyError('Overridden environment must contain the HOME variable.')
removed = []
env = os.environ.copy() env = os.environ.copy()
# Clean python related environment variables # Clean python related environment variables
for k in PYTHON_ENVIRONMENT_REMOVE_LIST + SYSTEM_ENVIRONMENT_REMOVE_LIST \ for k in PYTHON_ENVIRONMENT_REMOVE_LIST + SYSTEM_ENVIRONMENT_REMOVE_LIST \
+ LOCALE_ENVIRONMENT_REMOVE_LIST: + LOCALE_ENVIRONMENT_REMOVE_LIST:
old = env.pop(k, None) old = env.pop(k, None)
if old is not None: if old is not None and k not in override:
removed_env.append(k) removed.append(k)
changed_env['HOME'] = env['HOME'] = home_path
for k in sorted(changed_env.iterkeys()): for k in sorted(override):
logger.debug('Overridden %s = %r' % (k, changed_env[k])) env[k] = override[k]
logger.debug('Removed from environment: %s' % ', '.join(sorted(removed_env))) logger.debug("Overridden %s = '%s'", k, override[k])
logger.debug('Removed from environment: %s' % ', '.join(sorted(removed)))
return env return env
...@@ -308,8 +315,11 @@ def launchBuildout(path, buildout_binary, logger, ...@@ -308,8 +315,11 @@ def launchBuildout(path, buildout_binary, logger,
process_handler = SlapPopen(invocation_list, process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=logger), preexec_fn=lambda: dropPrivileges(uid, gid, logger=logger),
cwd=path, cwd=path,
env=getCleanEnvironment(logger=logger, env=getCleanEnvironment(logger,
home_path=path), {
'HOME': path,
'USER': pwd.getpwuid(uid).pw_name,
}),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
logger=logger) logger=logger)
......
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