diff options
author | Samuel Munilla <smunilla@redhat.com> | 2016-10-25 15:37:57 -0400 |
---|---|---|
committer | Samuel Munilla <smunilla@redhat.com> | 2016-10-25 16:00:43 -0400 |
commit | 07113bc31ffa60a5fc3f34b392576d4639474485 (patch) | |
tree | 3bac8a17b5c199a5ee6255f4243997819ecb8c8a /roles | |
parent | 6c705bae58578893d17ed6aeaf30efc3a7681b0a (diff) | |
download | openshift-07113bc31ffa60a5fc3f34b392576d4639474485.tar.gz openshift-07113bc31ffa60a5fc3f34b392576d4639474485.tar.bz2 openshift-07113bc31ffa60a5fc3f34b392576d4639474485.tar.xz openshift-07113bc31ffa60a5fc3f34b392576d4639474485.zip |
Fix race condtion in openshift_facts
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
Diffstat (limited to 'roles')
-rwxr-xr-x | roles/openshift_facts/library/openshift_facts.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 61ce55b7f..1d611f010 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -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) |