ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [1/4] git commit: AMBARI-5644. For remote database configuration, ambari server script should not run DDL. Fix display text. (swagle)
Date Fri, 02 May 2014 00:57:46 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 548419513 -> ef80c0a97


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


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

Branch: refs/heads/trunk
Commit: cd50f5cdf0a0086650b954eeb02b437c12e6fbf9
Parents: 5484195
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu May 1 17:55:38 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu May 1 17:55:38 2014 -0700

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 91 ++++++--------------
 .../src/test/python/TestAmbariServer.py         | 36 +-------
 2 files changed, 29 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cd50f5cd/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 182bc38..36afa5a 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -1354,25 +1354,15 @@ def store_remote_properties(args):
 # Initialize remote database schema
 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
@@ -1386,8 +1376,9 @@ def get_db_cli_tool(args):
   return None
 
 
-#execute SQL script on remote database
+#execute SQL script on remote database: Deprecated
 def execute_remote_script(args, scriptPath):
+  print_warning_msg("Deprecated method called.")
   tool = get_db_cli_tool(args)
   if not tool:
     # 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...'
     retcode = setup_remote_db(args)
     if retcode == -1:
-      err = "The cli was not found"
+      err = "Remote database setup aborted."
       raise NonFatalException(err)
 
     if not retcode == 0:
@@ -2305,63 +2296,31 @@ def reset(args):
     err = "Ambari Server 'reset' cancelled"
     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()
   parse_properties_file(args)
 
-  # configure_database_username_password(args)
   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,
                                                      BLIND_PASSWORD, args.database_name)
     client_usage_cmd_init = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_INIT_SCRIPTS[DATABASE_INDEX],
args.database_username,
                                                      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:
+    # 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
     filename = args.drop_script_file
     username = args.database_username
@@ -2384,6 +2343,8 @@ def reset(args):
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
       else:
         raise NonFatalException("Non critical error in DDL")
+    pass
+  pass
 
 
 #

http://git-wip-us.apache.org/repos/asf/ambari/blob/cd50f5cd/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index be3c64a..53e090e 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -2333,7 +2333,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       result = ambari_server.setup(args)
       self.fail("Should throw exception")
     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, "get_YN_input")
@@ -2342,10 +2342,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "configure_database_username_password")
   @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "execute_remote_script")
   @patch.object(ambari_server, "is_root")
   @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,
                  run_os_command_mock, print_info_msg_mock,
                  setup_db_mock, get_YN_inputMock, is_server_running_mock):
@@ -2409,10 +2408,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     #remote db case
     args.persistence_type = "remote"
-    execute_remote_script_mock.return_value = (0, None, None)
     rcode = ambari_server.reset(args)
     self.assertEqual(None, rcode)
-    self.assertTrue(execute_remote_script_mock.called)
 
   @patch.object(ambari_server, "get_YN_input")
   @patch("__builtin__.raw_input")
@@ -3395,7 +3392,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       self.fail("Should throw exception")
     except NonFatalException as fe:
       # 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("sys.exit")
@@ -3463,33 +3460,6 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     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")
   def test_get_ambari_properties(self, find_properties_file_mock):


Mime
View raw message