ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: AMBARI-6254 Usability: Ambari-server may fail to start Postgres with a cryptic message (dsen)
Date Tue, 24 Jun 2014 17:35:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 8cf801387 -> 406308408


AMBARI-6254 Usability: Ambari-server may fail to start Postgres with a cryptic message (dsen)


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

Branch: refs/heads/trunk
Commit: 406308408e55c1092927311fdcddc7c6edfae399
Parents: 8cf8013
Author: Dmytro Sen <dsen@hortonworks.com>
Authored: Tue Jun 24 20:35:05 2014 +0300
Committer: Dmytro Sen <dsen@hortonworks.com>
Committed: Tue Jun 24 20:35:05 2014 +0300

----------------------------------------------------------------------
 ambari-server/sbin/ambari-server                |  2 +-
 ambari-server/src/main/python/ambari-server.py  | 50 +++++++++---------
 .../src/test/python/TestAmbariServer.py         | 55 ++++++++++----------
 3 files changed, 54 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/40630840/ambari-server/sbin/ambari-server
----------------------------------------------------------------------
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index 0610657..74b8302 100644
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -35,7 +35,7 @@ case "$1" in
         ;;
 esac
 
-export PATH=/usr/lib/ambari-server/*:$PATH
+export PATH=/usr/lib/ambari-server/*:$PATH:/sbin/:/usr/sbin
 export AMBARI_CONF_DIR=/etc/ambari-server/conf:$PATH
 
 # Because Ambari rpm unpacks modules here on all systems

http://git-wip-us.apache.org/repos/asf/ambari/blob/40630840/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 20ccba2..7987b95 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -906,17 +906,17 @@ def configure_postgres():
     else:
       #Postgres has been configured before, must not override backup
       print "Backup for pg_hba found, reconfiguration not required"
-      return 0
+      return 0, "", ""
   configure_pg_hba_postgres_user()
   configure_pg_hba_ambaridb_users()
   os.chmod(PG_HBA_CONF_FILE, 0644)
   configure_postgresql_conf()
   #restart postgresql if already running
-  pg_status = get_postgre_status()
+  pg_status, retcode, out, err = get_postgre_status()
   if pg_status == PG_STATUS_RUNNING:
-    retcode = restart_postgres()
-    return retcode
-  return 0
+    retcode, out, err = restart_postgres()
+    return retcode, out, err
+  return 0, "", ""
 
 
 def restart_postgres():
@@ -931,13 +931,13 @@ def restart_postgres():
   if result is None:
     print_info_msg("Killing restart PostgresSQL process")
     process.kill()
-    pg_status = get_postgre_status()
+    pg_status, retcode, out, err = get_postgre_status()
     # SUSE linux set status of stopped postgresql proc to unused
     if pg_status == "unused" or pg_status == "stopped":
       print_info_msg("PostgreSQL is stopped. Restarting ...")
       retcode, out, err = run_os_command(PG_START_CMD)
-      return retcode
-  return 0
+      return retcode, out, err
+  return 0, "", ""
 
 
 # todo: check if the scheme is already exist
@@ -1075,14 +1075,14 @@ def get_postgre_status():
     pg_status = re.search('(stopped|running)', out, re.IGNORECASE).group(0).lower()
   except AttributeError:
     pg_status = None
-  return pg_status
+  return pg_status, retcode, out, err
 
 
 def check_postgre_up():
-  pg_status = get_postgre_status()
+  pg_status, retcode, out, err = get_postgre_status()
   if pg_status == PG_STATUS_RUNNING:
     print_info_msg("PostgreSQL is running")
-    return 0
+    return pg_status, 0, out, err
   else:
     # run initdb only on non ubuntu systems as ubuntu does not have initdb cmd.
     if OS_TYPE != OSConst.OS_UBUNTU:
@@ -1103,7 +1103,7 @@ def check_postgre_up():
         print_info_msg("Result of postgres start cmd: " + str(result))
         if result is None:
           process.kill()
-          pg_status = get_postgre_status()
+          pg_status, retcode, out, err = get_postgre_status()
         else:
           retcode = result
       else:
@@ -1111,15 +1111,14 @@ def check_postgre_up():
         retcode = process.returncode
       if pg_status == PG_STATUS_RUNNING:
         print_info_msg("Postgres process is running. Returning...")
-        return 0
+        return pg_status, 0, out, err
     except (Exception), e:
-      pg_status = get_postgre_status()
+      pg_status, retcode, out, err = get_postgre_status()
       if pg_status == PG_STATUS_RUNNING:
-        return 0
+        return pg_status, 0, out, err
       else:
-        print_error_msg("Postgres start failed. " + str(e))
-        return 1
-    return retcode
+        print_error_msg("Postgres start failed. " + str(e))    
+    return pg_status, retcode, out, err
 
 
 def get_validated_db_name(database_name):
@@ -2277,15 +2276,16 @@ def setup(args):
     store_local_properties(args)
 
     print 'Checking PostgreSQL...'
-    retcode = check_postgre_up()
+    pg_status, retcode, out, err = check_postgre_up()
     if not retcode == 0:
-      err = 'Unable to start PostgreSQL server. Exiting'
+      err = 'Unable to start PostgreSQL server. Status {0}. {1}.' \
+            ' Exiting'.format(pg_status, err)
       raise FatalException(retcode, err)
 
     print 'Configuring local database...'
     retcode, outdata, errdata = setup_db(args)
     if not retcode == 0:
-      err = 'Running database init script was failed. Exiting.'
+      err = 'Running database init script was failed. {0}. Exiting.'.format(errdata)
       raise FatalException(retcode, err)
 
     if is_user_changed:
@@ -2293,9 +2293,9 @@ def setup(args):
       remove_file(PG_HBA_CONF_FILE_BACKUP)
 
     print 'Configuring PostgreSQL...'
-    retcode = configure_postgres()
+    retcode, out, err = configure_postgres()
     if not retcode == 0:
-      err = 'Unable to configure PostgreSQL server. Exiting'
+      err = 'Unable to configure PostgreSQL server. {0} Exiting'.format(err)
       raise FatalException(retcode, err)
 
   else:
@@ -2496,9 +2496,9 @@ def start(args):
     print "Ambari Server running with 'root' privileges."
 
     if args.persistence_type == "local":
-      retcode = check_postgre_up()
+      pg_status, retcode, out, err = check_postgre_up()
       if not retcode == 0:
-        err = "Unable to start PostgreSQL server. Exiting"
+        err = 'Unable to start PostgreSQL server. Status {0}. {1}. Exiting'.format(pg_status,
err)
         raise FatalException(retcode, err)
 
   else:  # Skipping actions that require root permissions

http://git-wip-us.apache.org/repos/asf/ambari/blob/40630840/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 4d4816d..2abb15b 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -487,17 +487,17 @@ class TestAmbariServer(TestCase):
 
     out = StringIO.StringIO()
     sys.stdout = out
-    rcode = ambari_server.configure_postgres()
+    retcode, out1, err = ambari_server.configure_postgres()
     sys.stdout = sys.__stdout__
-    self.assertEqual(0, rcode)
+    self.assertEqual(0, retcode)
     self.assertEqual("Backup for pg_hba found, reconfiguration not required\n",
                      out.getvalue())
 
     ambari_server.PG_HBA_CONF_FILE_BACKUP = tempfile.mktemp()
-    get_postgre_status_mock.return_value = ambari_server.PG_STATUS_RUNNING
-    restart_postgres_mock.return_value = 0
+    get_postgre_status_mock.return_value = ambari_server.PG_STATUS_RUNNING, 0, "", ""
+    restart_postgres_mock.return_value = 0, "", ""
 
-    rcode = ambari_server.configure_postgres()
+    rcode, out, err = ambari_server.configure_postgres()
 
     self.assertTrue(os.path.isfile(ambari_server.PG_HBA_CONF_FILE_BACKUP),
                     "postgresql.conf backup not created")
@@ -510,8 +510,8 @@ class TestAmbariServer(TestCase):
     self.assertEqual(0, rcode)
 
     os.unlink(ambari_server.PG_HBA_CONF_FILE_BACKUP)
-    get_postgre_status_mock.return_value = "stopped"
-    rcode = ambari_server.configure_postgres()
+    get_postgre_status_mock.return_value = "stopped", 0, "", ""
+    rcode, out, err = ambari_server.configure_postgres()
     self.assertEqual(0, rcode)
     os.unlink(ambari_server.PG_HBA_CONF_FILE_BACKUP)
     sys.stdout = sys.__stdout__
@@ -527,14 +527,14 @@ class TestAmbariServer(TestCase):
     p = MagicMock()
     p.poll.return_value = 0
     popenMock.return_value = p
-    rcode = ambari_server.restart_postgres()
-    self.assertEqual(0, rcode)
+    retcode, out, err = ambari_server.restart_postgres()
+    self.assertEqual(0, retcode)
 
     p.poll.return_value = None
-    get_postgre_status_mock.return_value = "stopped"
+    get_postgre_status_mock.return_value = "stopped", 0, "", ""
     run_os_command_mock.return_value = (1, None, None)
-    rcode = ambari_server.restart_postgres()
-    self.assertEqual(1, rcode)
+    retcode, out, err = ambari_server.restart_postgres()
+    self.assertEqual(1, retcode)
 
 
   @patch("shlex.split")
@@ -2056,12 +2056,12 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   def test_get_postgre_status(self, run_os_command_mock):
 
     run_os_command_mock.return_value = (1, "running", None)
-    result = ambari_server.get_postgre_status()
-    self.assertEqual("running", result)
+    pg_status, retcode, out, err = ambari_server.get_postgre_status()
+    self.assertEqual("running", pg_status)
 
     run_os_command_mock.return_value = (1, "wrong", None)
-    result = ambari_server.get_postgre_status()
-    self.assertEqual(None, result)
+    pg_status, retcode, out, err = ambari_server.get_postgre_status()
+    self.assertEqual(None, pg_status)
 
 
   @patch("time.sleep")
@@ -2075,15 +2075,16 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     p.communicate.return_value = (None, None)
     p.returncode = 0
     popen_mock.return_value = p
+    get_postgre_status_mock.return_value = "running", 0, "", ""
     run_os_command_mock.return_value = (0, None, None)
-    rcode = ambari_server.check_postgre_up()
-    self.assertEqual(0, rcode)
+    pg_status, retcode, out, err = ambari_server.check_postgre_up()
+    self.assertEqual(0, retcode)
 
     ambari_server.OS = 'suse'
     p.poll.return_value = 4
-    get_postgre_status_mock.return_value = None
-    rcode = ambari_server.check_postgre_up()
-    self.assertEqual(4, rcode)
+    get_postgre_status_mock.return_value = "stopped", 0, "", ""
+    pg_status, retcode, out, err = ambari_server.check_postgre_up()
+    self.assertEqual(4, retcode)
 
 
   @patch("platform.linux_distribution")
@@ -2332,11 +2333,11 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     check_ambari_user_mock.return_value = 0
     check_jdbc_drivers_mock.return_value = 0
     check_iptables_mock.return_value = (0, "other")
-    check_postgre_up_mock.return_value = 0
+    check_postgre_up_mock.return_value = "running", 0, "", ""
     setup_db_mock.return_value = (0, None, None)
     setup_remote_db_mock.return_value = 0
     is_local_database_mock.return_value = False
-    configure_postgres_mock.return_value = 0
+    configure_postgres_mock.return_value = 0, "", ""
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0
     store_remote_properties_mock.return_value = 0
@@ -2713,7 +2714,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
      args.persistence_type = "local"
 
      # case: postgres failed to start
-     check_postgre_up_mock.return_value = 1
+     check_postgre_up_mock.return_value = None, 1, "Unable to start PostgreSQL serv", "error"
      try:
        ambari_server.start(args)
        self.fail("Should fail with 'Unable to start PostgreSQL server'")
@@ -2724,7 +2725,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
      parse_properties_file_mock.reset_mock()
 
-     check_postgre_up_mock.return_value = 0
+     check_postgre_up_mock.return_value = "running", 0, "success", ""
 
      # Case: custom user is "root"
      read_ambari_user_mock.return_value = "root"
@@ -4830,9 +4831,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     check_ambari_user_mock.return_value = 0
     check_jdbc_drivers_mock.return_value = 0
     check_iptables_mock.return_value = (0, "other")
-    check_postgre_up_mock.return_value = 0
+    check_postgre_up_mock.return_value = "running", 0, "", ""
     is_local_database_mock.return_value = True
-    configure_postgres_mock.return_value = 0
+    configure_postgres_mock.return_value = 0, "", ""
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0
     is_jdbc_user_changed_mock.return_value = False


Mime
View raw message