Commit 24508b1a authored by Marco Mariani's avatar Marco Mariani

dict-kw cleanup

parent 65e35e46
...@@ -314,18 +314,18 @@ class Partition(object): ...@@ -314,18 +314,18 @@ class Partition(object):
'templates/program_partition_supervisord.conf.in').read() 'templates/program_partition_supervisord.conf.in').read()
for runner in runner_list: for runner in runner_list:
self.partition_supervisor_configuration += '\n' + \ self.partition_supervisor_configuration += '\n' + \
program_partition_template % dict( program_partition_template % {
program_id='_'.join([partition_id, runner]), 'program_id': '_'.join([partition_id, runner]),
program_directory=self.instance_path, 'program_directory': self.instance_path,
program_command=os.path.join(path, runner), 'program_command': os.path.join(path, runner),
program_name=runner+extension, 'program_name': runner + extension,
instance_path=self.instance_path, 'instance_path': self.instance_path,
user_id=uid, 'user_id': uid,
group_id=gid, 'group_id': gid,
# As supervisord has no environment to inherit, setup a minimalistic one # As supervisord has no environment to inherit, setup a minimalistic one
HOME=pwd.getpwuid(uid).pw_dir, 'HOME': pwd.getpwuid(uid).pw_dir,
USER=pwd.getpwuid(uid).pw_name, 'USER': pwd.getpwuid(uid).pw_name,
) }
def updateSymlink(self, sr_symlink, software_path): def updateSymlink(self, sr_symlink, software_path):
if os.path.lexists(sr_symlink): if os.path.lexists(sr_symlink):
...@@ -376,14 +376,14 @@ class Partition(object): ...@@ -376,14 +376,14 @@ class Partition(object):
# fill generated buildout with additional information # fill generated buildout with additional information
buildout_text = open(config_location).read() buildout_text = open(config_location).read()
buildout_text += '\n\n' + pkg_resources.resource_string(__name__, buildout_text += '\n\n' + pkg_resources.resource_string(__name__,
'templates/buildout-tail.cfg.in') % dict( 'templates/buildout-tail.cfg.in') % {
computer_id=self.computer_id, 'computer_id': self.computer_id,
partition_id=self.partition_id, 'partition_id': self.partition_id,
server_url=self.server_url, 'server_url': self.server_url,
software_release_url=self.software_release_url, 'software_release_url': self.software_release_url,
key_file=self.key_file, 'key_file': self.key_file,
cert_file=self.cert_file 'cert_file': self.cert_file,
) }
open(config_location, 'w').write(buildout_text) open(config_location, 'w').write(buildout_text)
os.chmod(config_location, 0o640) os.chmod(config_location, 0o640)
# Try to find the best possible buildout: # Try to find the best possible buildout:
...@@ -460,10 +460,11 @@ class Partition(object): ...@@ -460,10 +460,11 @@ class Partition(object):
partition_id = self.computer_partition.getId() partition_id = self.computer_partition.getId()
group_partition_template = pkg_resources.resource_stream(__name__, group_partition_template = pkg_resources.resource_stream(__name__,
'templates/group_partition_supervisord.conf.in').read() 'templates/group_partition_supervisord.conf.in').read()
self.partition_supervisor_configuration = group_partition_template % dict( self.partition_supervisor_configuration = group_partition_template % {
instance_id=partition_id, 'instance_id': partition_id,
program_list=','.join(['_'.join([partition_id, runner]) 'program_list': ','.join(['_'.join([partition_id, runner])
for runner in runner_list+service_list])) for runner in runner_list + service_list])
}
# Same method to add to service and run # Same method to add to service and run
self.addServiceToGroup(partition_id, runner_list,self.run_path) self.addServiceToGroup(partition_id, runner_list,self.run_path)
self.addServiceToGroup(partition_id, service_list,self.service_path, self.addServiceToGroup(partition_id, service_list,self.service_path,
......
...@@ -516,20 +516,17 @@ class Slapgrid(object): ...@@ -516,20 +516,17 @@ class Slapgrid(object):
# Creates supervisord configuration # Creates supervisord configuration
updateFile(self.supervisord_configuration_path, updateFile(self.supervisord_configuration_path,
pkg_resources.resource_stream(__name__, pkg_resources.resource_stream(__name__,
'templates/supervisord.conf.in').read() % dict( 'templates/supervisord.conf.in').read() % {
supervisord_configuration_directory=\ 'supervisord_configuration_directory': self.supervisord_configuration_directory,
self.supervisord_configuration_directory, 'supervisord_socket': os.path.abspath(self.supervisord_socket),
supervisord_socket=os.path.abspath(self.supervisord_socket), 'supervisord_loglevel': 'info',
supervisord_loglevel='info', 'supervisord_logfile': os.path.abspath(os.path.join(self.instance_root, 'var', 'log', 'supervisord.log')),
supervisord_logfile=os.path.abspath(os.path.join( 'supervisord_logfile_maxbytes': '50MB',
self.instance_root, 'var', 'log', 'supervisord.log')), 'supervisord_nodaemon': 'false',
supervisord_logfile_maxbytes='50MB', 'supervisord_pidfile': os.path.abspath(os.path.join(self.instance_root, 'var', 'run', 'supervisord.pid')),
supervisord_nodaemon='false', 'supervisord_logfile_backups': '10',
supervisord_pidfile=os.path.abspath(os.path.join( 'watchdog_command': self.getWatchdogLine(),
self.instance_root, 'var', 'run', 'supervisord.pid')), })
supervisord_logfile_backups='10',
watchdog_command = self.getWatchdogLine(),
))
except (WrongPermissionError, PathDoesNotExistError) as error: except (WrongPermissionError, PathDoesNotExistError) as error:
raise error raise error
...@@ -668,14 +665,14 @@ class Slapgrid(object): ...@@ -668,14 +665,14 @@ class Slapgrid(object):
promise = os.path.basename(command[0]) promise = os.path.basename(command[0])
self.logger.info("Checking promise %r.", promise) self.logger.info("Checking promise %r.", promise)
kw = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
process_handler = subprocess.Popen(command, process_handler = subprocess.Popen(command,
preexec_fn=lambda: dropPrivileges(uid, gid), preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=cwd, cwd=cwd,
env=None if sys.platform == 'cygwin' else {}, env=None if sys.platform == 'cygwin' else {},
**kw) stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
process_handler.stdin.flush() process_handler.stdin.flush()
process_handler.stdin.close() process_handler.stdin.close()
process_handler.stdin = None process_handler.stdin = None
...@@ -1129,12 +1126,12 @@ class Slapgrid(object): ...@@ -1129,12 +1126,12 @@ class Slapgrid(object):
#stat sys call to get statistics informations #stat sys call to get statistics informations
uid = stat_info.st_uid uid = stat_info.st_uid
gid = stat_info.st_gid gid = stat_info.st_gid
kw = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_handler = SlapPopen(invocation_list, process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid), preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=os.path.join(instance_path, 'etc', 'report'), cwd=os.path.join(instance_path, 'etc', 'report'),
env=None, env=None,
**kw) stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if process_handler.returncode is None: if process_handler.returncode is None:
process_handler.kill() process_handler.kill()
if process_handler.returncode != 0: if process_handler.returncode != 0:
......
...@@ -278,9 +278,8 @@ def bootstrapBuildout(path, buildout=None, ...@@ -278,9 +278,8 @@ def bootstrapBuildout(path, buildout=None,
path)) path))
kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_handler = SlapPopen(invocation_list, process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid), preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=path, cwd=path, **kw)
**kw)
if process_handler.returncode is None or process_handler.returncode != 0: if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r' % (path) message = 'Failed to run buildout profile in directory %r' % (path)
logger.error(message) logger.error(message)
...@@ -321,8 +320,10 @@ def launchBuildout(path, buildout_binary, ...@@ -321,8 +320,10 @@ def launchBuildout(path, buildout_binary,
path)) path))
kw = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) kw = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_handler = SlapPopen(invocation_list, process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid), cwd=path, preexec_fn=lambda: dropPrivileges(uid, gid),
env=getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw) cwd=path,
env=getCleanEnvironment(pwd.getpwuid(uid).pw_dir),
**kw)
if process_handler.returncode is None or process_handler.returncode != 0: if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r' % (path) message = 'Failed to run buildout profile in directory %r' % (path)
logger.error(message) logger.error(message)
......
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