Переглянути джерело

AMBARI-5427. Usability: Cleanup database connection checking during setup (when using postgres). (mpapirkovskyy)

Myroslav Papirkovskyy 11 роки тому
батько
коміт
e002774b5c

+ 8 - 2
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
 

+ 1 - 1
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")