Forráskód Böngészése

AMBARI-5170. Fix Ambari Setup on Ubuntu.(vbrodetskyi)

Vitaly Brodetskyi 11 éve
szülő
commit
4bae123883

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 176 - 167
ambari-server/src/main/python/ambari-server.py


+ 79 - 0
ambari-server/src/main/python/ambari_server/utils.py

@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+import os
+
+#OS constants
+OS_UBUNTU = 'ubuntu'
+OS_FEDORA = 'fedora'
+OS_OPENSUSE = 'opensuse'
+OS_SUSE = 'suse'
+OS_SUSE_ENTERPRISE = 'sles'
+
+#PostgreSQL settings
+UBUNTU_PG_HBA_ROOT = "/etc/postgresql"
+PG_HBA_ROOT_DEFAULT = "/var/lib/pgsql/data"
+PG_STATUS_RUNNING_DEFAULT = "running"
+
+#Environment
+ENV_PATH_DEFAULT = ['/bin', '/usr/bin', '/sbin', '/usr/sbin']  # default search path
+ENV_PATH = os.getenv('PATH', '').split(':') + ENV_PATH_DEFAULT
+
+
+  # ToDo: move that function to common-functions
+def locate_file(filename, default=''):
+  """Locate command path according to OS environment"""
+  for path in ENV_PATH:
+    path = "%s/%s" % (path, filename)
+    if os.path.isfile(path):
+      return path
+  if default != '':
+    return "%s/%s" % (default, filename)
+  else:
+    return filename
+
+
+def get_ubuntu_pg_version():
+  """Return installed version of postgre server. In case of several
+  installed versions will be returned a more new one.
+  """
+  postgre_ver = ""
+
+  if os.path.isdir(UBUNTU_PG_HBA_ROOT):  # detect actual installed versions of PG and select a more new one
+    postgre_ver = sorted(
+    [fld for fld in os.listdir(UBUNTU_PG_HBA_ROOT) if os.path.isdir(os.path.join(UBUNTU_PG_HBA_ROOT, fld))], reverse=True)
+    if len(postgre_ver) > 0:
+      return postgre_ver[0]
+  return postgre_ver
+
+
+def get_postgre_hba_dir(OS):
+  """Return postgre hba dir location depends on OS"""
+  if OS == OS_UBUNTU:
+    return "%s/%s/main" % (UBUNTU_PG_HBA_ROOT, get_ubuntu_pg_version())
+  else:
+    return PG_HBA_ROOT_DEFAULT
+
+
+def get_postgre_running_status(OS):
+  """Return postgre running status indicator"""
+  if OS == OS_UBUNTU:
+    return "%s/main" % get_ubuntu_pg_version()
+  else:
+    return PG_STATUS_RUNNING_DEFAULT

+ 10 - 11
ambari-server/src/test/python/TestAmbariServer.py

@@ -1065,7 +1065,7 @@ class TestAmbariServer(TestCase):
     self.assertTrue(f.flush.called)
     self.assertTrue(f.close.called)
     self.assertEqual(2, len(dlprogress_mock.call_args_list))
-    
+
   @patch("shutil.copy")
   @patch("os.path.join")
   @patch("os.path.exists")
@@ -1276,7 +1276,7 @@ class TestAmbariServer(TestCase):
     # Testing call under root
     is_root_mock.return_value = True
     read_ambari_user_method.return_value = "user"
-    #Case #1: if client ssl is on and user didnt choose 
+    #Case #1: if client ssl is on and user didnt choose
     #disable ssl option and choose import certs and keys
     p.get_property.side_effect = ["key_dir", "5555", "6666", "true"]
     get_YN_input_mock.side_effect = [False, True]
@@ -1321,7 +1321,7 @@ class TestAmbariServer(TestCase):
     p.store.reset_mock()
     import_cert_and_key_action_mock.reset_mock()
 
-    #Case #3: if client ssl is off and user choose option 
+    #Case #3: if client ssl is off and user choose option
     #to import cert and keys
     p.get_property.side_effect = ["key_dir", "", None]
     get_YN_input_mock.side_effect = [True, True]
@@ -1343,7 +1343,7 @@ class TestAmbariServer(TestCase):
     p.store.reset_mock()
     import_cert_and_key_action_mock.reset_mock()
 
-    #Case #4: if client ssl is off and 
+    #Case #4: if client ssl is off and
     #user did not choose option to import cert and keys
     p.get_property.side_effect = ["key_dir", "", None]
     get_YN_input_mock.side_effect = [False]
@@ -1763,8 +1763,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     os_path_exists_mock.return_value = False
     status, pid = ambari_server.is_server_runing()
     self.assertFalse(status)
-    
-    
+
+
   @patch.object(ambari_server, "run_os_command")
   @patch("__builtin__.open")
   @patch("os.path.exists")
@@ -1773,9 +1773,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     os_path_exists_mock.return_value = True
     f = open_mock.return_value
     f.readline.return_value = "" # empty file content
-    run_os_command_mock.return_value = 0, "", ""  
+    run_os_command_mock.return_value = 0, "", ""
     self.assertRaises(NonFatalException, ambari_server.is_server_runing)
-    
+
     open_mock.side_effect = IOError('[Errno 13] Permission denied: /var/run/ambari-server/ambari-server.pid')
     self.assertRaises(FatalException, ambari_server.is_server_runing)
 
@@ -2533,7 +2533,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     is_root_mock.return_value = True
     find_jdk_mock.return_value = None
     is_server_running_mock.return_value = (False, 0)
-    
+
     try:
       ambari_server.start(args)
       self.fail("Should fail with 'No JDK found'")
@@ -3746,7 +3746,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
 
 
-    # Failed to copy_files    
+    # Failed to copy_files
 
     find_jdbc_driver_mock.side_effect = [drivers_list]
     try:
@@ -4708,4 +4708,3 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertTrue(run_metainfo_upgrade_mock.called)
     run_metainfo_upgrade_mock.assert_called_with({})
 
-

+ 63 - 0
ambari-server/src/test/python/TestUtils.py

@@ -0,0 +1,63 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from unittest import TestCase
+from mock.mock import patch
+
+
+utils = __import__('ambari_server.utils').utils
+
+
+class TestUtils(TestCase):
+  @patch('os.listdir')
+  @patch('os.path.isdir')
+  def test_get_ubuntu_pg_version(self, path_isdir_mock, os_listdir_mock):
+    path_isdir_mock.return_value = True
+    os_listdir_mock.return_value = ['8.4', '9.1']
+
+    self.assertEqual('9.1', utils.get_ubuntu_pg_version())
+
+  @patch('ambari_server.utils.get_ubuntu_pg_version')
+  def test_get_postgre_hba_dir(self, get_ubuntu_pg_version_mock):
+    utils.UBUNTU_PG_HBA_ROOT = '/tmp'
+    utils.PG_HBA_ROOT_DEFAULT = '/redhat/postgre/data'
+    get_ubuntu_pg_version_mock.return_value = '9.1'
+
+    self.assertEqual('/tmp/9.1/main', utils.get_postgre_hba_dir('ubuntu'))
+    self.assertEqual('/redhat/postgre/data', utils.get_postgre_hba_dir('redhat'))
+
+  @patch('ambari_server.utils.get_ubuntu_pg_version')
+  def test_get_postgre_running_status(self, get_ubuntu_pg_version_mock):
+    utils.PG_STATUS_RUNNING_DEFAULT = "red_running"
+    get_ubuntu_pg_version_mock.return_value = '9.1'
+
+    self.assertEqual('9.1/main', utils.get_postgre_running_status('ubuntu'))
+    self.assertEqual('red_running', utils.get_postgre_running_status('redhat'))
+
+  @patch('os.path.isfile')
+  def test_locate_file(self, isfile_mock):
+    utils.ENV_PATH = ['/test']
+    # File was found in the path
+    isfile_mock.return_value = True
+    self.assertEquals('/test/myfile', utils.locate_file('myfile'))
+    # File not found in the path
+    isfile_mock.return_value = False
+    self.assertEquals('myfile', utils.locate_file('myfile'))
+    # Testing default vaule
+    isfile_mock.return_value = False
+    self.assertEquals('/tmp/myfile', utils.locate_file('myfile', '/tmp'))

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott