This is an automated email from the ASF dual-hosted git repository.

aonishuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 50d955084256a79c2b03599cfc0e3658779057d5
Author: Andrew Onishuk <aonis...@hortonworks.com>
AuthorDate: Wed Sep 26 10:03:01 2018 +0300

    AMBARI-24670. Directory creation sometimes fails with parallel_execution=1 
(aonishuk)
---
 .../python/resource_management/core/providers/system.py   | 15 +++++++++++----
 .../src/main/python/resource_management/core/source.py    |  2 +-
 .../src/main/python/resource_management/core/sudo.py      | 11 +++++++++--
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git 
a/ambari-common/src/main/python/resource_management/core/providers/system.py 
b/ambari-common/src/main/python/resource_management/core/providers/system.py
index 6293436..95c12ad 100644
--- a/ambari-common/src/main/python/resource_management/core/providers/system.py
+++ b/ambari-common/src/main/python/resource_management/core/providers/system.py
@@ -172,7 +172,7 @@ class DirectoryProvider(Provider):
       if self.resource.follow:
         # Follow symlink until the tail.
         followed_links = set()
-        while sudo.path_lexists(path):
+        while sudo.path_islink(path):
           if path in followed_links:
             raise Fail("Applying %s failed, looped symbolic links found while 
resolving %s" % (self.resource, path))
           followed_links.add(path)
@@ -188,8 +188,15 @@ class DirectoryProvider(Provider):
         if not sudo.path_isdir(dirname):
           raise Fail("Applying %s failed, parent directory %s doesn't exist" % 
(self.resource, dirname))
         
-        sudo.makedir(path, self.resource.mode or 0755)
-      
+        try:
+          sudo.makedir(path, self.resource.mode or 0755)
+        except Exception as ex:
+          # race condition (somebody created the file before us)
+          if "File exists" in str(ex):
+            sudo.makedirs(path, self.resource.mode or 0755)
+          else:
+            raise
+
     if not sudo.path_isdir(path):
       raise Fail("Applying %s failed, file %s already exists" % 
(self.resource, path))
     
@@ -216,7 +223,7 @@ class LinkProvider(Provider):
       oldpath = os.path.realpath(path)
       if oldpath == self.resource.to:
         return
-      if not sudo.path_lexists(path):
+      if not sudo.path_islink(path):
         raise Fail(
           "%s trying to create a symlink with the same name as an existing 
file or directory" % self.resource)
       Logger.info("%s replacing old symlink to %s" % (self.resource, oldpath))
diff --git a/ambari-common/src/main/python/resource_management/core/source.py 
b/ambari-common/src/main/python/resource_management/core/source.py
index 32c5cad..a2b1598 100644
--- a/ambari-common/src/main/python/resource_management/core/source.py
+++ b/ambari-common/src/main/python/resource_management/core/source.py
@@ -72,7 +72,7 @@ class StaticFile(Source):
       basedir = self.env.config.basedir
       path = os.path.join(basedir, "files", self.name)
       
-    if not sudo.path_isfile(path) and not sudo.path_lexists(path):
+    if not sudo.path_isfile(path):
       raise Fail("{0} Source file {1} is not found".format(repr(self), path))
 
     return self.read_file(path)
diff --git a/ambari-common/src/main/python/resource_management/core/sudo.py 
b/ambari-common/src/main/python/resource_management/core/sudo.py
index f103c8d..990b293 100644
--- a/ambari-common/src/main/python/resource_management/core/sudo.py
+++ b/ambari-common/src/main/python/resource_management/core/sudo.py
@@ -159,7 +159,10 @@ if os.geteuid() == 0:
   
   def path_isdir(path):
     return os.path.isdir(path)
-  
+
+  def path_islink(path):
+    return os.path.islink(path)
+
   def path_lexists(path):
     return os.path.lexists(path)
   
@@ -267,10 +270,14 @@ else:
   # os.path.isdir
   def path_isdir(path):
     return (shell.call(["test", "-d", path], sudo=True)[0] == 0)
+
+  # os.path.islink
+  def path_islink(path):
+    return (shell.call(["test", "-L", path], sudo=True)[0] == 0)
   
   # os.path.lexists
   def path_lexists(path):
-    return (shell.call(["test", "-L", path], sudo=True)[0] == 0)
+    return (shell.call(["test", "-e", path], sudo=True)[0] == 0)
   
   # os.readlink
   def readlink(path):

Reply via email to