|
@@ -32,10 +32,12 @@ class TestCheckHost(TestCase):
|
|
|
|
|
|
@patch("os.path.isfile")
|
|
@patch("os.path.isfile")
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(Script, 'get_config')
|
|
|
|
+ @patch.object(Script, 'get_tmp_dir')
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
- def testJavaHomeAvailableCheck(self, structured_out_mock, mock_config, os_isfile_mock):
|
|
|
|
|
|
+ def testJavaHomeAvailableCheck(self, structured_out_mock, get_tmp_dir_mock, mock_config, os_isfile_mock):
|
|
# test, java home exists
|
|
# test, java home exists
|
|
os_isfile_mock.return_value = True
|
|
os_isfile_mock.return_value = True
|
|
|
|
+ get_tmp_dir_mock.return_value = "/tmp"
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "java_home_check",
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "java_home_check",
|
|
"java_home" : "test_java_home"}}
|
|
"java_home" : "test_java_home"}}
|
|
|
|
|
|
@@ -57,12 +59,13 @@ class TestCheckHost(TestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(Script, 'get_config')
|
|
|
|
+ @patch.object(Script, 'get_tmp_dir')
|
|
@patch("check_host.Execute")
|
|
@patch("check_host.Execute")
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
@patch("subprocess.Popen")
|
|
@patch("subprocess.Popen")
|
|
@patch("check_host.format")
|
|
@patch("check_host.format")
|
|
@patch("os.path.isfile")
|
|
@patch("os.path.isfile")
|
|
- def testDBConnectionCheck(self, isfile_mock, format_mock, popenMock, structured_out_mock, execute_mock, mock_config):
|
|
|
|
|
|
+ def testDBConnectionCheck(self, isfile_mock, format_mock, popenMock, structured_out_mock, execute_mock, get_tmp_dir_mock, mock_config):
|
|
# test, download DBConnectionVerification.jar failed
|
|
# test, download DBConnectionVerification.jar failed
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
"java_home" : "test_java_home",
|
|
"java_home" : "test_java_home",
|
|
@@ -73,7 +76,7 @@ class TestCheckHost(TestCase):
|
|
"user_name" : "test_user_name",
|
|
"user_name" : "test_user_name",
|
|
"user_passwd" : "test_user_passwd",
|
|
"user_passwd" : "test_user_passwd",
|
|
"jdk_name" : "test_jdk_name"}}
|
|
"jdk_name" : "test_jdk_name"}}
|
|
-
|
|
|
|
|
|
+ get_tmp_dir_mock.return_value = "/tmp"
|
|
execute_mock.side_effect = Exception("test exception")
|
|
execute_mock.side_effect = Exception("test exception")
|
|
isfile_mock.return_value = True
|
|
isfile_mock.return_value = True
|
|
checkHost = CheckHost()
|
|
checkHost = CheckHost()
|
|
@@ -83,10 +86,10 @@ class TestCheckHost(TestCase):
|
|
'DBConnectionVerification.jar from Ambari Server resources. Check network access to Ambari ' \
|
|
'DBConnectionVerification.jar from Ambari Server resources. Check network access to Ambari ' \
|
|
'Server.\ntest exception', 'exit_code': 1}})
|
|
'Server.\ntest exception', 'exit_code': 1}})
|
|
|
|
|
|
- self.assertEquals(format_mock.call_args_list[1][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
|
|
|
|
|
|
+ self.assertEquals(format_mock.call_args_list[2][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
|
|
"--retry 5 {jdk_location}{check_db_connection_jar_name} -o {check_db_connection_jar_name}'")
|
|
"--retry 5 {jdk_location}{check_db_connection_jar_name} -o {check_db_connection_jar_name}'")
|
|
|
|
|
|
- self.assertEquals(format_mock.call_args_list[2][0][0], "[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]")
|
|
|
|
|
|
+ self.assertEquals(format_mock.call_args_list[3][0][0], "[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]")
|
|
|
|
|
|
# test, download jdbc driver failed
|
|
# test, download jdbc driver failed
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
@@ -111,10 +114,10 @@ class TestCheckHost(TestCase):
|
|
'Server host to make the JDBC driver available for download and to enable testing '
|
|
'Server host to make the JDBC driver available for download and to enable testing '
|
|
'the database connection.\n')
|
|
'the database connection.\n')
|
|
self.assertEquals(structured_out_mock.call_args[0][0]['db_connection_check']['exit_code'], 1)
|
|
self.assertEquals(structured_out_mock.call_args[0][0]['db_connection_check']['exit_code'], 1)
|
|
- self.assertEquals(format_mock.call_args_list[3][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
|
|
|
|
|
|
+ self.assertEquals(format_mock.call_args_list[4][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
|
|
"--retry 5 {jdbc_url} -o {jdbc_name}'")
|
|
"--retry 5 {jdbc_url} -o {jdbc_name}'")
|
|
|
|
|
|
- self.assertEquals(format_mock.call_args_list[4][0][0], "[ -f /usr/lib/ambari-agent/{jdbc_name}]")
|
|
|
|
|
|
+ self.assertEquals(format_mock.call_args_list[5][0][0], "[ -f /usr/lib/ambari-agent/{jdbc_name}]")
|
|
|
|
|
|
# test, no connection to remote db
|
|
# test, no connection to remote db
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
|
|
@@ -172,8 +175,9 @@ class TestCheckHost(TestCase):
|
|
|
|
|
|
@patch("socket.gethostbyname")
|
|
@patch("socket.gethostbyname")
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(Script, 'get_config')
|
|
|
|
+ @patch.object(Script, 'get_tmp_dir')
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
- def testHostResolution(self, structured_out_mock, mock_config, mock_socket):
|
|
|
|
|
|
+ def testHostResolution(self, structured_out_mock, get_tmp_dir_mock, mock_config, mock_socket):
|
|
mock_socket.return_value = "192.168.1.1"
|
|
mock_socket.return_value = "192.168.1.1"
|
|
jsonFilePath = os.path.join("../resources/custom_actions", "check_host_ip_addresses.json")
|
|
jsonFilePath = os.path.join("../resources/custom_actions", "check_host_ip_addresses.json")
|
|
|
|
|
|
@@ -181,7 +185,8 @@ class TestCheckHost(TestCase):
|
|
jsonPayload = json.load(jsonFile)
|
|
jsonPayload = json.load(jsonFile)
|
|
|
|
|
|
mock_config.return_value = ConfigDictionary(jsonPayload)
|
|
mock_config.return_value = ConfigDictionary(jsonPayload)
|
|
-
|
|
|
|
|
|
+ get_tmp_dir_mock.return_value = "/tmp"
|
|
|
|
+
|
|
checkHost = CheckHost()
|
|
checkHost = CheckHost()
|
|
checkHost.actionexecute(None)
|
|
checkHost.actionexecute(None)
|
|
|
|
|
|
@@ -209,15 +214,17 @@ class TestCheckHost(TestCase):
|
|
'failed_count': 5, 'success_count': 0, 'exit_code': 0}})
|
|
'failed_count': 5, 'success_count': 0, 'exit_code': 0}})
|
|
|
|
|
|
@patch.object(Script, 'get_config')
|
|
@patch.object(Script, 'get_config')
|
|
|
|
+ @patch.object(Script, 'get_tmp_dir')
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
@patch("resource_management.libraries.script.Script.put_structured_out")
|
|
- def testInvalidCheck(self, structured_out_mock, mock_config):
|
|
|
|
|
|
+ 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("../resources/custom_actions", "invalid_check.json")
|
|
|
|
|
|
with open(jsonFilePath, "r") as jsonFile:
|
|
with open(jsonFilePath, "r") as jsonFile:
|
|
jsonPayload = json.load(jsonFile)
|
|
jsonPayload = json.load(jsonFile)
|
|
|
|
|
|
mock_config.return_value = ConfigDictionary(jsonPayload)
|
|
mock_config.return_value = ConfigDictionary(jsonPayload)
|
|
-
|
|
|
|
|
|
+ get_tmp_dir_mock.return_value = "tmp"
|
|
|
|
+
|
|
checkHost = CheckHost()
|
|
checkHost = CheckHost()
|
|
checkHost.actionexecute(None)
|
|
checkHost.actionexecute(None)
|
|
|
|
|