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 <aonis...@hortonworks.com> Authored: Thu Feb 9 15:19:58 2017 +0200 Committer: Andrew Onishuk <aonis...@hortonworks.com> 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