From b95ab85a9319abe7dba8c254ef69c2c4eedc578f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 6 Jan 2016 15:59:33 +0000 Subject: More robust artifact cachedir creation When starting various distbuilds at the same time we were having random 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 the 'artifacts' folder after Mason finishes. Change-Id: Ie328ec1debf12f27f49641fbf7ad4fa9403ba8a3 --- morphlib/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/morphlib/util.py b/morphlib/util.py index 94b0f4c4..b76029df 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 . import contextlib +import errno import itertools import os import pipes @@ -136,7 +137,11 @@ 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): - os.mkdir(artifact_cachedir) + try: + os.mkdir(artifact_cachedir) + except OSError as e: + if e.errno != errno.EEXIST: + raise lac = morphlib.localartifactcache.LocalArtifactCache( fs.osfs.OSFS(artifact_cachedir)) -- cgit v1.2.1