summaryrefslogtreecommitdiff
path: root/morphlib/plugins
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2015-08-03 10:03:29 +0000
committerBaserock Gerrit <gerrit@baserock.org>2015-09-01 08:25:24 +0000
commit0b50b9ceca5fc604550537297e786d876d28508a (patch)
treecdc599c2e293ff8269e612c8b265648c9ac505d1 /morphlib/plugins
parent41cbcdf6b5c0f823ac5589faaf6da3651ad69dab (diff)
downloadmorph-0b50b9ceca5fc604550537297e786d876d28508a.tar.gz
Stop moving staging areas of failed builds
Stop moving staging areas of failed builds from the 'staging' directory to the 'failed' directory. Moving staging areas make it very difficult to debug build failures on the build essential chunks, as the paths set on the configure scripts and some environment variables (e.g. STAGE2_SYSROOT, DESTDIR) will be invalid after moving the staging area. This change will also make it easier to create scripts that chroot n environment similiar to the one where the build failure occurred. To make it still possible to safely do a build an run `morph gc` in parallel, we use flock(2) to control access to the staging area directory. Also, move the `test_supports_non_isolated_mode` test into a different class, as it requires a different SetUp() routine (the staging area is contructed with different parameters). Change-Id: I06c3c435ad05c12afabc0adc2a9d4f8a284ccc02
Diffstat (limited to 'morphlib/plugins')
-rw-r--r--morphlib/plugins/gc_plugin.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/morphlib/plugins/gc_plugin.py b/morphlib/plugins/gc_plugin.py
index 71522b04..79c65e5d 100644
--- a/morphlib/plugins/gc_plugin.py
+++ b/morphlib/plugins/gc_plugin.py
@@ -17,6 +17,7 @@ import logging
import os
import shutil
import time
+import fcntl
import fs.osfs
import cliapp
@@ -82,7 +83,32 @@ class GCPlugin(cliapp.Plugin):
# assumes that they exist in various places.
self.app.status(msg='Cleaning up temp dir %(temp_path)s',
temp_path=temp_path, chatty=True)
- for subdir in ('deployments', 'failed', 'chunks'):
+
+ self.app.status(msg='Removing temp subdirectory: staging')
+ staging_dir = os.path.join(temp_path, 'staging')
+ subdirs = (f for f in os.listdir(staging_dir)
+ if os.path.isdir(os.path.join(staging_dir, f)))
+ for subdir in subdirs:
+ fd = None
+ prefix_dir = os.path.join(staging_dir, subdir)
+ try:
+ fd = os.open(prefix_dir, os.O_RDONLY)
+ fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ chroot_script = os.path.join('%s.sh' % prefix_dir)
+ if os.path.exists(chroot_script):
+ os.remove(chroot_script)
+ log_file = os.path.join('%s.log' % prefix_dir)
+ if os.path.exists(log_file):
+ os.remove(log_file)
+ if os.path.exists(prefix_dir):
+ shutil.rmtree(prefix_dir)
+ except IOError:
+ pass
+ finally:
+ if fd is not None:
+ os.close(fd)
+
+ for subdir in ('deployments', 'chunks'):
if morphlib.util.get_bytes_free_in_path(temp_path) >= min_space:
self.app.status(msg='Not Removing subdirectory '
'%(subdir)s, enough space already cleared',