You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2014/12/11 18:30:57 UTC
ambari git commit: AMBARI-8615. Fix restarting ambari-agent (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk 400b1af7e -> 79be85886
AMBARI-8615. Fix restarting ambari-agent (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/79be8588
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/79be8588
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/79be8588
Branch: refs/heads/trunk
Commit: 79be85886bbd457e49fd1ee5d14905f64e9c1890
Parents: 400b1af
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Thu Dec 11 19:30:47 2014 +0200
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Thu Dec 11 19:30:47 2014 +0200
----------------------------------------------------------------------
ambari-agent/src/main/python/ambari_agent/main.py | 8 ++++++--
ambari-agent/src/test/python/ambari_agent/TestMain.py | 10 ++++++----
2 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/79be8588/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index 5b1048b..80d0b77 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -37,6 +37,7 @@ import hostname
from DataCleaner import DataCleaner
import socket
from ambari_commons import OSConst, OSCheck
+from shell import shellRunner
from ambari_agent import shell
import HeartbeatHandlers
from HeartbeatHandlers import bind_signal_handlers
@@ -151,7 +152,8 @@ def stop_agent():
pid = f.read()
pid = int(pid)
f.close()
- os.kill(pid, signal.SIGTERM)
+ runner = shellRunner()
+ runner.run(['sudo', 'kill', '-15', str(pid)])
time.sleep(5)
if os.path.exists(ProcessHelper.pidfile):
raise Exception("PID file still exists.")
@@ -160,7 +162,9 @@ def stop_agent():
if pid == -1:
print ("Agent process is not running")
else:
- os.kill(pid, signal.SIGKILL)
+ res = runner.run(['sudo', 'kill', '-9', str(pid)])
+ if res['exitCode'] != 0:
+ raise Exception("Error while performing agent stop. " + res['error'] + res['output'])
os._exit(1)
def reset_agent(options):
http://git-wip-us.apache.org/repos/asf/ambari/blob/79be8588/ambari-agent/src/test/python/ambari_agent/TestMain.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestMain.py b/ambari-agent/src/test/python/ambari_agent/TestMain.py
index f599dac..dce94df 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -38,6 +38,7 @@ with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
from ambari_agent.Controller import Controller
from ambari_agent.DataCleaner import DataCleaner
import ambari_agent.HeartbeatHandlers as HeartbeatHandlers
+ from ambari_agent.shell import shellRunner
class TestMain(unittest.TestCase):
@@ -189,7 +190,7 @@ class TestMain(unittest.TestCase):
@patch("time.sleep")
- @patch("os.kill")
+ @patch.object(shellRunner,"run")
@patch("os._exit")
@patch("os.path.exists")
def test_daemonize_and_stop(self, exists_mock, _exit_mock, kill_mock, sleep_mock):
@@ -207,18 +208,19 @@ class TestMain(unittest.TestCase):
# Testing normal exit
exists_mock.return_value = False
main.stop_agent()
- kill_mock.assert_called_with(int(pid), signal.SIGTERM)
+ kill_mock.assert_called_with(['sudo', 'kill', '-15', pid])
_exit_mock.assert_called_with(0)
# Restore
kill_mock.reset_mock()
_exit_mock.reset_mock()
+ kill_mock.return_value = {'exitCode': 0, 'output': 'out', 'error': 'err'}
# Testing exit when failed to remove pid file
exists_mock.return_value = True
main.stop_agent()
- kill_mock.assert_any_call(int(pid), signal.SIGTERM)
- kill_mock.assert_any_call(int(pid), signal.SIGKILL)
+ kill_mock.assert_any_call(['sudo', 'kill', '-15', pid])
+ kill_mock.assert_any_call(['sudo', 'kill', '-9', pid])
_exit_mock.assert_called_with(1)
# Restore