You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/06/09 18:07:34 UTC
svn commit: r1491239 - in
/incubator/ambari/branches/branch-1.2.4/ambari-server/src:
main/python/ambari-server.py test/python/TestAmbaryServer.py
Author: mahadev
Date: Sun Jun 9 16:07:33 2013
New Revision: 1491239
URL: http://svn.apache.org/r1491239
Log:
AMBARI-2333. Cannot setup oracle or mysql w/o client library. (Oleksandr Diachenko via mahadev)
Modified:
incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py?rev=1491239&r1=1491238&r2=1491239&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/python/ambari-server.py Sun Jun 9 16:07:33 2013
@@ -71,6 +71,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 + " "
@@ -892,15 +896,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
@@ -1055,7 +1067,6 @@ def print_info_msg(msg):
print("INFO: " + msg)
-
#
# Prints an "error" messsage.
#
@@ -1067,9 +1078,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)
#
@@ -1263,6 +1276,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
@@ -1304,7 +1323,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":
@@ -1338,7 +1357,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/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py?rev=1491239&r1=1491238&r2=1491239&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/test/python/TestAmbaryServer.py Sun Jun 9 16:07:33 2013
@@ -998,6 +998,61 @@ class TestAmbariServer(TestCase):
self.assertTrue(get_choice_string_input_mock.called)
self.assertEqual(4, len(get_choice_string_input_mock.call_args_list[0][0]))
+ @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):