Pārlūkot izejas kodu

AMBARI-5644. For remote database configuration, ambari server script should not run DDL. Fix display text. (swagle)

Siddharth Wagle 11 gadi atpakaļ
vecāks
revīzija
cd50f5cdf0

+ 26 - 65
ambari-server/src/main/python/ambari-server.py

@@ -1354,25 +1354,15 @@ def store_remote_properties(args):
 # Initialize remote database schema
 # Initialize remote database schema
 def setup_remote_db(args):
 def setup_remote_db(args):
 
 
-  not_found_msg = "Cannot find {0} {1} client in the path to load the Ambari Server schema.\
- Before starting Ambari Server, you must run the following DDL against the database to create \
-the schema ".format(DATABASE_NAMES[DATABASE_INDEX], str(DATABASE_CLI_TOOLS_DESC[DATABASE_INDEX]))
-  client_usage_cmd = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX], args.database_username,
-                                                     BLIND_PASSWORD, args.database_name)
+  setup_msg = "Before starting Ambari Server, you must run the following DDL " \
+              "against the database to create the schema: {0}".format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
 
 
-  retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
-  if retcode != 0:
-    if retcode == -1:
-      print_warning_msg(not_found_msg + os.linesep + client_usage_cmd)
-      if not SILENT:
-        raw_input(PRESS_ENTER_MSG)
-      return retcode
+  print_warning_msg(setup_msg)
 
 
-    print err
-    print_error_msg('Database bootstrap failed. Please, provide correct connection properties.')
-    return retcode
+  proceed = get_YN_input("Proceed with configuring remote database connection properties [y/n] (n)? ", True)
+  retCode = 0 if proceed else -1
 
 
-  return 0
+  return retCode
 
 
 
 
 # Get database client executable path
 # Get database client executable path
@@ -1386,8 +1376,9 @@ def get_db_cli_tool(args):
   return None
   return None
 
 
 
 
-#execute SQL script on remote database
+#execute SQL script on remote database: Deprecated
 def execute_remote_script(args, scriptPath):
 def execute_remote_script(args, scriptPath):
+  print_warning_msg("Deprecated method called.")
   tool = get_db_cli_tool(args)
   tool = get_db_cli_tool(args)
   if not tool:
   if not tool:
     # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
     # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
@@ -2264,7 +2255,7 @@ def setup(args):
     print 'Configuring remote database connection properties...'
     print 'Configuring remote database connection properties...'
     retcode = setup_remote_db(args)
     retcode = setup_remote_db(args)
     if retcode == -1:
     if retcode == -1:
-      err = "The cli was not found"
+      err = "Remote database setup aborted."
       raise NonFatalException(err)
       raise NonFatalException(err)
 
 
     if not retcode == 0:
     if not retcode == 0:
@@ -2305,63 +2296,31 @@ def reset(args):
     err = "Ambari Server 'reset' cancelled"
     err = "Ambari Server 'reset' cancelled"
     raise FatalException(1, err)
     raise FatalException(1, err)
 
 
-  okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), SILENT)
-
-  if not okToRun:
-    err = "Ambari Server 'reset' cancelled"
-    raise FatalException(1, err)
-
-  print "Resetting the Server database..."
-
   check_database_name_property()
   check_database_name_property()
   parse_properties_file(args)
   parse_properties_file(args)
 
 
-  # configure_database_username_password(args)
   if args.persistence_type == "remote":
   if args.persistence_type == "remote":
-    client_desc = DATABASE_NAMES[DATABASE_INDEX] + ' ' + DATABASE_CLI_TOOLS_DESC[DATABASE_INDEX]
     client_usage_cmd_drop = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_DROP_SCRIPTS[DATABASE_INDEX], args.database_username,
     client_usage_cmd_drop = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_DROP_SCRIPTS[DATABASE_INDEX], args.database_username,
                                                      BLIND_PASSWORD, args.database_name)
                                                      BLIND_PASSWORD, args.database_name)
     client_usage_cmd_init = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX], args.database_username,
     client_usage_cmd_init = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX], args.database_username,
                                                      BLIND_PASSWORD, args.database_name)
                                                      BLIND_PASSWORD, args.database_name)
 
 
-    if get_db_cli_tool(args) != -1:
-      retcode, out, err = execute_remote_script(args, DATABASE_DROP_SCRIPTS[DATABASE_INDEX])
-      if not retcode == 0:
-        if retcode == -1:
-          print_warning_msg('Cannot find ' + client_desc +
-                            ' client in the path to reset the Ambari Server ' +
-                            'schema. To reset Ambari Server schema ' +
-                            'you must run the following DDL against the database ' +
-                            'to drop the schema:' + os.linesep + client_usage_cmd_drop
-                            + os.linesep + 'Then you must run the following DDL '
-                            + 'against the database to create the schema: ' + os.linesep
-                             + client_usage_cmd_init + os.linesep)
-        raise NonFatalException(err)
-      if err:
-        print_warning_msg(err)
-      retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
-      if not retcode == 0:
-        if retcode == -1:
-          print_warning_msg('Cannot find ' + client_desc + ' client in the path to ' +
-                            'reset the Ambari Server schema. To reset Ambari Server schema ' +
-                            'you must run the following DDL against the database to '
-                            + 'drop the schema:' + os.linesep + client_usage_cmd_drop
-                            + os.linesep + 'Then you must run the following DDL ' +
-                            'against the database to create the schema: ' + os.linesep +
-                            client_usage_cmd_init + os.linesep)
-        raise NonFatalException(err)
-      if err:
-        print_warning_msg(err)
-    else:
-      err = 'Cannot find ' + client_desc + ' client in the path to reset the Ambari ' +\
-      'Server schema. To reset Ambari Server schema ' + \
-      'you must run the following DDL against the database to drop the schema:' + \
-      os.linesep + client_usage_cmd_drop + os.linesep +   \
-      'Then you must run the following DDL against the database to create the ' + \
-      'schema: ' + os.linesep + client_usage_cmd_init + os.linesep
-      raise NonFatalException(err)
-
+    print_warning_msg('To reset Ambari Server schema ' +
+                      'you must run the following DDL against the database to '
+                      + 'drop the schema:' + os.linesep + client_usage_cmd_drop
+                      + os.linesep + 'Then you must run the following DDL ' +
+                      'against the database to create the schema: ' + os.linesep +
+                      client_usage_cmd_init + os.linesep)
   else:
   else:
+    # Run automatic reset only for embedded DB
+    okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), SILENT)
+
+    if not okToRun:
+      err = "Ambari Server 'reset' cancelled"
+      raise FatalException(1, err)
+
+    print "Resetting the Server database..."
+
     dbname = args.database_name
     dbname = args.database_name
     filename = args.drop_script_file
     filename = args.drop_script_file
     username = args.database_username
     username = args.database_username
@@ -2384,6 +2343,8 @@ def reset(args):
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
       else:
       else:
         raise NonFatalException("Non critical error in DDL")
         raise NonFatalException("Non critical error in DDL")
+    pass
+  pass
 
 
 
 
 #
 #

+ 3 - 33
ambari-server/src/test/python/TestAmbariServer.py

@@ -2333,7 +2333,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       result = ambari_server.setup(args)
       result = ambari_server.setup(args)
       self.fail("Should throw exception")
       self.fail("Should throw exception")
     except NonFatalException as fe:
     except NonFatalException as fe:
-      self.assertTrue("cli was not found" in fe.reason)
+      self.assertTrue("Remote database setup aborted." in fe.reason)
 
 
   @patch.object(ambari_server, 'is_server_runing')
   @patch.object(ambari_server, 'is_server_runing')
   @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "get_YN_input")
@@ -2342,10 +2342,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "configure_database_username_password")
   @patch.object(ambari_server, "configure_database_username_password")
   @patch.object(ambari_server, "parse_properties_file")
   @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "execute_remote_script")
   @patch.object(ambari_server, "is_root")
   @patch.object(ambari_server, "is_root")
   @patch.object(ambari_server, "check_database_name_property")
   @patch.object(ambari_server, "check_database_name_property")
-  def test_reset(self, check_database_name_property_mock, is_root_mock, execute_remote_script_mock,
+  def test_reset(self, check_database_name_property_mock, is_root_mock,
                  parse_properties_file_mock, configure_database_username_password_mock,
                  parse_properties_file_mock, configure_database_username_password_mock,
                  run_os_command_mock, print_info_msg_mock,
                  run_os_command_mock, print_info_msg_mock,
                  setup_db_mock, get_YN_inputMock, is_server_running_mock):
                  setup_db_mock, get_YN_inputMock, is_server_running_mock):
@@ -2409,10 +2408,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
 
     #remote db case
     #remote db case
     args.persistence_type = "remote"
     args.persistence_type = "remote"
-    execute_remote_script_mock.return_value = (0, None, None)
     rcode = ambari_server.reset(args)
     rcode = ambari_server.reset(args)
     self.assertEqual(None, rcode)
     self.assertEqual(None, rcode)
-    self.assertTrue(execute_remote_script_mock.called)
 
 
   @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "get_YN_input")
   @patch("__builtin__.raw_input")
   @patch("__builtin__.raw_input")
@@ -3395,7 +3392,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       self.fail("Should throw exception")
       self.fail("Should throw exception")
     except NonFatalException as fe:
     except NonFatalException as fe:
       # Expected
       # Expected
-      self.assertTrue("The cli was not found" in fe.reason)
+      self.assertTrue("Remote database setup aborted." in fe.reason)
 
 
   @patch.object(ambari_server, 'verify_setup_allowed')
   @patch.object(ambari_server, 'verify_setup_allowed')
   @patch("sys.exit")
   @patch("sys.exit")
@@ -3463,33 +3460,6 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
 
     self.assertTrue(found)
     self.assertTrue(found)
 
 
-  @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "get_db_cli_tool")
-  @patch.object(ambari_server, "print_error_msg")
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "setup_db")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "check_database_name_property")
-  @patch.object(ambari_server, 'is_server_runing')
-  def test_reset_remote_db_wo_client(self, is_server_runing_mock, check_database_name_property_mock, is_root_mock, run_os_command_mock,
-                                     setup_db_mock,
-                                     get_YN_inputMock, print_error_msg_mock, get_db_cli_tool_mock,
-                                     parse_properties_file_mock):
-    args = MagicMock()
-    get_YN_inputMock.return_value = True
-    run_os_command_mock.return_value = (0, None, None)
-    args.persistence_type = "remote"
-    get_db_cli_tool_mock.return_value = None
-    is_root_mock.return_value = True
-    is_server_runing_mock.return_value = (False, 0)
-    try:
-      ambari_server.reset(args)
-      self.fail("Should throw exception")
-    except NonFatalException as fe:
-      # Expected
-      self.assertTrue("Client wasn't found" in fe.reason)
-      pass
 
 
   @patch.object(ambari_server, "find_properties_file")
   @patch.object(ambari_server, "find_properties_file")
   def test_get_ambari_properties(self, find_properties_file_mock):
   def test_get_ambari_properties(self, find_properties_file_mock):