summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-03-07 15:23:06 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-03-14 10:54:55 +0000
commit678bac5ca44a8b4b7b5f0e3ab17104b5171cda0e (patch)
tree4b79024bcfc596072a5e0fd853317e81d63fafff
parentd79ea3978718aba1d4e3585de873b4a661428d07 (diff)
downloadmorph-678bac5ca44a8b4b7b5f0e3ab17104b5171cda0e.tar.gz
Move tempdir creation out of the loop
We don't need to remove the whole thing every time, and for nested deployments, we want to keep the directories around, since there will be multiple deploys happening in it concurrently.
-rw-r--r--morphlib/plugins/deploy_plugin.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 71ca5a2c..51f5b247 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -332,13 +332,20 @@ class DeployPlugin(cliapp.Plugin):
ref=build_ref, dirname=gd.dirname,
remote=remote.get_push_url(), chatty=True)
- for system in cluster_morphology['systems']:
- self.deploy_system(build_command, root_repo_dir,
- bb.root_repo_url, bb.root_ref,
- system, env_vars)
-
- def deploy_system(self, build_command, root_repo_dir, build_repo, ref,
- system, env_vars):
+ # Create a tempdir for this deployment to work in
+ deploy_tempdir = tempfile.mkdtemp(
+ dir=os.path.join(self.app.settings['tempdir'], 'deployments'))
+ try:
+ for system in cluster_morphology['systems']:
+ self.deploy_system(build_command, deploy_tempdir,
+ root_repo_dir,
+ bb.root_repo_url, bb.root_ref,
+ system, env_vars)
+ finally:
+ shutil.rmtree(deploy_tempdir)
+
+ def deploy_system(self, build_command, deploy_tempdir,
+ root_repo_dir, build_repo, ref, system, env_vars):
# Find the artifact to build
morph = system['morph']
srcpool = build_command.create_source_pool(build_repo, ref,
@@ -373,11 +380,12 @@ class DeployPlugin(cliapp.Plugin):
'for system "%s"' % system_id)
morphlib.util.sanitize_environment(final_env)
- self.do_deploy(build_command, root_repo_dir, ref, artifact,
+ self.do_deploy(build_command, deploy_tempdir,
+ root_repo_dir, ref, artifact,
deployment_type, location, final_env)
- def do_deploy(self, build_command, root_repo_dir, ref, artifact,
- deployment_type, location, env):
+ def do_deploy(self, build_command, deploy_tempdir, root_repo_dir,
+ ref, artifact, deployment_type, location, env):
# Run optional write check extension. These are separate from the write
# extension because it may be several minutes before the write
# extension itself has the chance to raise an error.
@@ -388,18 +396,15 @@ class DeployPlugin(cliapp.Plugin):
except ExtensionNotFoundError:
pass
- # Create a tempdir for this deployment to work in
- deploy_tempdir = tempfile.mkdtemp(
- dir=os.path.join(self.app.settings['tempdir'], 'deployments'))
- try:
- # Create a tempdir to extract the rootfs in
- system_tree = tempfile.mkdtemp(dir=deploy_tempdir)
+ # Create a tempdir to extract the rootfs in
+ system_tree = tempfile.mkdtemp(dir=deploy_tempdir)
- # Extensions get a private tempdir so we can more easily clean
- # up any files an extension left behind
- deploy_private_tempdir = tempfile.mkdtemp(dir=deploy_tempdir)
- env['TMPDIR'] = deploy_private_tempdir
+ # Extensions get a private tempdir so we can more easily clean
+ # up any files an extension left behind
+ deploy_private_tempdir = tempfile.mkdtemp(dir=deploy_tempdir)
+ env['TMPDIR'] = deploy_private_tempdir
+ try:
# Unpack the artifact (tarball) to a temporary directory.
self.app.status(msg='Unpacking system for configuration')
@@ -453,7 +458,8 @@ class DeployPlugin(cliapp.Plugin):
finally:
# Cleanup.
self.app.status(msg='Cleaning up')
- shutil.rmtree(deploy_tempdir)
+ shutil.rmtree(deploy_private_tempdir)
+ shutil.rmtree(system_tree)
self.app.status(msg='Finished deployment')