You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/03/20 21:08:13 UTC

ambari git commit: AMBARI-10148 Unit test failure in test_daemonize_and_stop

Repository: ambari
Updated Branches:
  refs/heads/trunk 52e8e9b2a -> 2bb070b6d


AMBARI-10148 Unit test failure in test_daemonize_and_stop

Fixed Agent code. Fixed mocks in TestMain.py.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2bb070b6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2bb070b6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2bb070b6

Branch: refs/heads/trunk
Commit: 2bb070b6d67764fec7e142f71a5ad35a15bf044d
Parents: 52e8e9b
Author: Florian Barca <fb...@hortonworks.com>
Authored: Fri Mar 20 13:06:52 2015 -0700
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Fri Mar 20 13:07:43 2015 -0700

----------------------------------------------------------------------
 ambari-agent/src/main/python/ambari_agent/main.py     |  2 +-
 ambari-agent/src/test/python/ambari_agent/TestMain.py | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2bb070b6/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 23f575b..fe95e1a 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -148,12 +148,12 @@ def daemonize():
 def stop_agent():
 # stop existing Ambari agent
   pid = -1
+  runner = shellRunner()
   try:
     f = open(ProcessHelper.pidfile, 'r')
     pid = f.read()
     pid = int(pid)
     f.close()
-    runner = shellRunner()
     runner.run([AMBARI_SUDO_BINARY, 'kill', '-15', str(pid)])
     time.sleep(5)
     if os.path.exists(ProcessHelper.pidfile):

http://git-wip-us.apache.org/repos/asf/ambari/blob/2bb070b6/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 23d532a..3bca7de 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -28,7 +28,7 @@ import tempfile
 import ConfigParser
 
 from ambari_commons import OSCheck
-from only_for_platform import only_for_platform, get_platform, PLATFORM_WINDOWS, PLATFORM_LINUX
+from only_for_platform import get_platform, not_for_platform, only_for_platform, PLATFORM_WINDOWS, PLATFORM_LINUX
 from mock.mock import MagicMock, patch, ANY, Mock
 
 if get_platform() != PLATFORM_WINDOWS:
@@ -46,7 +46,8 @@ with patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_
   import ambari_agent.HeartbeatHandlers as HeartbeatHandlers
   from ambari_commons.os_check import OSConst, OSCheck
 
-  from ambari_commons.shell import shellRunner
+  if get_platform() != PLATFORM_WINDOWS:
+    from ambari_commons.shell import shellRunnerLinux
 
 class TestMain(unittest.TestCase):
 
@@ -82,7 +83,8 @@ class TestMain(unittest.TestCase):
   @patch.object(main.logger, "addHandler")
   @patch.object(main.logger, "setLevel")
   @patch("logging.handlers.RotatingFileHandler")
-  def test_setup_logging(self, rfh_mock, setLevel_mock, addHandler_mock):
+  @patch("logging.basicConfig")
+  def test_setup_logging(self, basicConfig_mock, rfh_mock, setLevel_mock, addHandler_mock):
     # Testing silent mode
     main.setup_logging(False)
     self.assertTrue(addHandler_mock.called)
@@ -199,9 +201,10 @@ class TestMain(unittest.TestCase):
     main.perform_prestart_checks(None)
     self.assertFalse(exit_mock.called)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("time.sleep")
-  @patch.object(shellRunner,"run")
+  @patch.object(shellRunnerLinux,"run")
   @patch("sys.exit")
   @patch("os.path.exists")
   def test_daemonize_and_stop(self, exists_mock, sys_exit_mock, kill_mock, sleep_mock):