incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1491237 - in /incubator/ambari/trunk/ambari-server/src: main/python/ambari-server.py test/python/TestAmbaryServer.py
Date Sun, 09 Jun 2013 16:06:29 GMT
Author: mahadev
Date: Sun Jun  9 16:06:28 2013
New Revision: 1491237

URL: http://svn.apache.org/r1491237
Log:
AMBARI-2333. Cannot setup oracle or mysql w/o client library. (Oleksandr Diachenko via mahadev)

Modified:
    incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1491237&r1=1491236&r2=1491237&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Sun Jun  9 16:06:28
2013
@@ -73,6 +73,10 @@ ambari_provider_module = os.environ.get(
 STACK_NAME_VER_SEP = "-"
 JAVA_SHARE_PATH="/usr/share/java"
 
+# terminal styles
+BOLD_ON='\033[1m'
+BOLD_OFF='\033[0m'
+
 if ambari_provider_module is not None:
   ambari_provider_module_option = "-Dprovider.module.class=" +\
                                   ambari_provider_module + " "
@@ -996,15 +1000,23 @@ def reset(args):
     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 ' + DATABASE_NAMES[DATABASE_INDEX] + ' client in
the path, for reset please run the following DDL against the DB: ' +
+          DATABASE_DROP_SCRIPTS[DATABASE_INDEX] + ", then: " + DATABASE_INIT_SCRIPTS[DATABASE_INDEX],
True)
         print err
         return retcode
 
       retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
       if not retcode == 0:
+        if retcode == -1:
+          print_warning_msg('Cannot find ' + DATABASE_NAMES[DATABASE_INDEX] + ' client in
the path, for reset please run the following DDL against the DB: ' +
+          DATABASE_DROP_SCRIPTS[DATABASE_INDEX] + ", then: " + DATABASE_INIT_SCRIPTS[DATABASE_INDEX],
True)
         print err
         return retcode
 
     else:
+      print_warning_msg('Cannot find ' + DATABASE_NAMES[DATABASE_INDEX] + ' client in the
path, for reset please run the following DDL against the DB: ' +
+      DATABASE_INIT_SCRIPTS[DATABASE_INDEX] + ", then: " + DATABASE_DROP_SCRIPTS[DATABASE_INDEX],
True)
       print_error_msg(DATABASE_CLI_TOOLS[DATABASE_INDEX] + " not found. Unable to perform
automatic reset.")
       return -1
 
@@ -1166,7 +1178,6 @@ def print_info_msg(msg):
     print("INFO: " + msg)
 
 
-
 #
 # Prints an "error" messsage.
 #
@@ -1178,9 +1189,11 @@ def print_error_msg(msg):
 #
 # Prints a "warning" messsage.
 #
-def print_warning_msg(msg):
-  print("WARNING: " + msg)
-
+def print_warning_msg(msg, bold=False):
+  if bold:
+    print(BOLD_ON + "WARNING: " + msg + BOLD_OFF)
+  else:
+    print("WARNING: " + msg)
 
 
 #
@@ -1374,6 +1387,12 @@ def setup_remote_db(args):
 
   retcode, out, err = execute_remote_script(args, DATABASE_INIT_SCRIPTS[DATABASE_INDEX])
   if retcode != 0:
+
+    if retcode == -1:
+      print_warning_msg('Cannot find ' + DATABASE_NAMES[DATABASE_INDEX] + 
+                        ' client in the path, for setup please run the following DDL against
the DB: ' +
+                        DATABASE_INIT_SCRIPTS[DATABASE_INDEX], True)
+
     print err
     print_error_msg('Database bootstrap failed. Please, provide correct connection properties.')
     return retcode
@@ -1415,7 +1434,7 @@ def execute_remote_script(args, scriptPa
   if not tool:
     args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
     print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    return -1
+    return -1, "Client wasn't found", "Client wasn't found"
 
   if args.database == "postgres":
 
@@ -1449,7 +1468,7 @@ def execute_remote_script(args, scriptPa
     )))
     return retcode, out, err
 
-  return -1, "Wrong database", "Wrong database"
+  return -2, "Wrong database", "Wrong database"
 
 def configure_database_username_password(args):
   conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())

Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1491237&r1=1491236&r2=1491237&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Sun Jun  9 16:06:28
2013
@@ -1088,6 +1088,63 @@ class TestAmbariServer(TestCase):
 
     pass
 
+
+  @patch("sys.exit")
+  @patch.object(ambari_server, "get_db_cli_tool")
+  @patch.object(ambari_server, "store_remote_properties")
+  @patch.object(ambari_server, "is_local_database")
+  @patch.object(ambari_server, "check_iptables")
+
+  def test_setup_remote_db_wo_client(self, check_iptables_mock, is_local_db_mock,
+                                     store_remote_properties_mock, get_db_cli_tool_mock,
exit_mock):
+
+    out = StringIO.StringIO()
+    sys.stdout = out
+
+    args = MagicMock()
+
+    is_local_db_mock.return_value = False
+    check_iptables_mock.return_value = (0, "other")
+    store_remote_properties_mock.return_value = 0
+    get_db_cli_tool_mock.return_value = None
+
+    failed = False
+    result = None
+
+    try:
+      result = ambari_server.setup(args)
+    except Exception:
+      failed = True
+
+    self.assertEqual(False, failed)
+    self.assertEqual(None, result)
+    self.assertEqual(True, exit_mock.called)
+
+    sys.stdout = sys.__stdout__
+
+  @patch.object(ambari_server, "parse_properties")
+  @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")
+  def test_reset_remote_db_wo_client(self, run_os_command_mock, setup_db_mock,
+                                     get_YN_inputMock, print_error_msg_mock, get_db_cli_tool_mock,
parse_properties_mock):
+
+    out = StringIO.StringIO()
+    sys.stdout = out
+
+    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
+    rcode = ambari_server.reset(args)
+    self.assertEqual(-1, rcode)
+
+    sys.stdout = sys.__stdout__
+
+
   def get_sample(self, sample):
     """
     Returns sample file content as string with normalized line endings



Mime
View raw message