Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 38421200C16 for ; Thu, 9 Feb 2017 14:20:15 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 370CB160B64; Thu, 9 Feb 2017 13:20:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 88333160B4C for ; Thu, 9 Feb 2017 14:20:14 +0100 (CET) Received: (qmail 33074 invoked by uid 500); 9 Feb 2017 13:20:10 -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 32996 invoked by uid 99); 9 Feb 2017 13:20:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2017 13:20:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06EC7DFBDB; Thu, 9 Feb 2017 13:20:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aonishuk@apache.org To: commits@ambari.apache.org Date: Thu, 09 Feb 2017 13:20:10 -0000 Message-Id: <9a45db3760be48c5bdece494cde97307@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] ambari git commit: AMBARI-19941. Hive start fails in non-root if agent previously ran as root (aonishuk) archived-at: Thu, 09 Feb 2017 13:20:15 -0000 Repository: ambari Updated Branches: refs/heads/branch-2.5 a879b8ac4 -> 0ff74fc31 refs/heads/trunk 8561542e6 -> 10a0ba464 AMBARI-19941. Hive start fails in non-root if agent previously ran as root (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/10a0ba46 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/10a0ba46 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/10a0ba46 Branch: refs/heads/trunk Commit: 10a0ba464bf1575775b09c2b9e1f210c8dfaf549 Parents: 8561542 Author: Andrew Onishuk Authored: Thu Feb 9 15:19:58 2017 +0200 Committer: Andrew Onishuk Committed: Thu Feb 9 15:19:58 2017 +0200 ---------------------------------------------------------------------- .../python/resource_management/TestContentSources.py | 11 +++++++---- .../src/main/python/resource_management/core/source.py | 8 +++----- 2 files changed, 10 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/10a0ba46/ambari-agent/src/test/python/resource_management/TestContentSources.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestContentSources.py b/ambari-agent/src/test/python/resource_management/TestContentSources.py index 5f4ee06..eb5eee2 100644 --- a/ambari-agent/src/test/python/resource_management/TestContentSources.py +++ b/ambari-agent/src/test/python/resource_management/TestContentSources.py @@ -20,6 +20,13 @@ from unittest import TestCase from mock.mock import patch, MagicMock from only_for_platform import get_platform, not_for_platform, os_distro_value, PLATFORM_WINDOWS +import os + +if get_platform() != PLATFORM_WINDOWS: + with patch.object(os, "geteuid", return_value=0): + from resource_management.core import sudo + reload(sudo) + from ambari_commons.os_check import OSCheck from resource_management.core import Environment @@ -29,12 +36,8 @@ from resource_management.core.source import DownloadSource from resource_management.core.source import Template from resource_management.core.source import InlineTemplate -if get_platform() != PLATFORM_WINDOWS: - from resource_management.core import sudo - from ambari_jinja2 import UndefinedError, TemplateNotFound import urllib2 -import os @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) http://git-wip-us.apache.org/repos/asf/ambari/blob/10a0ba46/ambari-common/src/main/python/resource_management/core/source.py ---------------------------------------------------------------------- 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 916a618..cee6f57 100644 --- a/ambari-common/src/main/python/resource_management/core/source.py +++ b/ambari-common/src/main/python/resource_management/core/source.py @@ -25,6 +25,7 @@ from resource_management.core.environment import Environment from resource_management.core.logger import Logger from resource_management.core.exceptions import Fail from resource_management.core.utils import checked_unite +from resource_management.core import sudo __all__ = ["Source", "Template", "InlineTemplate", "StaticFile", "DownloadSource"] @@ -197,12 +198,9 @@ class DownloadSource(Source): content = web_file.read() if self.cache: - with open(filepath, 'w') as fp: - fp.write(content) + sudo.create_file(filepath, content) else: Logger.info("Not downloading the file from {0}, because {1} already exists".format(self.url, filepath)) - - with open(filepath) as fp: - content = fp.read() + content = sudo.read_file(filepath) return content