AMBARI-5427. Usability: Cleanup database connection checking during setup (when using postgres). (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e002774b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e002774b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e002774b Branch: refs/heads/trunk Commit: e002774b5c4e59c659eef1d729928976973265f5 Parents: 80a499a Author: Myroslav Papirkovskyy <mpapyrkovs...@hortonworks.com> Authored: Thu Apr 10 18:44:47 2014 +0300 Committer: Myroslav Papirkovskyy <mpapyrkovs...@hortonworks.com> Committed: Thu Apr 24 14:51:51 2014 +0300 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 10 ++++++++-- ambari-server/src/test/python/TestAmbariServer.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e002774b/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 f74ef29..4bb9035 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -969,12 +969,18 @@ def setup_db(args): command[-1] = command[-1].format(scriptFile, username, password, dbname) for i in range(SETUP_DB_CONNECT_ATTEMPTS): - print 'Connecting to the database. Attempt %d...' % (i+1) + sys.stdout.write('Connecting to local database...') retcode, outdata, errdata = run_os_command(command) if retcode == 0: + print 'done.' return retcode, outdata, errdata - time.sleep(SETUP_DB_CONNECT_TIMEOUT) + timeOutMsg = 'connection timed out' + if (i+1) < SETUP_DB_CONNECT_ATTEMPTS: + timeOutMsg += '...retrying (%d)' % (i+1) + print timeOutMsg + time.sleep(SETUP_DB_CONNECT_TIMEOUT) + print 'unable to connect to database' print_error_msg(errdata) return retcode, outdata, errdata http://git-wip-us.apache.org/repos/asf/ambari/blob/e002774b/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 56814a2..74f1476 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -590,7 +590,7 @@ class TestAmbariServer(TestCase): result = ambari_server.setup_db(MagicMock()) self.assertTrue(run_os_command_mock.called) self.assertEqual((1, 'error', 'error') , result) - self.assertEqual(3, sleep_mock.call_count) + self.assertEqual(2, sleep_mock.call_count) pass @patch.object(ambari_server, "configure_database_username_password")