You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/06/09 22:45:18 UTC
svn commit: r1491291 - in
/incubator/ambari/branches/branch-1.2.4/ambari-server/src:
main/python/ambari-server.py test/python/TestAmbaryServer.py
Author: smohanty
Date: Sun Jun 9 20:45:18 2013
New Revision: 1491291
URL: http://svn.apache.org/r1491291
Log:
AMBARI-2334. When setup for oracle, postgres should not be started. (Myroslav Papirkovskyy via smohanty)
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=1491291&r1=1491290&r2=1491291&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 20:45:18 2013
@@ -889,7 +889,7 @@ def reset(args):
print "Reseting the Server database..."
- parse_properties(args)
+ parse_properties_file(args)
# configure_database_username_password(args)
if args.persistence_type=="remote":
@@ -939,6 +939,7 @@ def reset(args):
# Starts the Ambari Server.
#
def start(args):
+ parse_properties_file(args)
if os.path.exists(PID_DIR + os.sep + PID_NAME):
f = open(PID_DIR + os.sep + PID_NAME, "r")
pid = int(f.readline())
@@ -957,10 +958,12 @@ def start(args):
"command to install a JDK automatically or install any "
"JDK manually to " + JDK_INSTALL_DIR)
return -1
- retcode = check_postgre_up()
- if not retcode == 0:
- print_error_msg("Unable to start PostgreSQL server. Exiting")
- sys.exit(retcode)
+
+ if args.persistence_type == "local":
+ retcode = check_postgre_up()
+ if not retcode == 0:
+ print_error_msg("Unable to start PostgreSQL server. Exiting")
+ sys.exit(retcode)
print 'Checking iptables...'
retcode, out = check_iptables()
@@ -1001,7 +1004,7 @@ def stop(args):
# Upgrades the Ambari Server.
#
def upgrade(args):
- parse_properties(args)
+ parse_properties_file(args)
if args.persistence_type == "remote":
@@ -1404,7 +1407,7 @@ def store_local_properties(args):
return 0
-def parse_properties(args):
+def parse_properties_file(args):
conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
properties = Properties()
@@ -1416,16 +1419,25 @@ def parse_properties(args):
args.persistence_type = properties[PERSISTENCE_TYPE_PROPERTY]
+ if not args.persistence_type:
+ args.persistence_type = "local"
+
if args.persistence_type == 'remote':
args.database = properties[JDBC_DATABASE_PROPERTY]
args.database_host = properties[JDBC_HOSTNAME_PROPERTY]
args.database_port = properties[JDBC_PORT_PROPERTY]
args.database_name = properties[JDBC_SCHEMA_PROPERTY]
global DATABASE_INDEX
- DATABASE_INDEX = DATABASE_NAMES.index(args.database)
+ try:
+ DATABASE_INDEX = DATABASE_NAMES.index(args.database)
+ except ValueError:
+ pass
args.database_username = properties[JDBC_USER_NAME_PROPERTY]
- args.database_password = open(properties[JDBC_PASSWORD_FILE_PROPERTY]).read()
+
+ args.database_password_file = properties[JDBC_PASSWORD_FILE_PROPERTY]
+ if args.database_password_file:
+ args.database_password = open(properties[JDBC_PASSWORD_FILE_PROPERTY]).read()
return 0
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=1491291&r1=1491290&r2=1491291&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 20:45:18 2013
@@ -326,6 +326,7 @@ class TestAmbariServer(TestCase):
tf2 = tempfile.NamedTemporaryFile()
ambari_server.PG_HBA_CONF_FILE = tf1.name
ambari_server.PG_HBA_CONF_FILE_BACKUP = tf2.name
+ args = MagicMock()
out = StringIO.StringIO()
sys.stdout = out
@@ -822,14 +823,17 @@ class TestAmbariServer(TestCase):
@patch.object(ambari_server, "print_info_msg")
@patch.object(ambari_server, "run_os_command")
@patch.object(ambari_server, "configure_database_username_password")
- def test_reset(self, configure_database_username_password_mock,
+ @patch.object(ambari_server, "parse_properties_file")
+ def test_reset(self, parse_properties_file_mock, configure_database_username_password_mock,
run_os_command_mock, print_info_msg_mock,
setup_db_mock, get_YN_inputMock):
out = StringIO.StringIO()
sys.stdout = out
+ parse_properties_file_mock.return_value = 0
args = MagicMock()
+ args.persistence_type = "local"
get_YN_inputMock.return_value = False
rcode = ambari_server.reset(args)
self.assertEqual(-1, rcode)
@@ -851,8 +855,8 @@ class TestAmbariServer(TestCase):
@patch.object(ambari_server, "setup_db")
@patch.object(ambari_server, "print_info_msg")
@patch.object(ambari_server, "run_os_command")
- @patch.object(ambari_server, "parse_properties")
- def test_silent_reset(self, parse_properties_mock,
+ @patch.object(ambari_server, "parse_properties_file")
+ def test_silent_reset(self, parse_properties_file_mock,
run_os_command_mock, print_info_msg_mock,
setup_db_mock):
@@ -888,7 +892,8 @@ class TestAmbariServer(TestCase):
@patch.object(ambari_server, "print_error_msg")
@patch.object(ambari_server, "check_postgre_up")
@patch.object(ambari_server, "check_iptables")
- def test_start(self, check_iptables_mock, check_postgre_up_mock,
+ @patch.object(ambari_server, "parse_properties_file")
+ def test_start(self, parse_properties_file_mock, check_iptables_mock, check_postgre_up_mock,
print_error_msg_mock, find_jdk_mock, get_conf_dir_mock,
print_info_msg_mock, popenMock, openMock, pexistsMock,
killMock):
@@ -911,14 +916,21 @@ class TestAmbariServer(TestCase):
self.assertEqual(-1, rcode)
find_jdk_mock.return_value = "somewhere"
+ args.persistence_type="remote"
check_postgre_up_mock.return_value = 0
check_iptables_mock.return_value = (0, None)
p = MagicMock()
popenMock.return_value = p
rcode = ambari_server.start(args)
self.assertEqual(None, rcode)
+ self.assertFalse(check_postgre_up_mock.called)
self.assertTrue(f.write.called)
+ args.persistence_type="local"
+ rcode = ambari_server.start(args)
+ self.assertEqual(None, rcode)
+ self.assertTrue(check_postgre_up_mock.called)
+
sys.stdout = sys.__stdout__
@@ -1031,14 +1043,14 @@ class TestAmbariServer(TestCase):
sys.stdout = sys.__stdout__
- @patch.object(ambari_server, "parse_properties")
+ @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")
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):
+ get_YN_inputMock, print_error_msg_mock, get_db_cli_tool_mock, parse_properties_file_mock):
out = StringIO.StringIO()
sys.stdout = out
@@ -1054,6 +1066,28 @@ class TestAmbariServer(TestCase):
sys.stdout = sys.__stdout__
+ @patch.object(ambari_server, "search_file")
+ def test_parse_properties_file(self, search_file_mock):
+
+ tf1 = tempfile.NamedTemporaryFile()
+ search_file_mock.return_value = tf1.name
+
+ args = MagicMock()
+ ambari_server.parse_properties_file(args)
+ self.assertEquals(args.persistence_type, "local")
+
+
+ with open(tf1.name, 'w') as fout:
+ fout.write("\n")
+ fout.write(ambari_server.PERSISTENCE_TYPE_PROPERTY+"=remote")
+
+ args = MagicMock()
+
+ ambari_server.parse_properties_file(args)
+ self.assertEquals(args.persistence_type, "remote")
+
+ sys.stdout = sys.__stdout__
+
def get_sample(self, sample):
"""