Browse Source

Merge pull request #2667 from smunilla/BZ1385449

Fix race condtion in openshift_facts
Scott Dodson 8 years ago
parent
commit
52ab71a6f7
1 changed files with 5 additions and 2 deletions
  1. 5 2
      roles/openshift_facts/library/openshift_facts.py

+ 5 - 2
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)