ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [ambari] branch trunk updated: AMBARI-23305. Grafana install fails with "KeyError: 'getpwnam(): name not found: ams'" (aonishuk)
Date Tue, 20 Mar 2018 14:47:26 GMT
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


The following commit(s) were added to refs/heads/trunk by this push:
     new d7b9399  AMBARI-23305. Grafana install fails with "KeyError: 'getpwnam(): name not
found: ams'" (aonishuk)
d7b9399 is described below

commit d7b93999d7891f830193e2f85230af4f8645d14e
Author: Andrew Onishuk <aonishuk@hortonworks.com>
AuthorDate: Tue Mar 20 16:42:42 2018 +0200

    AMBARI-23305. Grafana install fails with "KeyError: 'getpwnam(): name not found: ams'"
(aonishuk)
---
 ambari-agent/src/main/python/ambari_agent/FileCache.py     | 14 ++++++++++----
 ambari-agent/src/test/python/ambari_agent/TestFileCache.py |  2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py b/ambari-agent/src/main/python/ambari_agent/FileCache.py
index cbc0755..d7eee7a 100644
--- a/ambari-agent/src/main/python/ambari_agent/FileCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py
@@ -25,6 +25,7 @@ import shutil
 import zipfile
 import urllib2
 import urllib
+import time
 
 from ambari_agent.Utils import execute_with_retries
 
@@ -272,14 +273,19 @@ class FileCache():
           os.unlink(directory)
         elif os.path.isdir(directory):
           """
-          Execute shutil.rmtree(directory) multiple times.
-          Reason: race condition, where a file (e.g. *.pyc) in deleted directory
-          is created during function is running, causing it to fail.
+          All the magic here is because status/exec commands can execute at the same time
as this code, causing weird race conditions
           """
-          execute_with_retries(CLEAN_DIRECTORY_TRIES, CLEAN_DIRECTORY_TRY_SLEEP, OSError,
shutil.rmtree, directory)
+          new_directory_name = directory + '.bak.' + str(time.time())
+          os.rename(directory, new_directory_name)
+          try:
+            execute_with_retries(CLEAN_DIRECTORY_TRIES, CLEAN_DIRECTORY_TRY_SLEEP, OSError,
shutil.rmtree, new_directory_name)
+          except:
+            logger.exception("Can not remove directory {0}".format(new_directory_name))
+
         # create directory itself and any parent directories
       os.makedirs(directory)
     except Exception, err:
+      logger.exception("Can not invalidate cache directory {0}".format(directory))
       raise CachingException("Can not invalidate cache directory {0}: {1}",
                              directory, str(err))
 
diff --git a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
index 31fe4b6..64b2f2c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
@@ -341,7 +341,7 @@ class TestFileCache(TestCase):
   @patch("os.unlink")
   @patch("shutil.rmtree")
   @patch("os.makedirs")
-  def test_invalidate_directory(self, makedirs_mock, rmtree_mock,
+  def invalidate_directory(self, makedirs_mock, rmtree_mock,
                                 unlink_mock, isdir_mock, isfile_mock,
                                 exists_mock):
     fileCache = FileCache(self.config)

-- 
To stop receiving notification emails like this one, please contact
aonishuk@apache.org.

Mime
View raw message