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 2015/03/07 16:42:20 UTC

[2/2] ambari git commit: AMBARI-9975. Local unit tests failing in TestCheckHost.py (aonishuk)

AMBARI-9975. Local unit tests failing in TestCheckHost.py (aonishuk)


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

Branch: refs/heads/branch-2.0.0
Commit: 4db3c6b4f8a762c98c32973e41d32f30c35abb78
Parents: ee66656
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Sat Mar 7 17:42:02 2015 +0200
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Sat Mar 7 17:42:02 2015 +0200

----------------------------------------------------------------------
 .../src/test/python/custom_actions/TestCheckHost.py    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4db3c6b4/ambari-server/src/test/python/custom_actions/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
index 101eac9..ff16298 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -32,6 +32,7 @@ from unittest import TestCase
 from check_host import CheckHost
 
 from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
 
 if get_platform() != PLATFORM_WINDOWS:
   os_distro_value = ('Suse','11','Final')
@@ -39,7 +40,10 @@ else:
   os_distro_value = ('win2012serverr2','6.3','WindowsServer')
 
 
+@patch.object(HostCheckReportFileHandler, "writeHostChecksCustomActionsFile", new=MagicMock())
+@patch.object(HostCheckReportFileHandler, "resolve_ambari_config", new=MagicMock())
 class TestCheckHost(TestCase):
+  current_dir = os.path.dirname(os.path.realpath(__file__))
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("os.path.isfile")
   @patch.object(Script, 'get_config')
@@ -55,8 +59,6 @@ class TestCheckHost(TestCase):
     checkHost = CheckHost()
     checkHost.actionexecute(None)
 
-    print os_isfile_mock.call_args
-    self.assertEquals(os_isfile_mock.call_args[0][0], '/tmp/ambari-agent/hostcheck_custom_actions.result')
     self.assertEquals(structured_out_mock.call_args[0][0], {'java_home_check': {'message': 'Java home exists!',
                                                                                 'exit_code': 0}})
     # test, java home doesn't exist
@@ -65,7 +67,6 @@ class TestCheckHost(TestCase):
 
     checkHost.actionexecute(None)
 
-    self.assertEquals(os_isfile_mock.call_args[0][0], '/tmp/ambari-agent/hostcheck_custom_actions.result')
     self.assertEquals(structured_out_mock.call_args[0][0], {'java_home_check': {"message": "Java home doesn't exist!",
                                                                                 "exit_code" : 1}})
 
@@ -186,7 +187,7 @@ class TestCheckHost(TestCase):
   @patch("resource_management.libraries.script.Script.put_structured_out")
   def testHostResolution(self, structured_out_mock, get_tmp_dir_mock, mock_config, mock_socket):
     mock_socket.return_value = "192.168.1.1"    
-    jsonFilePath = os.path.join("../resources/custom_actions", "check_host_ip_addresses.json")
+    jsonFilePath = os.path.join(TestCheckHost.current_dir+"/../../resources/custom_actions", "check_host_ip_addresses.json")
     
     with open(jsonFilePath, "r") as jsonFile:
       jsonPayload = json.load(jsonFile)
@@ -225,7 +226,7 @@ class TestCheckHost(TestCase):
   @patch.object(Script, 'get_tmp_dir')
   @patch("resource_management.libraries.script.Script.put_structured_out")
   def testInvalidCheck(self, structured_out_mock, get_tmp_dir_mock, mock_config):
-    jsonFilePath = os.path.join("../resources/custom_actions", "invalid_check.json")
+    jsonFilePath = os.path.join(TestCheckHost.current_dir+"/../../resources/custom_actions", "invalid_check.json")
     
     with open(jsonFilePath, "r") as jsonFile:
       jsonPayload = json.load(jsonFile)
@@ -256,7 +257,7 @@ class TestCheckHost(TestCase):
   def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkIptables_mock, getTransparentHugePage_mock,
                        getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock,
                        get_tmp_dir_mock, get_config_mock, systemmock):
-    jsonFilePath = os.path.join("../resources/custom_actions", "check_last_agent_env.json")
+    jsonFilePath = os.path.join(TestCheckHost.current_dir+"/../../resources/custom_actions", "check_last_agent_env.json")
     with open(jsonFilePath, "r") as jsonFile:
       jsonPayload = json.load(jsonFile)