Pārlūkot izejas kodu

AMBARI-12275. if any error comes while test connection of ranger DB then it display password in logs (aonishuk)

Andrew Onishuk 10 gadi atpakaļ
vecāks
revīzija
3568d7176b

+ 8 - 15
ambari-server/src/main/resources/custom_actions/scripts/check_host.py

@@ -34,6 +34,7 @@ from ambari_agent.HostInfo import HostInfo
 from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
 from resource_management.core.resources import Directory, File
 from ambari_commons.constants import AMBARI_SUDO_BINARY
+from resource_management.core import shell
 
 CHECK_JAVA_HOME = "java_home_check"
 CHECK_DB_CONNECTION = "db_connection_check"
@@ -317,27 +318,19 @@ class CheckHost(Script):
       print message
       db_connection_check_structured_output = {"exit_code" : 1, "message": message}
       return db_connection_check_structured_output
-  
-  
+
+
     # try to connect to db
     db_connection_check_command = format("{java_exec} -cp {check_db_connection_path}{class_path_delimiter}" \
            "{jdbc_path} -Djava.library.path={agent_cache_dir} org.apache.ambari.server.DBConnectionVerification \"{db_connection_url}\" " \
            "{user_name} {user_passwd!p} {jdbc_driver}")
-    print "INFO db_connection_check_command: " + db_connection_check_command
-    process = subprocess.Popen(db_connection_check_command,
-                               stdout=subprocess.PIPE,
-                               stdin=subprocess.PIPE,
-                               stderr=subprocess.PIPE,
-                               shell=True)
-    (stdoutdata, stderrdata) = process.communicate()
-    print "INFO stdoutdata: " + stdoutdata
-    print "INFO stderrdata: " + stderrdata
-    print "INFO returncode: " + str(process.returncode)
-  
-    if process.returncode == 0:
+
+    code, out = shell.call(db_connection_check_command)
+
+    if code == 0:
       db_connection_check_structured_output = {"exit_code" : 0, "message": "DB connection check completed successfully!" }
     else:
-      db_connection_check_structured_output = {"exit_code" : 1, "message":  stdoutdata + stderrdata }
+      db_connection_check_structured_output = {"exit_code" : 1, "message":  out }
   
     return db_connection_check_structured_output
 

+ 4 - 7
ambari-server/src/test/python/custom_actions/TestCheckHost.py

@@ -75,10 +75,10 @@ class TestCheckHost(TestCase):
   @patch.object(Script, 'get_tmp_dir')
   @patch("check_host.download_file")
   @patch("resource_management.libraries.script.Script.put_structured_out")
-  @patch("subprocess.Popen")
   @patch("check_host.format")
   @patch("os.path.isfile")
-  def testDBConnectionCheck(self, isfile_mock, format_mock, popenMock, structured_out_mock, download_file_mock, get_tmp_dir_mock, mock_config):
+  @patch("resource_management.core.shell.call")
+  def testDBConnectionCheck(self, shell_call_mock, isfile_mock, format_mock, structured_out_mock, download_file_mock, get_tmp_dir_mock, mock_config):
     # test, download DBConnectionVerification.jar failed
     mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
                                                    "java_home" : "test_java_home",
@@ -139,10 +139,7 @@ class TestCheckHost(TestCase):
     format_mock.reset_mock()
     download_file_mock.reset_mock()
     download_file_mock.side_effect = [p, p]
-    s = MagicMock()
-    s.communicate.return_value = ("test message", "")
-    s.returncode = 1
-    popenMock.return_value = s
+    shell_call_mock.return_value = (1, "test message")
 
     checkHost.actionexecute(None)
 
@@ -156,7 +153,7 @@ class TestCheckHost(TestCase):
     # test, db connection success
     download_file_mock.reset_mock()
     download_file_mock.side_effect = [p, p]
-    s.returncode = 0
+    shell_call_mock.return_value = (0, "test message")
 
     checkHost.actionexecute(None)