You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2015/12/01 14:28:40 UTC

ambari git commit: AMBARI-14119. Ambari fails to start with posgres DB on Suse.(vbrodetskyi)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 183eb2722 -> 9f52815bf


AMBARI-14119. Ambari fails to start with posgres DB on Suse.(vbrodetskyi)


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

Branch: refs/heads/branch-2.1
Commit: 9f52815bfee66552dfd600288b39adc6e530cb56
Parents: 183eb27
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Tue Dec 1 12:30:05 2015 +0200
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Tue Dec 1 12:30:05 2015 +0200

----------------------------------------------------------------------
 .../python/ambari_server/dbConfiguration.py     |  8 ++++++-
 .../ambari_server/dbConfiguration_linux.py      | 22 +++++++++++++++++
 .../src/test/python/TestAmbariServer.py         | 25 +++++++++++++++++---
 3 files changed, 51 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9f52815b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration.py b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
index ae7d280..59274b3 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration.py
@@ -20,7 +20,7 @@ limitations under the License.
 import glob
 import os
 
-from ambari_commons import OSConst
+from ambari_commons import OSConst, OSCheck
 from ambari_commons.exceptions import FatalException
 from ambari_commons.logging_utils import get_silent, print_error_msg, print_info_msg, print_warning_msg, set_silent
 from ambari_commons.os_family_impl import OsFamilyImpl
@@ -124,6 +124,9 @@ class DBMSConfig(object):
       #DB setup should be done last after doing any setup.
       if self._is_local_database():
         self._setup_local_server(properties)
+        # this issue appears only for Suse. Postgres need /var/run/postgresql dir but do not create it
+        if OSCheck.is_suse_family():
+          self._create_postgres_lock_directory()
       else:
         self._setup_remote_server(properties)
     return result
@@ -212,6 +215,9 @@ class DBMSConfig(object):
     #linux_prompt_db_properties(args)
     return False
 
+  def _create_postgres_lock_directory(self):
+    pass
+
   def _setup_local_server(self, properties):
     pass
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9f52815b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
index 933113e..e8d292a 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -26,6 +26,7 @@ import socket
 import subprocess
 import sys
 import time
+import pwd
 
 from ambari_commons import OSCheck, OSConst
 from ambari_commons.logging_utils import get_silent, get_verbose, print_error_msg, print_info_msg, print_warning_msg
@@ -408,6 +409,27 @@ class PGConfig(LinuxDBMSConfig):
     print 'Default properties detected. Using built-in database.'
     self._store_local_properties(properties)
 
+  def _create_postgres_lock_directory(self):
+    postgres_user_uid = None
+    try:
+      postgres_user_uid = pwd.getpwnam("postgres").pw_uid
+    except KeyError:
+      print "WARNING: Unable to create /var/run/postgresql directory, because user [postgres] doesn't exist. Potentially," \
+            " postgresql service start can be failed."
+      return
+
+    try:
+      if not os.path.isdir("/var/run/postgresql"):
+        os.mkdir("/var/run/postgresql")
+    except Exception as e:
+      print "WARNING: Unable to create /var/run/postgresql directory. Potentially," \
+            " postgresql service start can be failed."
+      print "Unexpected error: " + str(e)
+      return
+
+    if postgres_user_uid:
+      os.chown("/var/run/postgresql", postgres_user_uid, -1)
+
   def _setup_local_database(self):
     print 'Checking PostgreSQL...'
     (pg_status, retcode, out, err) = PGConfig._check_postgre_up()

http://git-wip-us.apache.org/repos/asf/ambari/blob/9f52815b/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 bc23402..8e3139b 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -2534,16 +2534,26 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     pass
 
   @not_for_platform(PLATFORM_WINDOWS)
-  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch("os.path.isdir")
+  @patch("os.mkdir")
+  @patch("os.chown")
+  @patch("pwd.getpwnam")
+  @patch.object(OSCheck, "get_os_family")
   @patch.object(PGConfig, "_setup_local_server")
   @patch("ambari_server.dbConfiguration_linux.print_info_msg")
   @patch("ambari_server.dbConfiguration_linux.read_password")
   @patch("ambari_server.dbConfiguration_linux.get_validated_string_input")
   @patch("ambari_server.dbConfiguration.get_validated_string_input")
   @patch("ambari_server.serverSetup.get_YN_input")
-  def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, gvsi_2_mock, rp_mock, print_info_msg_mock, sls_mock):
+  def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, gvsi_2_mock, rp_mock, print_info_msg_mock, sls_mock,
+                                            get_os_family_mock, get_pw_nam_mock, chown_mock, mkdir_mock, isdir_mock):
     gyni_mock.return_value = True
     list_of_return_values = ["ambari-server", "ambari", "ambari", "1"]
+    get_os_family_mock.return_value = OSConst.SUSE_FAMILY
+    pw = MagicMock()
+    pw.setattr('pw_uid', 0)
+    pw.setattr('pw_gid', 0)
+    get_pw_nam_mock.return_value = pw
 
     def side_effect(*args, **kwargs):
       return list_of_return_values.pop()
@@ -2582,11 +2592,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertEqual(dbmsConfig.database_username, "ambari")
     self.assertEqual(dbmsConfig.database_password, "bigdata")
 
+    isdir_mock.return_value = False
+
     dbmsConfig.configure_database(props)
 
     self.assertEqual(dbmsConfig.database_username, "ambari-server")
     self.assertEqual(dbmsConfig.database_password, "password")
     self.assertEqual(dbmsConfig.sid_or_sname, "sid")
+    self.assertTrue(chown_mock.called)
+    self.assertTrue(mkdir_mock.called)
     pass
 
   @not_for_platform(PLATFORM_WINDOWS)
@@ -2865,6 +2879,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     pass
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch("pwd.getpwnam")
   @patch("ambari_commons.firewall.run_os_command")
   @patch("os.path.exists")
   @patch("os.path.isfile")
@@ -2907,7 +2922,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
                  store_password_file_mock, get_ambari_properties_1_mock, get_ambari_properties_2_mock,
                  update_properties_mock, get_YN_input_1_mock, ensure_jdbc_driver_installed_mock,
                  remove_file_mock, isfile_mock, exists_mock,
-                 run_os_command_mock):
+                 run_os_command_mock, get_pw_nam_mock):
     hostname = "localhost"
     db_name = "db_ambari"
     postgres_schema = "sc_ambari"
@@ -2931,6 +2946,10 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     failed = False
     properties = Properties()
 
+    def side_effect(username):
+      raise KeyError("")
+
+    get_pw_nam_mock.side_effect = side_effect
     get_YN_input_mock.return_value = False
     isfile_mock.return_value = False
     verify_setup_allowed_method.return_value = 0