Repository: ambari Updated Branches: refs/heads/trunk f42378ec9 -> 45f2c9169
AMBARI-8663. pam_authenticate: Conversation error during deploy on suse (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/45f2c916 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/45f2c916 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/45f2c916 Branch: refs/heads/trunk Commit: 45f2c9169a391886c0f321bc6c6d65956bda68bf Parents: f42378e Author: Andrew Onishuk <aonis...@hortonworks.com> Authored: Thu Dec 11 19:39:50 2014 +0200 Committer: Andrew Onishuk <aonis...@hortonworks.com> Committed: Thu Dec 11 19:39:50 2014 +0200 ---------------------------------------------------------------------- ambari-agent/conf/unix/ambari-agent | 4 ++-- .../src/test/python/ambari_agent/TestAlerts.py | 1 - .../resource_management/TestContentSources.py | 1 - .../resource_management/TestExecuteResource.py | 18 +++++++-------- .../resource_management/TestGroupResource.py | 12 ++++++---- .../TestMonitorWebserverResource.py | 1 - .../resource_management/TestSubstituteVars.py | 1 - .../resource_management/TestUserResource.py | 24 +++++++++++--------- .../python/resource_management/core/shell.py | 23 +++++++++---------- .../python/stacks/1.3.2/HDFS/test_datanode.py | 4 ++-- .../python/stacks/2.0.6/HDFS/test_datanode.py | 8 +++---- 11 files changed, 48 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/conf/unix/ambari-agent ---------------------------------------------------------------------- diff --git a/ambari-agent/conf/unix/ambari-agent b/ambari-agent/conf/unix/ambari-agent index 30acd65..f14c584 100755 --- a/ambari-agent/conf/unix/ambari-agent +++ b/ambari-agent/conf/unix/ambari-agent @@ -33,7 +33,7 @@ case "$1" in ;; esac -export PATH=/usr/lib/ambari-server/*:$PATH +export PATH=/usr/sbin:/sbin:/usr/lib/ambari-server/*:$PATH export AMBARI_CONF_DIR=/etc/ambari-server/conf:$PATH # Because Ambari rpm unpacks modules here on all systems @@ -48,7 +48,7 @@ AMBARI_AGENT_PY_SCRIPT=/usr/lib/python2.6/site-packages/ambari_agent/AmbariAgent OK=1 NOTOK=0 -sudo -v +echo "" | sudo -S -l > /dev/null 2>&1 if [ "$?" != "0" ]; then echo "You can't perform this operation as non-sudoer user. Please, re-login as one" exit 0 http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/ambari_agent/TestAlerts.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py index a7814c0..96be539 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py +++ b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py @@ -18,7 +18,6 @@ See the License for the specific language governing permissions and limitations under the License. ''' -from stacks.utils.RMFTestCase import * import os import socket import sys http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/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 d09df44..651ff83 100644 --- a/ambari-agent/src/test/python/resource_management/TestContentSources.py +++ b/ambari-agent/src/test/python/resource_management/TestContentSources.py @@ -16,7 +16,6 @@ See the License for the specific language governing permissions and limitations under the License. ''' -from stacks.utils.RMFTestCase import * from unittest import TestCase from mock.mock import patch, MagicMock http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/resource_management/TestExecuteResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py index 4bb1404..fb1c11c 100644 --- a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py +++ b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py @@ -90,7 +90,7 @@ class TestExecuteResource(TestCase): execute_resource = Execute('echo "1"', path=["/test/one", "test/two"] ) - expected_command = ['/bin/bash', '--login', '-c', 'echo "1"'] + expected_command = ['/bin/bash', '--login', '--noprofile', '-c', 'echo "1"'] self.assertEqual(popen_mock.call_args_list[0][0][0], expected_command) @patch('time.sleep') @@ -178,7 +178,7 @@ class TestExecuteResource(TestCase): ) - expected_command = ['/bin/bash', '--login', '-c', '/usr/bin/sudo su test_user -l -s /bin/bash -c \'export PATH=' + os.environ['PATH'] + ':/bin JAVA_HOME=/test/java/home > /dev/null ; echo "1"\''] + expected_command = ['/bin/bash', '--login', '--noprofile', '-c', '/usr/bin/sudo su test_user -l -s /bin/bash -c \'export PATH=' + os.environ['PATH'] + ':/bin JAVA_HOME=/test/java/home > /dev/null ; echo "1"\''] self.assertEqual(popen_mock.call_args_list[0][0][0], expected_command) @@ -225,12 +225,12 @@ class TestExecuteResource(TestCase): Execute(('arg1', 'arg2', "`ls /root`"), ) - self.assertEqual(popen_mock.call_args_list[0][0][0][3], expected_command0) - self.assertEqual(popen_mock.call_args_list[1][0][0][3], expected_command1) - self.assertEqual(popen_mock.call_args_list[2][0][0][3], expected_command2) - self.assertEqual(popen_mock.call_args_list[3][0][0][3], expected_command3) - self.assertEqual(popen_mock.call_args_list[4][0][0][3], expected_command4) - self.assertEqual(popen_mock.call_args_list[5][0][0][3], expected_command5) + self.assertEqual(popen_mock.call_args_list[0][0][0][4], expected_command0) + self.assertEqual(popen_mock.call_args_list[1][0][0][4], expected_command1) + self.assertEqual(popen_mock.call_args_list[2][0][0][4], expected_command2) + self.assertEqual(popen_mock.call_args_list[3][0][0][4], expected_command3) + self.assertEqual(popen_mock.call_args_list[4][0][0][4], expected_command4) + self.assertEqual(popen_mock.call_args_list[5][0][0][4], expected_command5) @patch.object(subprocess, "Popen") def test_attribute_command_one_line(self, popen_mock): @@ -243,4 +243,4 @@ class TestExecuteResource(TestCase): with Environment("/") as env: Execute(expected_command) - self.assertEqual(popen_mock.call_args_list[0][0][0][3], expected_command) + self.assertEqual(popen_mock.call_args_list[0][0][0][4], expected_command) http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/resource_management/TestGroupResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestGroupResource.py b/ambari-agent/src/test/python/resource_management/TestGroupResource.py index bc037f1..29decbb 100644 --- a/ambari-agent/src/test/python/resource_management/TestGroupResource.py +++ b/ambari-agent/src/test/python/resource_management/TestGroupResource.py @@ -24,9 +24,11 @@ from resource_management.core.system import System import subprocess import grp +import os @patch.object(System, "os_family", new = 'redhat') +@patch.object(os, "environ", new = {'PATH':'/bin'}) class TestGroupResource(TestCase): @patch.object(grp, "getgrnam") @@ -45,7 +47,7 @@ class TestGroupResource(TestCase): self.assertEqual(popen_mock.call_count, 1) - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H groupadd -p secure hadoop"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E groupadd -p secure hadoop"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) getgrnam_mock.assert_called_with('hadoop') @@ -66,7 +68,7 @@ class TestGroupResource(TestCase): self.assertEqual(popen_mock.call_count, 1) - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H groupmod -p secure -g 2 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E groupmod -p secure -g 2 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) getgrnam_mock.assert_called_with('mapred') @@ -90,7 +92,7 @@ class TestGroupResource(TestCase): except Fail: pass self.assertEqual(popen_mock.call_count, 1) - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H groupmod -p secure -g 2 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E groupmod -p secure -g 2 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) getgrnam_mock.assert_called_with('mapred') @@ -110,7 +112,7 @@ class TestGroupResource(TestCase): self.assertEqual(popen_mock.call_count, 1) - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'groupdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', 'groupdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) getgrnam_mock.assert_called_with('mapred') @@ -134,5 +136,5 @@ class TestGroupResource(TestCase): pass self.assertEqual(popen_mock.call_count, 1) - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'groupdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', 'groupdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) getgrnam_mock.assert_called_with('mapred') http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py b/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py index d5b2c42..533ecaa 100644 --- a/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py +++ b/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py @@ -16,7 +16,6 @@ See the License for the specific language governing permissions and limitations under the License. ''' -from stacks.utils.RMFTestCase import * from unittest import TestCase from mock.mock import patch, MagicMock from resource_management import * http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/resource_management/TestSubstituteVars.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestSubstituteVars.py b/ambari-agent/src/test/python/resource_management/TestSubstituteVars.py index 9e42f92..2e7bc59 100644 --- a/ambari-agent/src/test/python/resource_management/TestSubstituteVars.py +++ b/ambari-agent/src/test/python/resource_management/TestSubstituteVars.py @@ -18,7 +18,6 @@ See the License for the specific language governing permissions and limitations under the License. ''' -from stacks.utils.RMFTestCase import * from unittest import TestCase, main from resource_management.libraries.functions.substitute_vars import substitute_vars http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-agent/src/test/python/resource_management/TestUserResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestUserResource.py b/ambari-agent/src/test/python/resource_management/TestUserResource.py index f21a3c5..458053b 100644 --- a/ambari-agent/src/test/python/resource_management/TestUserResource.py +++ b/ambari-agent/src/test/python/resource_management/TestUserResource.py @@ -24,8 +24,10 @@ from resource_management.core.system import System from resource_management.core.resources import User import pwd import subprocess +import os @patch.object(System, "os_family", new = 'redhat') +@patch.object(os, "environ", new = {'PATH':'/bin'}) class TestUserResource(TestCase): @patch.object(subprocess, "Popen") @@ -38,7 +40,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H useradd -m -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E useradd -m -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -52,7 +54,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -66,7 +68,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "remove", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'userdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', 'userdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -81,7 +83,7 @@ class TestUserResource(TestCase): user = User("mapred", action = "create", comment = "testComment", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -c testComment -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -c testComment -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -96,7 +98,7 @@ class TestUserResource(TestCase): user = User("mapred", action = "create", home = "/test/home", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/bash -d /test/home mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/bash -d /test/home mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -111,7 +113,7 @@ class TestUserResource(TestCase): user = User("mapred", action = "create", password = "secure", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/bash -p secure mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/bash -p secure mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -125,7 +127,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create", shell = "/bin/sh") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/sh mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/sh mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -139,7 +141,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create", uid = "1", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/bash -u 1 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/bash -u 1 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -153,7 +155,7 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create", gid = "1", shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -s /bin/bash -g 1 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -s /bin/bash -g 1 mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -168,7 +170,7 @@ class TestUserResource(TestCase): user = User("mapred", action = "create", groups = ['1','2','3'], shell = "/bin/bash") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H usermod -G 1,2,3 -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E usermod -G 1,2,3 -s /bin/bash mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) @patch.object(subprocess, "Popen") @@ -181,5 +183,5 @@ class TestUserResource(TestCase): with Environment('/') as env: user = User("mapred", action = "create") - popen_mock.assert_called_with(['/bin/bash', '--login', '-c', "/usr/bin/sudo -H useradd -m mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={}, cwd=None) + popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E useradd -m mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-common/src/main/python/resource_management/core/shell.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/core/shell.py b/ambari-common/src/main/python/resource_management/core/shell.py index cd8b05b..ef44ca4 100644 --- a/ambari-common/src/main/python/resource_management/core/shell.py +++ b/ambari-common/src/main/python/resource_management/core/shell.py @@ -34,15 +34,15 @@ from resource_management.core.logger import Logger SUDO_ENVIRONMENT_PLACEHOLDER = "{ENV_PLACEHOLDER}" def checked_call(command, verbose=False, logoutput=False, - cwd=None, env={}, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): + cwd=None, env=None, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): return _call(command, verbose, logoutput, True, cwd, env, preexec_fn, user, wait_for_finish, timeout, path, output_file, sudo) def call(command, verbose=False, logoutput=False, - cwd=None, env={}, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): + cwd=None, env=None, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): return _call(command, verbose, logoutput, False, cwd, env, preexec_fn, user, wait_for_finish, timeout, path, output_file, sudo) def _call(command, verbose=False, logoutput=False, throw_on_failure=True, - cwd=None, env={}, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): + cwd=None, env=None, preexec_fn=None, user=None, wait_for_finish=True, timeout=None, path=None, output_file=None, sudo=False): """ Execute shell command @@ -53,16 +53,14 @@ def _call(command, verbose=False, logoutput=False, throw_on_failure=True, @return: retrun_code, stdout """ - + # Append current PATH to env['PATH'] and path - if 'PATH' in env: - env['PATH'] = os.pathsep.join([os.environ['PATH'], env['PATH']]) + env = {} if not env else env + env['PATH'] = os.pathsep.join([os.environ['PATH'], env['PATH']]) if 'PATH' in env else os.environ['PATH'] if path: - if not 'PATH' in env: - env['PATH'] = '' path = os.pathsep.join(path) if isinstance(path, (list, tuple)) else path - env['PATH'] = os.pathsep.join([os.environ['PATH'], path]) - + env['PATH'] = os.pathsep.join([env['PATH'], path]) + # prepare command cmd if sudo: command = as_sudo(command, env=env) @@ -77,7 +75,8 @@ def _call(command, verbose=False, logoutput=False, throw_on_failure=True, if verbose: Logger.info("Call command: " + Logger.get_protected_text(command)) - subprocess_command = ["/bin/bash","--login","-c", command] + # --noprofile is used to preserve PATH set for ambari-agent + subprocess_command = ["/bin/bash","--login","--noprofile","-c", command] proc = subprocess.Popen(subprocess_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd, env=env, shell=False, preexec_fn=preexec_fn) @@ -129,7 +128,7 @@ def as_sudo(command, env=SUDO_ENVIRONMENT_PLACEHOLDER): raise Fail(err_msg) env = get_environment_str(env) if env != SUDO_ENVIRONMENT_PLACEHOLDER else SUDO_ENVIRONMENT_PLACEHOLDER - return "/usr/bin/sudo {0} -H {1}".format(env, command) + return "/usr/bin/sudo {0} -H -E {1}".format(env, command) def as_user(command, user , env=SUDO_ENVIRONMENT_PLACEHOLDER): if isinstance(command, (list, tuple)): http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py b/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py index a896d02..7054eef 100644 --- a/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py +++ b/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py @@ -110,7 +110,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/lib/hadoop/bin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/lib/hadoop/bin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/lib/hadoop/libexec'}, not_if = 'ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) @@ -134,7 +134,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/lib/hadoop/bin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/lib/hadoop/bin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/lib/hadoop/libexec'}, not_if = None, ) http://git-wip-us.apache.org/repos/asf/ambari/blob/45f2c916/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py index 424649c..18cb30d 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py @@ -129,7 +129,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/lib/hadoop/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/lib/hadoop/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/lib/hadoop/libexec'}, not_if = 'ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) @@ -165,7 +165,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/hdp/current/hadoop-client/libexec'}, not_if = 'ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) @@ -234,7 +234,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/lib/hadoop/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/lib/hadoop/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/lib/hadoop/libexec'}, not_if = None, ) @@ -274,7 +274,7 @@ class TestDatanode(RMFTestCase): action = ['delete'], not_if='ls /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid >/dev/null 2>&1 && ps -p `cat /var/run/hadoop/hdfs/hadoop-hdfs-datanode.pid` >/dev/null 2>&1', ) - self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', + self.assertResourceCalled('Execute', '/usr/bin/sudo {ENV_PLACEHOLDER} -H -E /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode', environment = {'HADOOP_LIBEXEC_DIR': '/usr/hdp/current/hadoop-client/libexec'}, not_if = None, )