diff options
author | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-01-12 13:13:15 +0000 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-01-22 12:44:43 +0000 |
commit | fa431c3ce38204f5237337fd2045ad6269413258 (patch) | |
tree | 35b2524a10e5ec93a60a19c04373e3e373a68274 /morphlib | |
parent | 0f00fbbed38757a2b0628341f172c69d9c4dd60a (diff) | |
download | morph-fa431c3ce38204f5237337fd2045ad6269413258.tar.gz |
More robust creation of cache dirs
When starting various distbuilds at the same time we were
having randomly errors like:
2016-01-06 12:14:03 Starting distributed build
2016-01-06 12:14:03 Connecting to mason-x86-64:7878
2016-01-06 12:14:03 Requesting build of git://192.168.222.58/baserock/baserock/definitions 28b92192c00a36395acd6a960959d3b4468f9894 systems/openstack-system-x86_64.morph
ERROR: /srv/distbuild/artifacts: File exists
ERROR: /srv/distbuild/artifacts: File exists
ERROR: /srv/distbuild/artifacts: File exists
ERROR: /srv/distbuild/artifacts: File exists
This has been happening in Mason since we remove every folder
used by Morph after Mason finishes.
Change-Id: I175de7282302d9c1e2fb1b0872f7eb72c742f28e
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/util.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/morphlib/util.py b/morphlib/util.py index 94b0f4c4..3b3e4d2b 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2011-2015 Codethink Limited +# Copyright (C) 2011-2016 Codethink Limited # Copyright © 2015 Richard Ipsum # # This program is free software; you can redistribute it and/or modify @@ -15,6 +15,7 @@ # with this program. If not, see <http://www.gnu.org/licenses/>. import contextlib +import errno import itertools import os import pipes @@ -105,8 +106,15 @@ def create_cachedir(settings): # pragma: no cover '''Return cache directory, creating it if necessary.''' cachedir = settings['cachedir'] - if not os.path.exists(cachedir): + # Don't check the folder exists and handle the exception that happens in + # this case to avoid errors if the folder is created by something else + # just after the check. + try: os.mkdir(cachedir) + except OSError as e: + if e.errno != errno.EEXIST: + raise + return cachedir @@ -135,8 +143,15 @@ def new_artifact_caches(settings): # pragma: no cover cachedir = create_cachedir(settings) artifact_cachedir = os.path.join(cachedir, 'artifacts') - if not os.path.exists(artifact_cachedir): + # Don't check the folder exists and handle the exception that happens in + # this case to avoid errors if the folder is created by something else + # just after the check. + try: os.mkdir(artifact_cachedir) + except OSError as e: + if e.errno != errno.EEXIST: + raise + lac = morphlib.localartifactcache.LocalArtifactCache( fs.osfs.OSFS(artifact_cachedir)) |