From commits-return-52003-archive-asf-public=cust-asf.ponee.io@ambari.apache.org Tue Mar 20 15:47:28 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id F422818064A for ; Tue, 20 Mar 2018 15:47:27 +0100 (CET) Received: (qmail 53566 invoked by uid 500); 20 Mar 2018 14:47:27 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 53557 invoked by uid 99); 20 Mar 2018 14:47:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2018 14:47:27 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 59E5B808B6; Tue, 20 Mar 2018 14:47:26 +0000 (UTC) Date: Tue, 20 Mar 2018 14:47:26 +0000 To: "commits@ambari.apache.org" Subject: [ambari] branch trunk updated: AMBARI-23305. Grafana install fails with "KeyError: 'getpwnam(): name not found: ams'" (aonishuk) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <152155724627.17842.13492404269592552089@gitbox.apache.org> From: aonishuk@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: ambari X-Git-Refname: refs/heads/trunk X-Git-Reftype: branch X-Git-Oldrev: ee0784a9b3393eb0c76f0ce0bd7ed4ea775864df X-Git-Newrev: d7b93999d7891f830193e2f85230af4f8645d14e X-Git-Rev: d7b93999d7891f830193e2f85230af4f8645d14e X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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.