Skip to content

Commit

Permalink
Fix race condtion in openshift_facts
Browse files Browse the repository at this point in the history
If, for some reason, two facts processes were run simultaneously
on the same host, creating the directory could cause an exception.
This should help with that.

Fixes Bug 1385449
  • Loading branch information
smunilla committed Oct 25, 2016
1 parent 6c705ba commit 07113bc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions roles/openshift_facts/library/openshift_facts.py
Expand Up @@ -1380,8 +1380,11 @@ def save_local_facts(filename, facts):
"""
try:
fact_dir = os.path.dirname(filename)
if not os.path.exists(fact_dir):
os.makedirs(fact_dir)
try:
os.makedirs(fact_dir) # try to make the directory
except OSError as exception:
if exception.errno != errno.EEXIST: # but it is okay if it is already there
raise # pass any other exceptions up the chain
with open(filename, 'w') as fact_file:
fact_file.write(module.jsonify(facts))
os.chmod(filename, 0o600)
Expand Down

0 comments on commit 07113bc

Please sign in to comment.