Updated Branches:
  refs/heads/trunk ddfbda054 -> 9a5060c0c

AMBARI-3008. Command "ambari-server setup -s" ends with error on SUSE. (Dmitry 
Sen via odiachenko)


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

Branch: refs/heads/trunk
Commit: 9a5060c0c63e1649093ebe883d789def7f55313a
Parents: ddfbda0
Author: Oleksandr Diachenko <[email protected]>
Authored: Wed Sep 4 18:55:21 2013 +0300
Committer: Oleksandr Diachenko <[email protected]>
Committed: Wed Sep 4 18:55:21 2013 +0300

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 13 ++++++++---
 .../src/test/python/TestAmbaryServer.py         | 24 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/9a5060c0/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 1e2d1e3..c77fdc2 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -214,6 +214,8 @@ AMBARI_PROPERTIES_FILE="ambari.properties"
 AMBARI_PROPERTIES_RPMSAVE_FILE="ambari.properties.rpmsave"
 RESOURCES_DIR_PROPERTY="resources.dir"
 
+SETUP_DB_CONNECT_TIMEOUT = 5
+SETUP_DB_CONNECT_ATTEMPTS = 3
 SETUP_DB_CMD = ['su', '-', 'postgres',
         '--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'" -v 
dbname="{3}"']
 UPGRADE_STACK_CMD = ['su', 'postgres',
@@ -877,9 +879,14 @@ def setup_db(args):
   command = SETUP_DB_CMD[:]
   command[-1] = command[-1].format(scriptFile, username, password, dbname)
 
-  retcode, outdata, errdata = run_os_command(command)
-  if not retcode == 0:
-    print errdata
+  for i in range(SETUP_DB_CONNECT_ATTEMPTS):
+    print 'Connecting to the database. Attempt %d...' % (i+1)
+    retcode, outdata, errdata = run_os_command(command)
+    if retcode == 0:
+      return retcode
+    time.sleep(SETUP_DB_CONNECT_TIMEOUT)
+
+  print_error_msg(errdata)
   return retcode
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/9a5060c0/ambari-server/src/test/python/TestAmbaryServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbaryServer.py 
b/ambari-server/src/test/python/TestAmbaryServer.py
index ef897c5..fbaa210 100644
--- a/ambari-server/src/test/python/TestAmbaryServer.py
+++ b/ambari-server/src/test/python/TestAmbaryServer.py
@@ -522,7 +522,31 @@ class TestAmbariServer(TestCase):
     self.assertTrue(configure_database_username_password_mock.called)
     self.assertEqual(0, result)
 
+  @patch.object(ambari_server, "configure_database_username_password")
+  @patch("time.sleep")
+  @patch.object(ambari_server, "run_os_command")
+  def test_setup_db_connect_attempts_fail(self, run_os_command_mock,
+                                          sleep_mock, config_db_mock):
+    run_os_command_mock.side_effect = [(1, "error", "error"),(1, "error", 
"error"),
+                                       (1, "error", "error")]
+    result = ambari_server.setup_db(MagicMock())
+    self.assertTrue(run_os_command_mock.called)
+    self.assertEqual(1, result)
+    self.assertEqual(3, sleep_mock.call_count)
+    pass
 
+  @patch.object(ambari_server, "configure_database_username_password")
+  @patch("time.sleep")
+  @patch.object(ambari_server, "run_os_command")
+  def test_setup_db_connect_attempts_success(self, run_os_command_mock,
+                                             sleep_mock, config_db_mock):
+    run_os_command_mock.side_effect = [(1, "error", "error"),(0, None, None),
+                                       (0, None, None)]
+    result = ambari_server.setup_db(MagicMock())
+    self.assertTrue(run_os_command_mock.called)
+    self.assertEqual(0, result)
+    self.assertEqual(1, sleep_mock.call_count)
+    pass
 
   @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "run_os_command")

Reply via email to