Commit a84d4b79 authored by Marco Mariani's avatar Marco Mariani

SlapObject: cleaner buildout_cfg creation

parent be2b2ac7
...@@ -408,23 +408,25 @@ class Partition(object): ...@@ -408,23 +408,25 @@ class Partition(object):
'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') instance_cfg = os.path.join(self.software_path, 'instance.cfg')
if not os.path.exists(template_location): if not os.path.exists(instance_cfg):
# Backward compatibility: "instance.cfg" file was named "template.cfg". # Backward compatibility: "instance.cfg" file was named "template.cfg".
if os.path.exists(os.path.join(self.software_path, 'template.cfg')): if os.path.exists(os.path.join(self.software_path, 'template.cfg')):
template_location = os.path.join(self.software_path, 'template.cfg') instance_cfg = os.path.join(self.software_path, 'template.cfg')
else: else:
# No template: Software Release is either inconsistent or not correctly installed. # No template: Software Release is either inconsistent or not correctly installed.
# XXX What should it raise? # XXX What should it raise?
raise IOError('Software Release %s is not correctly installed.\nMissing file: %s' % ( raise IOError('Software Release %s is not correctly installed.\nMissing file: %s' % (
self.software_release_url, template_location)) self.software_release_url, instance_cfg))
config_location = os.path.join(self.instance_path, 'buildout.cfg')
self.logger.debug("Copying %r to %r" % (template_location, config_location))
shutil.copy(template_location, config_location)
buildout_cfg = os.path.join(self.instance_path, 'buildout.cfg')
self.logger.debug("Copying %r to %r" % (instance_cfg, buildout_cfg))
with open(buildout_cfg, 'w') as fout:
fout.write(open(instance_cfg).read())
fout.write('\n\n')
# fill generated buildout with additional information # fill generated buildout with additional information
buildout_text = open(config_location).read() fout.write(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,
...@@ -432,9 +434,9 @@ class Partition(object): ...@@ -432,9 +434,9 @@ class Partition(object):
'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) os.chmod(buildout_cfg, 0o640)
os.chmod(config_location, 0o640)
# Try to find the best possible buildout: # Try to find the best possible buildout:
# *) if software_root/bin/bootstrap exists use this one to bootstrap # *) if software_root/bin/bootstrap exists use this one to bootstrap
# locally # locally
...@@ -447,7 +449,7 @@ class Partition(object): ...@@ -447,7 +449,7 @@ class Partition(object):
else: else:
bootstrap_candidate_list = [] bootstrap_candidate_list = []
uid, gid = self.getUserGroupId() uid, gid = self.getUserGroupId()
os.chown(config_location, -1, int(gid)) os.chown(buildout_cfg, -1, int(gid))
if len(bootstrap_candidate_list) == 0: if len(bootstrap_candidate_list) == 0:
buildout_binary = os.path.join(self.software_path, 'bin', 'buildout') buildout_binary = os.path.join(self.software_path, 'bin', 'buildout')
self.logger.warning("Falling back to default buildout %r" % self.logger.warning("Falling back to default buildout %r" %
...@@ -490,7 +492,7 @@ class Partition(object): ...@@ -490,7 +492,7 @@ class Partition(object):
['buildout:bin-directory=%s' % ['buildout:bin-directory=%s' %
os.path.join(self.instance_path, 'sbin')]) os.path.join(self.instance_path, 'sbin')])
buildout_binary = os.path.join(self.instance_path, 'sbin', 'buildout') buildout_binary = os.path.join(self.instance_path, 'sbin', 'buildout')
# Launches buildout
utils.launchBuildout(path=self.instance_path, utils.launchBuildout(path=self.instance_path,
buildout_binary=buildout_binary, buildout_binary=buildout_binary,
logger=self.logger) logger=self.logger)
...@@ -588,6 +590,7 @@ class Partition(object): ...@@ -588,6 +590,7 @@ class Partition(object):
destroy_binary = os.path.join(self.instance_path, 'sbin', 'destroy') destroy_binary = os.path.join(self.instance_path, 'sbin', 'destroy')
if os.path.exists(destroy_binary): if os.path.exists(destroy_binary):
self._pre_destroy(destroy_binary) self._pre_destroy(destroy_binary)
# Manually cleans what remains # Manually cleans what remains
try: try:
for f in [self.key_file, self.cert_file]: for f in [self.key_file, self.cert_file]:
......
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