Commit 65622b9a authored by Marco Mariani's avatar Marco Mariani

make pep8 happy

parent c1058afd
...@@ -43,7 +43,7 @@ from supervisor import xmlrpc ...@@ -43,7 +43,7 @@ from supervisor import xmlrpc
from slapos.grid.utils import (md5digest, getCleanEnvironment, from slapos.grid.utils import (md5digest, getCleanEnvironment,
SlapPopen, dropPrivileges, updateFile) SlapPopen, dropPrivileges, updateFile)
from slapos.grid import utils # for mocked methods from slapos.grid import utils # for mocked methods
from slapos.slap.slap import NotFoundError from slapos.slap.slap import NotFoundError
from slapos.grid.svcbackend import getSupervisorRPC from slapos.grid.svcbackend import getSupervisorRPC
from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError, from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError,
...@@ -166,8 +166,8 @@ class Software(object): ...@@ -166,8 +166,8 @@ class Software(object):
] ]
if (self.signature_private_key_file or if (self.signature_private_key_file or
self.upload_cache_url or self.upload_cache_url or
self.upload_dir_url): self.upload_dir_url):
buildout_parameter_list.append('buildout:networkcache-section=networkcache') buildout_parameter_list.append('buildout:networkcache-section=networkcache')
for buildout_option, value in [ for buildout_option, value in [
('%ssignature-private-key-file=%s', self.signature_private_key_file), ('%ssignature-private-key-file=%s', self.signature_private_key_file),
...@@ -306,10 +306,7 @@ class Partition(object): ...@@ -306,10 +306,7 @@ class Partition(object):
uid, gid = self.getUserGroupId() uid, gid = self.getUserGroupId()
for name, path in [ for name, path in [('certificate', self.cert_file), ('key', self.key_file)]:
('certificate', self.cert_file),
('key', self.key_file),
]:
new_content = partition_certificate[name] new_content = partition_certificate[name]
old_content = None old_content = None
if os.path.exists(path): if os.path.exists(path):
...@@ -325,7 +322,6 @@ class Partition(object): ...@@ -325,7 +322,6 @@ class Partition(object):
fout.write(new_content) fout.write(new_content)
os.chown(path, uid, gid) os.chown(path, uid, gid)
def getUserGroupId(self): def getUserGroupId(self):
"""Returns tuple of (uid, gid) of partition""" """Returns tuple of (uid, gid) of partition"""
stat_info = os.stat(self.instance_path) stat_info = os.stat(self.instance_path)
...@@ -341,17 +337,17 @@ class Partition(object): ...@@ -341,17 +337,17 @@ class Partition(object):
for runner in runner_list: for runner in runner_list:
self.partition_supervisor_configuration += '\n' + \ self.partition_supervisor_configuration += '\n' + \
program_partition_template % { 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):
...@@ -391,7 +387,7 @@ class Partition(object): ...@@ -391,7 +387,7 @@ class Partition(object):
if not os.path.exists(self.software_path): if not os.path.exists(self.software_path):
# XXX What should it raise? # XXX What should it raise?
raise IOError('Software Release %s is not present on system.\n' raise IOError('Software Release %s is not present on system.\n'
'Cannot deploy instance.' % self.software_release_url) 'Cannot deploy instance.' % self.software_release_url)
# Generate buildout instance profile from template in Software Release # Generate buildout instance profile from template in Software Release
template_location = os.path.join(self.software_path, 'instance.cfg') template_location = os.path.join(self.software_path, 'instance.cfg')
...@@ -412,13 +408,13 @@ class Partition(object): ...@@ -412,13 +408,13 @@ class Partition(object):
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') % { '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:
...@@ -482,7 +478,6 @@ class Partition(object): ...@@ -482,7 +478,6 @@ class Partition(object):
logger=self.logger) logger=self.logger)
self.generateSupervisorConfigurationFile() self.generateSupervisorConfigurationFile()
def generateSupervisorConfigurationFile(self): def generateSupervisorConfigurationFile(self):
""" """
Generates supervisord configuration file from template. Generates supervisord configuration file from template.
...@@ -510,10 +505,10 @@ class Partition(object): ...@@ -510,10 +505,10 @@ class Partition(object):
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 % { 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,
......
...@@ -62,4 +62,3 @@ def patched_linux_distribution(distname='', version='', id='', ...@@ -62,4 +62,3 @@ def patched_linux_distribution(distname='', version='', id='',
pass pass
return platform.linux_distribution(distname, version, id, supported_dists, full_distribution_name) return platform.linux_distribution(distname, version, id, supported_dists, full_distribution_name)
This diff is collapsed.
...@@ -124,7 +124,7 @@ def getCleanEnvironment(logger, home_path='/tmp'): ...@@ -124,7 +124,7 @@ def getCleanEnvironment(logger, home_path='/tmp'):
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:
removed_env.append(k) removed_env.append(k)
...@@ -197,8 +197,7 @@ def dropPrivileges(uid, gid, logger): ...@@ -197,8 +197,7 @@ def dropPrivileges(uid, gid, logger):
# assert that privileges are dropped # assert that privileges are dropped
message_pre = 'After dropping to uid = %r and gid = %r ' \ message_pre = 'After dropping to uid = %r and gid = %r ' \
'and group_list = %s' % ( 'and group_list = %s' % (uid, gid, group_list)
uid, gid, group_list)
new_uid, new_gid, new_group_list = os.getuid(), os.getgid(), os.getgroups() new_uid, new_gid, new_group_list = os.getuid(), os.getgid(), os.getgroups()
if not (new_uid == uid and new_gid == gid and set(new_group_list) == group_list): if not (new_uid == uid and new_gid == gid and set(new_group_list) == group_list):
raise OSError('%s new_uid = %r and new_gid = %r and ' raise OSError('%s new_uid = %r and new_gid = %r and '
......
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