incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject [1/3] AMBARI-3141. Unit test TestAmbariServer .... filename has Ambari with a y. (mahadev)
Date Mon, 09 Sep 2013 17:21:35 GMT
Updated Branches:
  refs/heads/trunk f79b9ff3c -> 13a488d6f


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/13a488d6/ambari-server/src/test/python/TestAmbaryServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbaryServer.py b/ambari-server/src/test/python/TestAmbaryServer.py
deleted file mode 100644
index 28241df..0000000
--- a/ambari-server/src/test/python/TestAmbaryServer.py
+++ /dev/null
@@ -1,4108 +0,0 @@
-'''
-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 StringIO
-import re
-from unittest import TestCase
-import sys
-from mock.mock import patch
-from mock.mock import MagicMock
-from mock.mock import create_autospec
-import os, errno, tempfile
-import signal
-import stat
-import datetime
-import operator
-from pwd import getpwnam
-
-# We have to use this import HACK because the filename contains a dash
-ambari_server = __import__('ambari-server')
-FatalException = ambari_server.FatalException
-NonFatalException = ambari_server.NonFatalException
-
-
-class TestAmbariServer(TestCase):
-
-  def setUp(self):
-    out = StringIO.StringIO()
-    sys.stdout = out
-
-
-  def tearDown(self):
-    sys.stdout = sys.__stdout__
-
-
-  @patch.object(ambari_server, 'configure_database_username_password')
-  @patch.object(ambari_server, 'run_os_command')
-  @patch('optparse.Values')
-  def test_configure_pg_hba_ambaridb_users(self, OptParseValuesMock,
-                                run_os_command_method,
-                                configure_database_username_password_method):
-    # Prepare mocks
-    run_os_command_method.return_value = (0, "", "")
-    opvm = OptParseValuesMock.return_value
-    opvm.database_username = "ffdf"
-    tf1 = tempfile.NamedTemporaryFile()
-    ambari_server.PG_HBA_CONF_FILE = tf1.name
-    # Run test
-    ambari_server.configure_pg_hba_ambaridb_users()
-    # Check results
-    self.assertTrue(run_os_command_method.called)
-    self.assertTrue(configure_database_username_password_method.called)
-    string_expected = self.get_file_string(self
-      .get_samples_dir("configure_pg_hba_ambaridb_users1"))
-    string_actual = self.get_file_string(ambari_server.PG_HBA_CONF_FILE)
-    self.assertEquals(string_expected, string_actual)
-    pass
-
-  @patch('__builtin__.raw_input')
-  def test_servicename_regex(self, raw_input_method):
-
-    ''' Test to make sure the service name can contain digits '''
-    ambari_server.SILENT = False
-    raw_input_method.return_value = "OT100"
-    result = ambari_server.get_validated_service_name("ambari", 1)
-    self.assertEqual("OT100", result, "Not accepting digits")
-    pass
-    
-  @patch('__builtin__.raw_input')
-  def test_dbname_regex(self, raw_input_method):
-
-    ''' Test to make sure the service name can contain digits '''
-    ambari_server.SILENT = False
-    raw_input_method.return_value = "OT100"
-    result = ambari_server.get_validated_db_name("ambari")
-    self.assertEqual("OT100", result, "Not accepting digits")
- 
-
-  def test_configure_pg_hba_postgres_user(self):
-
-    tf1 = tempfile.NamedTemporaryFile()
-    ambari_server.PG_HBA_CONF_FILE = tf1.name
-
-    with open(ambari_server.PG_HBA_CONF_FILE, 'w') as fout:
-      fout.write("\n")
-      fout.write("local  all  all md5\n")
-      fout.write("host  all   all 0.0.0.0/0  md5\n")
-      fout.write("host  all   all ::/0 md5\n")
-
-    ambari_server.configure_pg_hba_postgres_user()
-
-    expected  = self.get_file_string(self.get_samples_dir(
-      "configure_pg_hba_ambaridb_users2"))
-    result = self.get_file_string(ambari_server.PG_HBA_CONF_FILE)
-    self.assertEqual(expected, result, "pg_hba_conf not processed")
-
-    mode = oct(os.stat(ambari_server.PG_HBA_CONF_FILE)[stat.ST_MODE])
-    str_mode = str(mode)[-4:]
-    self.assertEqual("0644", str_mode, "Wrong file permissions")
-
-
-
-  @patch('__builtin__.raw_input')
-  def get_choice_string_input(self, raw_input_method):
-    prompt = "blablabla"
-    default = "default blablabla"
-    firstChoice = set(['yes','ye', 'y'])
-    secondChoice = set(['no','n'])
-    # test first input
-    raw_input_method.return_value = "Y"
-
-    result = ambari_server.get_choice_string_input(prompt, default,
-        firstChoice, secondChoice)
-    self.assertEquals(result, True)
-    raw_input_method.reset_mock()
-    # test second input
-
-    raw_input_method.return_value = "N"
-
-    result = ambari_server.get_choice_string_input(prompt, default,
-        firstChoice, secondChoice)
-    self.assertEquals(result, False)
-
-    raw_input_method.reset_mock()
-
-    # test enter pressed
-
-    raw_input_method.return_value = ""
-
-    result = ambari_server.get_choice_string_input(prompt, default,
-        firstChoice, secondChoice)
-    self.assertEquals(result, default)
-
-    raw_input_method.reset_mock()
-
-    # test wrong input
-    list_of_return_values= ['yes', 'dsad', 'fdsfds']
-    def side_effect(list):
-      return list_of_return_values.pop()
-    raw_input_method.side_effect = side_effect
-
-    result = ambari_server.get_choice_string_input(prompt, default,
-        firstChoice, secondChoice)
-    self.assertEquals(result, True)
-    self.assertEquals(raw_input_method.call_count, 3)
-
-    pass
-
-
-
-  @patch('re.search')
-  @patch('__builtin__.raw_input')
-  @patch('getpass.getpass')
-  def get_validated_string_input(self, get_pass_method,
-      raw_input_method, re_search_method):
-    prompt = "blabla"
-    default = "default_pass"
-    pattern = "pattern_pp"
-    description = "blabla2"
-    # check password input
-    self.assertFalse(False, ambari_server.SILENT)
-    is_pass = True
-    get_pass_method.return_value = "dfdsfdsfds"
-
-    result = ambari_server.get_validated_string_input(prompt, default,
-        pattern, description, is_pass)
-
-    self.assertEquals(get_pass_method.return_value, result)
-    get_pass_method.assure_called_once(prompt)
-    self.assertFalse(raw_input_method.called)
-
-    # check raw input
-    get_pass_method.reset_mock()
-    raw_input_method.reset_mock()
-    is_pass = False
-    raw_input_method.return_value = "dkf90ewuf0"
-
-    result = ambari_server.get_validated_string_input(prompt, default,
-        pattern, description, is_pass)
-
-    self.assertEquals(raw_input_method.return_value, result)
-    self.assertFalse(get_pass_method.called)
-    raw_input_method.assure_called_once(prompt)
-
-
-
-  def test_get_pass_file_path(self):
-    result = ambari_server.get_pass_file_path("/etc/ambari/conf_file")
-    self.assertEquals("/etc/ambari/password.dat", result)
-    pass
-
-
-  @patch.object(ambari_server, 'is_server_runing')
-  @patch.object(ambari_server, 'setup_https')
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_setup_https(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method, setup_https_method, is_server_runing_method):
-      opm = OptionParserMock.return_value
-      options = MagicMock()
-      args = ["setup-https"]
-      opm.parse_args.return_value = (options, args)
-      setup_https_method.return_value = False
-
-      options.database=None
-      options.sid_or_sname = "sid"
-      ambari_server.main()
-
-      self.assertTrue(setup_https_method.called)
-      self.assertEqual(is_server_runing_method.call_count, 0)
-      is_server_runing_method.reset()
-      setup_https_method.return_value = True
-      ambari_server.main()
-      self.assertTrue(setup_https_method.called)
-      self.assertEqual(is_server_runing_method.call_count, 1)
-      self.assertFalse(False, ambari_server.VERBOSE)
-      self.assertFalse(False, ambari_server.SILENT)
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_setup(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method):
-    opm = OptionParserMock.return_value
-    options = MagicMock()
-    args = ["setup"]
-    opm.parse_args.return_value = (options, args)
-
-    options.database=None
-    options.sid_or_sname = "sid"
-    ambari_server.main()
-
-    self.assertTrue(setup_method.called)
-    self.assertFalse(start_method.called)
-    self.assertFalse(stop_method.called)
-    self.assertFalse(reset_method.called)
-
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
-
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_start(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method):
-    opm = OptionParserMock.return_value
-    options = MagicMock()
-    args = ["setup"]
-    opm.parse_args.return_value = (options, args)
-
-    options.database=None
-    options.sid_or_sname = "sname"
-    ambari_server.main()
-
-    self.assertTrue(setup_method.called)
-    self.assertFalse(start_method.called)
-    self.assertFalse(stop_method.called)
-    self.assertFalse(reset_method.called)
-
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
-
-
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_start_debug_short(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method):
-    opm = OptionParserMock.return_value
-    options = MagicMock()
-    args = ["start", "-g"]
-    opm.parse_args.return_value = (options, args)
-
-    options.database=None
-    options.sid_or_sname = "sid"
-
-    ambari_server.main()
-
-    self.assertFalse(setup_method.called)
-    self.assertTrue(start_method.called)
-    self.assertFalse(stop_method.called)
-    self.assertFalse(reset_method.called)
-
-    self.assertTrue(ambari_server.SERVER_DEBUG_MODE)  
-
-
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_start_debug_long(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method):
-    opm = OptionParserMock.return_value
-    options = MagicMock()
-    args = ["start", "--debug"]
-    opm.parse_args.return_value = (options, args)
-    options.database=None
-    options.sid_or_sname = "sid"
-
-    ambari_server.main()
-
-    self.assertFalse(setup_method.called)
-    self.assertTrue(start_method.called)
-    self.assertFalse(stop_method.called)
-    self.assertFalse(reset_method.called)
-
-    self.assertTrue(ambari_server.SERVER_DEBUG_MODE)
-
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_stop(self, OptionParserMock, reset_method, stop_method,
-                          start_method, setup_method):
-    opm = OptionParserMock.return_value
-    options = MagicMock()
-    args = ["stop"]
-    opm.parse_args.return_value = (options, args)
-
-    options.database = None
-    options.sid_or_sname = "sid"
-
-    ambari_server.main()
-
-    self.assertFalse(setup_method.called)
-    self.assertFalse(start_method.called)
-    self.assertTrue(stop_method.called)
-    self.assertFalse(reset_method.called)
-
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
-
-
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch('optparse.OptionParser')
-  def test_main_test_reset(self, OptionParserMock, reset_method, stop_method,
-                           start_method, setup_method):
-    opm = OptionParserMock.return_value
-
-    options = MagicMock()
-    args = ["reset"]
-    opm.parse_args.return_value = (options, args)
-    options.database=None
-    options.sid_or_sname = "sid"
-
-    ambari_server.main()
-
-    self.assertFalse(setup_method.called)
-    self.assertFalse(start_method.called)
-    self.assertFalse(stop_method.called)
-    self.assertTrue(reset_method.called)
-
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
-
-
-  def test_configure_postgresql_conf(self):
-    tf1 = tempfile.NamedTemporaryFile()
-    ambari_server.POSTGRESQL_CONF_FILE = tf1.name
-
-    with open(ambari_server.POSTGRESQL_CONF_FILE, 'w') as f:
-      f.write("#listen_addresses = '127.0.0.1'        #\n")
-      f.write("#listen_addresses = '127.0.0.1'")
-
-    ambari_server.configure_postgresql_conf()
-
-    expected  = self.get_file_string(self.get_samples_dir(
-      "configure_postgresql_conf1"))
-    result = self.get_file_string(ambari_server.POSTGRESQL_CONF_FILE)
-    self.assertEqual(expected, result, "postgresql.conf not updated")
-
-    mode = oct(os.stat(ambari_server.POSTGRESQL_CONF_FILE)[stat.ST_MODE])
-    str_mode = str(mode)[-4:]
-    self.assertEqual("0644", str_mode, "Wrong file permissions")
-
-
-  @patch.object(ambari_server, "restart_postgres")
-  @patch.object(ambari_server, "get_postgre_status")
-  @patch.object(ambari_server, "configure_postgresql_conf")
-  @patch.object(ambari_server, "configure_pg_hba_ambaridb_users")
-  @patch.object(ambari_server, "configure_pg_hba_postgres_user")
-  def test_configure_postgres(self, configure_pg_hba_postgres_user_mock,
-                              configure_pg_hba_ambaridb_users_mock,
-                              configure_postgresql_conf_mock,
-                              get_postgre_status_mock,
-                              restart_postgres_mock):
-    tf1 = tempfile.NamedTemporaryFile()
-    tf2 = tempfile.NamedTemporaryFile()
-    ambari_server.PG_HBA_CONF_FILE = tf1.name
-    ambari_server.PG_HBA_CONF_FILE_BACKUP = tf2.name
-    args = MagicMock()
-
-    out = StringIO.StringIO()
-    sys.stdout = out
-    rcode = ambari_server.configure_postgres()
-    sys.stdout = sys.__stdout__
-    self.assertEqual(0, rcode)
-    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
-
-    rcode = ambari_server.configure_postgres()
-
-    self.assertTrue(os.path.isfile(ambari_server.PG_HBA_CONF_FILE_BACKUP),
-      "postgresql.conf backup not created")
-    self.assertTrue(configure_pg_hba_postgres_user_mock.called)
-    self.assertTrue(configure_pg_hba_ambaridb_users_mock.called)
-    mode = oct(os.stat(ambari_server.PG_HBA_CONF_FILE)[stat.ST_MODE])
-    str_mode = str(mode)[-4:]
-    self.assertEqual("0644", str_mode, "Wrong file permissions")
-    self.assertTrue(configure_postgresql_conf_mock.called)
-    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()
-    self.assertEqual(0, rcode)
-    os.unlink(ambari_server.PG_HBA_CONF_FILE_BACKUP)
-    sys.stdout = sys.__stdout__
-
-
-
-  @patch("time.sleep")
-  @patch("subprocess.Popen")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "get_postgre_status")
-  @patch.object(ambari_server, "print_info_msg")
-  def test_restart_postgres(self, printInfoMsg_mock, get_postgre_status_mock,
-                            run_os_command_mock, popenMock, sleepMock):
-    p = MagicMock()
-    p.poll.return_value = 0
-    popenMock.return_value = p
-    rcode = ambari_server.restart_postgres()
-    self.assertEqual(0, rcode)
-
-    p.poll.return_value = None
-    get_postgre_status_mock.return_value = "stopped"
-    run_os_command_mock.return_value = (1, None, None)
-    rcode = ambari_server.restart_postgres()
-    self.assertEqual(1, rcode)
-
-
-
-  @patch("shlex.split")
-  @patch("subprocess.Popen")
-  @patch.object(ambari_server, "print_info_msg")
-  def test_run_os_command(self, printInfoMsg_mock, popenMock, splitMock):
-
-    p = MagicMock()
-    p.communicate.return_value = (None, None)
-    p.returncode = 3
-    popenMock.return_value = p
-
-    # with list arg
-    cmd = ["exec", "arg"]
-    ambari_server.run_os_command(cmd)
-    self.assertFalse(splitMock.called)
-
-    # with str arg
-    resp = ambari_server.run_os_command("runme")
-    self.assertEqual(3, resp[0])
-    self.assertTrue(splitMock.called)
-
-
-
-  @patch.object(ambari_server, "get_conf_dir")
-  @patch.object(ambari_server, "search_file")
-  def test_write_property(self, search_file_mock, get_conf_dir_mock):
-
-    expected_content = "key1=val1\n"
-
-    tf1 = tempfile.NamedTemporaryFile()
-    search_file_mock.return_value = tf1.name
-    ambari_server.write_property("key1", "val1")
-    result = tf1.read()
-    self.assertTrue(expected_content in result)
-
-
-
-  @patch.object(ambari_server, "configure_database_username_password")
-  @patch.object(ambari_server, "run_os_command")
-  def test_setup_db(self, run_os_command_mock,
-                    configure_database_username_password_mock):
-
-    run_os_command_mock.return_value = (0, None, None)
-    result = ambari_server.setup_db(MagicMock())
-    self.assertTrue(configure_database_username_password_mock.called)
-    self.assertEqual(0, result)
-
-  @patch.object(ambari_server, "configure_database_username_password")
-  @patch("time.sleep")
-  @patch.object(ambari_server, "run_os_command")
-  def test_setup_db_connect_attempts_fail(self, run_os_command_mock,
-                                          sleep_mock, config_db_mock):
-    run_os_command_mock.side_effect = [(1, "error", "error"),(1, "error", "error"),
-                                       (1, "error", "error")]
-    result = ambari_server.setup_db(MagicMock())
-    self.assertTrue(run_os_command_mock.called)
-    self.assertEqual(1, result)
-    self.assertEqual(3, sleep_mock.call_count)
-    pass
-
-  @patch.object(ambari_server, "configure_database_username_password")
-  @patch("time.sleep")
-  @patch.object(ambari_server, "run_os_command")
-  def test_setup_db_connect_attempts_success(self, run_os_command_mock,
-                                             sleep_mock, config_db_mock):
-    run_os_command_mock.side_effect = [(1, "error", "error"),(0, None, None),
-                                       (0, None, None)]
-    result = ambari_server.setup_db(MagicMock())
-    self.assertTrue(run_os_command_mock.called)
-    self.assertEqual(0, result)
-    self.assertEqual(1, sleep_mock.call_count)
-    pass
-
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "run_os_command")
-  def test_check_selinux(self, run_os_command_mock, getYNInput_mock):
-    run_os_command_mock.return_value = (0, ambari_server.SE_STATUS_DISABLED,
-                                        None)
-    rcode = ambari_server.check_selinux()
-    self.assertEqual(0, rcode)
-
-    getYNInput_mock.return_value = True
-    run_os_command_mock.return_value = (0,"enabled "
-                                          + ambari_server.SE_MODE_ENFORCING,
-                                        None)
-    rcode = ambari_server.check_selinux()
-    self.assertEqual(0, rcode)
-    self.assertTrue(run_os_command_mock.called)
-    self.assertTrue(getYNInput_mock.called)
-
-
-
-  @patch.object(ambari_server, "print_info_msg")
-  def test_get_ambari_jars(self, printInfoMsg_mock):
-
-    env = "/ambari/jars"
-    os.environ[ambari_server.AMBARI_SERVER_LIB] = env
-    result = ambari_server.get_ambari_jars()
-    self.assertEqual(env, result)
-
-    del os.environ[ambari_server.AMBARI_SERVER_LIB]
-    result = ambari_server.get_ambari_jars()
-    self.assertEqual("/usr/lib/ambari-server", result)
-    self.assertTrue(printInfoMsg_mock.called)
-
-
-  @patch("glob.glob")
-  @patch.object(ambari_server, "print_info_msg")
-  def test_get_share_jars(self, printInfoMsg_mock, globMock):
-    globMock.return_value = ["one", "two"]
-    expected = "one:two:one:two"
-    result = ambari_server.get_share_jars()
-    self.assertEqual(expected, result)
-    globMock.return_value = []
-    expected = ""
-    result = ambari_server.get_share_jars()
-    self.assertEqual(expected, result)
-
-
-  @patch("glob.glob")
-  @patch.object(ambari_server, "print_info_msg")
-  def test_get_ambari_classpath(self, printInfoMsg_mock, globMock):
-    globMock.return_value = ["one"]
-    result = ambari_server.get_ambari_classpath()
-    self.assertTrue(ambari_server.get_ambari_jars() in result)
-    self.assertTrue(ambari_server.get_share_jars() in result)
-    globMock.return_value = []
-    result = ambari_server.get_ambari_classpath()
-    self.assertTrue(ambari_server.get_ambari_jars() in result)
-    self.assertFalse(":" in result)
-
-
-  @patch.object(ambari_server, "print_info_msg")
-  def test_get_conf_dir(self, printInfoMsg_mock):
-    env = "/dummy/ambari/conf"
-    os.environ[ambari_server.AMBARI_CONF_VAR] = env
-    result = ambari_server.get_conf_dir()
-    self.assertEqual(env, result)
-
-    del os.environ[ambari_server.AMBARI_CONF_VAR]
-    result = ambari_server.get_conf_dir()
-    self.assertEqual("/etc/ambari-server/conf", result)
-
-
-  def test_search_file(self):
-
-    path = os.path.dirname(__file__)
-    result = ambari_server.search_file(__file__, path)
-    expected = os.path.abspath(__file__)
-    self.assertEqual(expected, result)
-
-    result = ambari_server.search_file("non_existent_file", path)
-    self.assertEqual(None, result)
-
-
-  @patch.object(ambari_server, "search_file")
-  def test_find_properties_file(self, search_file_mock):
-    # Testing case when file is not found
-    search_file_mock.return_value = None
-    try:
-      ambari_server.find_properties_file()
-      self.fail("File not found'")
-    except FatalException:
-      # Expected
-      pass
-    self.assertTrue(search_file_mock.called)
-
-    # Testing case when file is found
-    value = MagicMock()
-    search_file_mock.return_value = value
-    result = ambari_server.find_properties_file()
-    self.assertTrue(result is value)
-
-
-  @patch.object(ambari_server, "find_properties_file")
-  @patch("__builtin__.open")
-  @patch("ambari-server.Properties")
-  def test_read_ambari_user(self, properties_mock, open_mock, find_properties_file_mock):
-    open_mock.return_value = "dummy"
-    find_properties_file_mock.return_value = "dummy"
-    # Testing with defined user
-    properties_mock.return_value.__getitem__.return_value = "dummy_user"
-    user = ambari_server.read_ambari_user()
-    self.assertEquals(user, "dummy_user")
-    # Testing with undefined user
-    properties_mock.return_value.__getitem__.return_value = None
-    user = ambari_server.read_ambari_user()
-    self.assertEquals(user, None)
-
-
-  @patch("os.path.exists")
-  @patch.object(ambari_server, "set_file_permissions")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch.object(ambari_server, "get_value_from_properties")
-  @patch("os.mkdir")
-  def test_adjust_directory_permissions(self, mkdir_mock,
-            get_value_from_properties_mock, get_ambari_properties_mock,
-            run_os_command_mock, set_file_permissions_mock, exists_mock):
-    # Testing boostrap dir wipe
-    properties_mock = MagicMock()
-    get_value_from_properties_mock.return_value = "dummy_bootstrap_dir"
-    ambari_server.adjust_directory_permissions("user")
-    exists_mock.return_value = False
-    self.assertEquals(run_os_command_mock.call_args_list[0][0][0], "rm -rf dummy_bootstrap_dir")
-    self.assertTrue(mkdir_mock.called)
-
-    set_file_permissions_mock.reset_mock()
-    # Test recursive calls
-    old_list = ambari_server.NR_ADJUST_OWNERSHIP_LIST
-
-    ambari_server.NR_ADJUST_OWNERSHIP_LIST = [
-      ( "/etc/ambari-server/conf", "755", "{0}", True ),
-      ( "/etc/ambari-server/conf/ambari.properties", "644", "{0}", False )
-    ]
-
-    ambari_server.adjust_directory_permissions("user")
-    self.assertTrue(len(set_file_permissions_mock.call_args_list) ==
-                    len(ambari_server.NR_ADJUST_OWNERSHIP_LIST))
-    self.assertEquals(set_file_permissions_mock.call_args_list[0][0][3], True)
-    self.assertEquals(set_file_permissions_mock.call_args_list[1][0][3], False)
-
-    ambari_server.NR_ADJUST_OWNERSHIP_LIST = old_list
-
-
-  @patch("os.path.exists")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "print_warning_msg")
-  @patch.object(ambari_server, "print_info_msg")
-  def test_set_file_permissions(self, print_info_msg_mock, print_warning_msg_mock,
-                                run_os_command_mock, exists_mock):
-
-    # Testing not existent file scenario
-    exists_mock.return_value = False
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", False)
-    self.assertFalse(run_os_command_mock.called)
-    self.assertTrue(print_info_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-    # Testing OK scenario
-    exists_mock.return_value = True
-    run_os_command_mock.side_effect = [(0, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", False)
-    self.assertTrue(len(run_os_command_mock.call_args_list) == 2)
-    self.assertFalse(print_warning_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-    # Testing first command fail
-    run_os_command_mock.side_effect = [(1, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", False)
-    self.assertTrue(len(run_os_command_mock.call_args_list) == 2)
-    self.assertTrue(print_warning_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-    # Testing second command fail
-    run_os_command_mock.side_effect = [(0, "", ""), (1, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", False)
-    self.assertTrue(len(run_os_command_mock.call_args_list) == 2)
-    self.assertTrue(print_warning_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-    # Testing recursive operation
-
-    exists_mock.return_value = True
-    run_os_command_mock.side_effect = [(0, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", True)
-    self.assertTrue(len(run_os_command_mock.call_args_list) == 2)
-    self.assertTrue("-R" in run_os_command_mock.call_args_list[0][0][0])
-    self.assertTrue("-R" in run_os_command_mock.call_args_list[1][0][0])
-    self.assertFalse(print_warning_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-    # Testing non-recursive operation
-
-    exists_mock.return_value = True
-    run_os_command_mock.side_effect = [(0, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
-                                       "dummy-user", False)
-    self.assertTrue(len(run_os_command_mock.call_args_list) == 2)
-    self.assertFalse("-R" in run_os_command_mock.call_args_list[0][0][0])
-    self.assertFalse("-R" in run_os_command_mock.call_args_list[1][0][0])
-    self.assertFalse(print_warning_msg_mock.called)
-
-    run_os_command_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-
-
-
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "print_warning_msg")
-  @patch.object(ambari_server, "run_os_command")
-  def test_create_custom_user(self, run_os_command_mock, print_warning_msg_mock,
-          print_info_msg_mock, get_validated_string_input_mock):
-    user = "dummy-user"
-    get_validated_string_input_mock.return_value = user
-
-    # Testing scenario: absent user
-    run_os_command_mock.side_effect = [(0, "", "")]
-    result = ambari_server.create_custom_user()
-    self.assertFalse(print_warning_msg_mock.called)
-    self.assertEquals(result, (0, user))
-
-    print_info_msg_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-    run_os_command_mock.reset_mock()
-
-    # Testing scenario: existing user
-    run_os_command_mock.side_effect = [(9, "", "")]
-    result = ambari_server.create_custom_user()
-    self.assertTrue("User dummy-user already exists" in str(print_info_msg_mock.call_args_list[1][0]))
-    self.assertEquals(result, (0, user))
-
-    print_info_msg_mock.reset_mock()
-    print_warning_msg_mock.reset_mock()
-    run_os_command_mock.reset_mock()
-
-    # Testing scenario: os command fail
-    run_os_command_mock.side_effect = [(1, "", "")]
-    result = ambari_server.create_custom_user()
-    self.assertTrue(print_warning_msg_mock.called)
-    self.assertEquals(result, (1, None))
-
-
-
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "create_custom_user")
-  @patch.object(ambari_server, "write_property")
-  @patch.object(ambari_server, "adjust_directory_permissions")
-  @patch.object(ambari_server, "print_error_msg")
-  def test_check_ambari_user(self, print_error_msg_mock,
-            adjust_directory_permissions_mock, write_property_mock,
-            create_custom_user_mock, get_YN_input_mock, read_ambari_user_mock):
-
-    # Scenario: user is already defined, user does not want to reconfigure it
-    read_ambari_user_mock.return_value = "dummy-user"
-    get_YN_input_mock.return_value = False
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertFalse(write_property_mock.called)
-    self.assertFalse(create_custom_user_mock.called)
-    self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
-
-    get_YN_input_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-
-    # Scenario: user is already defined, but user wants to reconfigure it
-
-    read_ambari_user_mock.return_value = "dummy-user"
-    create_custom_user_mock.return_value = (0, "new-dummy-user")
-    get_YN_input_mock.return_value = True
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "new-dummy-user")
-    self.assertTrue(create_custom_user_mock.called)
-    self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
-
-    get_YN_input_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-
-    # Negative scenario: user is already defined, but user wants
-    # to reconfigure it, user creation failed
-
-    read_ambari_user_mock.return_value = "dummy-user"
-    create_custom_user_mock.return_value = (1, None)
-    get_YN_input_mock.return_value = True
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called)
-    self.assertFalse(write_property_mock.called)
-    self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
-
-    get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-
-    # Scenario: user is not defined (setup process)
-    read_ambari_user_mock.return_value = None
-    get_YN_input_mock.return_value = True
-    create_custom_user_mock.return_value = (0, "dummy-user")
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "dummy-user")
-    self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
-
-    get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-
-    # Scenario: user is not defined (setup process), user creation failed
-
-    read_ambari_user_mock.return_value = None
-    get_YN_input_mock.return_value = True
-    create_custom_user_mock.return_value = (1, None)
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called)
-    self.assertFalse(write_property_mock.called)
-    self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
-
-    get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-
-    # negative scenario: user is not defined (setup process), user creation failed
-
-    read_ambari_user_mock.return_value = None
-    get_YN_input_mock.return_value = True
-    create_custom_user_mock.return_value = (1, None)
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called)
-    self.assertFalse(write_property_mock.called)
-    self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
-
-    get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    write_property_mock.reset_mock()
-    adjust_directory_permissions_mock.reset_mock()
-
-    # Scenario: user is not defined and left to be root
-    read_ambari_user_mock.return_value = None
-    get_YN_input_mock.return_value = False
-    result = ambari_server.check_ambari_user()
-    self.assertTrue(get_YN_input_mock.called)
-    self.assertFalse(create_custom_user_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "root")
-    self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
-
-
-  @patch.object(ambari_server, "search_file")
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "set_file_permissions")
-  def test_store_password_file(self, set_file_permissions_mock,
-                    read_ambari_user_mock, open_mock, search_file_mock):
-    search_file_mock.return_value = "/etc/ambari-server/conf/ambari.properties"
-    open_mock.return_value = MagicMock()
-    ambari_server.store_password_file("password", "passfile")
-    self.assertTrue(set_file_permissions_mock.called)
-
-
-  @patch.object(ambari_server, "run_os_command")
-  def test_check_iptables(self, run_os_command_mock):
-    run_os_command_mock.return_value = (1, "test", "")
-    rcode, info = ambari_server.check_iptables()
-    self.assertEqual(1, rcode)
-    self.assertEqual("test", info)
-
-    run_os_command_mock.return_value = (2, "",
-                                        ambari_server.IP_TBLS_SRVC_NT_FND)
-    rcode = ambari_server.check_iptables()
-    self.assertEqual(0, rcode)
-
-
-  def test_dlprogress(self):
-
-    out = StringIO.StringIO()
-    sys.stdout = out
-    ambari_server.dlprogress("filename", 10, 2, 100)
-    sys.stdout = sys.__stdout__
-    self.assertNotEqual("", out.getvalue())
-
-
-  @patch("urllib2.urlopen")
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "dlprogress")
-  def test_track_jdk(self, dlprogress_mock, openMock, urlopenMock):
-
-    u = MagicMock()
-    u.info.return_value = {"Content-Length":"24576"}
-    chunks = [None, "second", "first"]
-    def side_effect(*args, **kwargs):
-      return chunks.pop()
-    u.read.side_effect = side_effect
-    urlopenMock.return_value = u
-
-    f = MagicMock()
-    openMock.return_value = f
-
-    ambari_server.track_jdk("base", "url", "local")
-
-    self.assertEqual(0, len(chunks))
-    self.assertTrue(f.write.called)
-    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")
-  @patch.object(ambari_server, "get_ambari_properties")
-  def test_install_jce_manualy(self, get_ambari_properties_mock,\
-                               os_path_exists_mock, os_path_join_mock,\
-                               shutil_copy_mock):
-    args = MagicMock()
-    args.jce_policy = "somewhere"
-    p = MagicMock()
-    get_ambari_properties_mock.return_value = p
-    p.__getitem__.side_effect = None
-    p.__getitem__.return_value = "somewhere"
-    os_path_exists_mock.return_value = True
-    os_path_join_mock.return_value = \
-                            "/var/lib/ambari-server/resources/jce_policy-6.zip" 
-    ambari_server.install_jce_manualy(args)	
-    self.assertTrue(shutil_copy_mock.called)
-
-    shutil_copy_mock.side_effect = Exception("exception")
-    try:
-      ambari_server.install_jce_manualy(args)
-      self.fail("Should throw exception because of not found jce_policy-6.zip")
-    except Exception:
-       # Expected
-      self.assertTrue(shutil_copy_mock.called)
-      pass  
-
-    shutil_copy_mock.side_effect = None
-    args.jce_policy = None
-    ambari_server.install_jce_manualy(args)
-
-
-  @patch.object(ambari_server, 'read_ambari_user')
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "find_properties_file")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch.object(ambari_server, "is_server_runing")
-  @patch.object(ambari_server, "import_cert_and_key_action")  
-  @patch.object(ambari_server, "get_YN_input")  
-  @patch("__builtin__.open")
-  @patch("ambari-server.Properties")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "is_valid_cert_host")  
-  @patch.object(ambari_server, "is_valid_cert_exp") 
-  def test_setup_https(self, is_valid_cert_exp_mock, is_valid_cert_host_mock,\
-                       is_root_mock, Properties_mock, open_Mock, get_YN_input_mock,\
-                       import_cert_and_key_action_mock,
-                       is_server_runing_mock, get_ambari_properties_mock,\
-                       find_properties_file_mock,\
-                       get_validated_string_input_mock,
-                       read_ambari_user_method):
-      
-    is_valid_cert_exp_mock.return_value=True
-    is_valid_cert_host_mock.return_value=True
-    args = MagicMock()
-    open_Mock.return_value = file
-    p = get_ambari_properties_mock.return_value
-
-    # Testing call under non-root
-    is_root_mock.return_value = False
-    try:
-      ambari_server.setup_https(args)
-      self.fail("Should throw exception")
-    except FatalException as fe:
-      # Expected
-      self.assertTrue("root-level" in fe.reason)
-      pass
-
-    # Testing call under root
-    is_root_mock.return_value = True
-    read_ambari_user_method.return_value = None
-    #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]
-    get_validated_string_input_mock.side_effect = ["4444"]
-    get_property_expected = "[call('security.server.keys_dir'),\n"+\
-                            " call('client.api.ssl.port'),\n"+\
-                            " call('client.api.ssl.port'),\n call('api.ssl')]"
-    process_pair_expected = "[call('client.api.ssl.port', '4444')]"
-    ambari_server.SILENT = False
-    ambari_server.setup_https(args)
-    
-    self.assertTrue(p.process_pair.called)
-    self.assertTrue(p.get_property.call_count == 4)
-    self.assertEqual(str(p.get_property.call_args_list), get_property_expected)
-    self.assertEqual(str(p.process_pair.call_args_list), process_pair_expected)
-    self.assertTrue(p.store.called)
-    self.assertTrue(import_cert_and_key_action_mock.called)
-
-    p.process_pair.reset_mock()
-    p.get_property.reset_mock()
-    p.store.reset_mock()
-    import_cert_and_key_action_mock.reset_mock()
-
-    #Case #2: if client ssl is on and user choose to disable ssl option
-    p.get_property.side_effect = ["key_dir","", "true"]
-    get_YN_input_mock.side_effect = [True]
-    get_validated_string_input_mock.side_effect = ["4444"]
-    get_property_expected = "[call('security.server.keys_dir'),\n"+\
-                            " call('client.api.ssl.port'),\n call('api.ssl')]"
-    process_pair_expected = "[call('api.ssl', 'false')]"
-    ambari_server.setup_https(args)
-    
-    self.assertTrue(p.process_pair.called)
-    self.assertTrue(p.get_property.call_count == 3)
-    self.assertEqual(str(p.get_property.call_args_list), get_property_expected)
-    self.assertEqual(str(p.process_pair.call_args_list), process_pair_expected)
-    self.assertTrue(p.store.called)
-    self.assertFalse(import_cert_and_key_action_mock.called)
-
-    p.process_pair.reset_mock()
-    p.get_property.reset_mock()
-    p.store.reset_mock()
-    import_cert_and_key_action_mock.reset_mock()
-
-    #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]
-    get_validated_string_input_mock.side_effect = ["4444"]
-    get_property_expected = "[call('security.server.keys_dir'),\n"+\
-                            " call('client.api.ssl.port'),\n call('api.ssl')]"
-    process_pair_expected = "[call('client.api.ssl.port', '4444')]"
-    ambari_server.setup_https(args)
-
-    self.assertTrue(p.process_pair.called)
-    self.assertTrue(p.get_property.call_count == 3)
-    self.assertEqual(str(p.get_property.call_args_list), get_property_expected)
-    self.assertEqual(str(p.process_pair.call_args_list), process_pair_expected)
-    self.assertTrue(p.store.called)
-    self.assertTrue(import_cert_and_key_action_mock.called)
-
-    p.process_pair.reset_mock()
-    p.get_property.reset_mock()
-    p.store.reset_mock()
-    import_cert_and_key_action_mock.reset_mock()
-    
-    #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]
-    get_validated_string_input_mock.side_effect = ["4444"]
-    get_property_expected = "[call('security.server.keys_dir'),\n"+\
-    " call('client.api.ssl.port'),\n call('api.ssl')]"
-    process_pair_expected = "[]"
-    ambari_server.setup_https(args)
-
-    self.assertFalse(p.process_pair.called)
-    self.assertTrue(p.get_property.call_count == 3)
-    self.assertEqual(str(p.get_property.call_args_list), get_property_expected)
-    self.assertEqual(str(p.process_pair.call_args_list), process_pair_expected)
-    self.assertFalse(p.store.called)
-    self.assertFalse(import_cert_and_key_action_mock.called)
-
-    p.process_pair.reset_mock()
-    p.get_property.reset_mock()
-    p.store.reset_mock()
-    import_cert_and_key_action_mock.reset_mock()
-
-    #Case #5: if silent mode is enabled
-    ambari_server.SILENT = True
-    try:
-      ambari_server.setup_https(args)
-      self.fail("Should throw exception")
-    except NonFatalException as fe:
-      self.assertTrue("setup-https is not enabled in silent mode" in fe.reason)
-
-    
-  @patch.object(ambari_server, "import_cert_and_key")
-  def test_import_cert_and_key_action(self, import_cert_and_key_mock):
-    import_cert_and_key_mock.return_value = True
-    properties = MagicMock()
-    properties.get_property.side_effect = ["key_dir","5555","6666", "true"]
-    properties.process_pair = MagicMock()
-    expect_process_pair = "[call('client.api.ssl.cert_name', 'https.crt'),\n"+\
-                          " call('client.api.ssl.key_name', 'https.key'),\n"+\
-                          " call('api.ssl', 'true')]"
-    ambari_server.import_cert_and_key_action("key_dir", properties)
-  	
-    self.assertEqual(str(properties.process_pair.call_args_list),\
-                     expect_process_pair)
-    
-  @patch.object(ambari_server, "remove_file")
-  @patch.object(ambari_server, "copy_file")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "set_file_permissions")
-  @patch.object(ambari_server, "import_file_to_keystore")
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "run_os_command")
-  @patch("os.path.join")
-  @patch.object(ambari_server, "get_validated_filepath_input")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "is_valid_cert_host")  
-  @patch.object(ambari_server, "is_valid_cert_exp")  
-  def test_import_cert_and_key(self,is_valid_cert_exp_mock,\
-                               is_valid_cert_host_mock,\
-                               get_validated_string_input_mock,\
-                               get_validated_filepath_input_mock,\
-                               os_path_join_mock, run_os_command_mock,\
-                               open_mock, import_file_to_keystore_mock,\
-                               set_file_permissions_mock, read_ambari_user_mock, copy_file_mock,\
-                               remove_file_mock):
-    is_valid_cert_exp_mock.return_value=True
-    is_valid_cert_host_mock.return_value=True
-    get_validated_string_input_mock.return_value = "password"
-    get_validated_filepath_input_mock.side_effect = \
-                                            ["cert_file_path","key_file_path"]
-    os_path_join_mock.side_effect = ["keystore_file_path", "keystore_file_path_tmp",\
-                                     "pass_file_path", "pass_file_path_tmp",\
-                                     "passin_file_path","password_file_path",\
-                                     "keystore_cert_file_path",\
-                                     "keystore_cert_key_file_path",]
-    run_os_command_mock.return_value = (0, "",	"")
-    om = open_mock.return_value
-    expect_import_file_to_keystore = "[call('keystore_file_path_tmp',"+\
-                                     " 'keystore_file_path'),\n"+\
-                                     " call('pass_file_path_tmp',"+\
-                                     " 'pass_file_path'),\n"+\
-                                     " call('cert_file_path',"+\
-                                     " 'keystore_cert_file_path'),\n"+\
-                                     " call('key_file_path',"+\
-                                     " 'keystore_cert_key_file_path')]"
-
-    ambari_server.import_cert_and_key("key_dir")
-    self.assertTrue(get_validated_filepath_input_mock.call_count == 2)
-    self.assertTrue(get_validated_string_input_mock.called)
-    self.assertEqual(os_path_join_mock.call_count, 8)
-    self.assertTrue(set_file_permissions_mock.call_count == 1)
-    self.assertEqual(str(import_file_to_keystore_mock.call_args_list),\
-                         expect_import_file_to_keystore)
-
-  @patch.object(ambari_server, "remove_file")
-  @patch.object(ambari_server, "copy_file")
-  @patch.object(ambari_server, "generate_random_string")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "set_file_permissions")
-  @patch.object(ambari_server, "import_file_to_keystore")
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "run_os_command")
-  @patch("os.path.join")
-  @patch.object(ambari_server, "get_validated_filepath_input")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "is_valid_cert_host")  
-  @patch.object(ambari_server, "is_valid_cert_exp")  
-  def test_import_cert_and_key_with_empty_password(self, \
-    is_valid_cert_exp_mock, is_valid_cert_host_mock,                                         
-    get_validated_string_input_mock, get_validated_filepath_input_mock,\
-    os_path_join_mock, run_os_command_mock, open_mock, \
-    import_file_to_keystore_mock, set_file_permissions_mock,
-    read_ambari_user_mock, generate_random_string_mock, copy_file_mock,\
-    remove_file_mock):
-      
-    is_valid_cert_exp_mock.return_value=True
-    is_valid_cert_host_mock.return_value=True
-    get_validated_string_input_mock.return_value = ""
-    get_validated_filepath_input_mock.side_effect =\
-    ["cert_file_path","key_file_path"]
-    os_path_join_mock.side_effect = ["keystore_file_path", "keystore_file_path_tmp",\
-                                     "pass_file_path", "pass_file_path_tmp",\
-                                     "passin_file_path","password_file_path",\
-                                     "keystore_cert_file_path",\
-                                     "keystore_cert_key_file_path",]
-    run_os_command_mock.return_value = (0, "",	"")
-
-    expect_import_file_to_keystore = "[call('keystore_file_path_tmp',"+\
-                                     " 'keystore_file_path'),\n"+\
-                                     " call('pass_file_path_tmp',"+\
-                                     " 'pass_file_path'),\n"+\
-                                     " call('cert_file_path',"+\
-                                     " 'keystore_cert_file_path'),\n"+\
-                                     " call('key_file_path.secured',"+\
-                                     " 'keystore_cert_key_file_path')]"
-
-    ambari_server.import_cert_and_key("key_dir")
-    self.assertEquals(get_validated_filepath_input_mock.call_count, 2)
-    self.assertTrue(get_validated_string_input_mock.called)
-    self.assertEquals(os_path_join_mock.call_count, 8)
-    self.assertEquals(set_file_permissions_mock.call_count, 1)
-    self.assertEqual(str(import_file_to_keystore_mock.call_args_list),\
-      expect_import_file_to_keystore)
-    self.assertTrue(generate_random_string_mock.called)
-
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "copy_file")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "set_file_permissions")
-  @patch.object(ambari_server, "import_file_to_keystore")
-  @patch.object(ambari_server, "run_os_command")
-  @patch("os.path.join")
-  @patch.object(ambari_server, "get_validated_filepath_input")
-  @patch.object(ambari_server, "get_validated_string_input")
-  def test_import_cert_and_key_with_incorrect_password(self,
-                                                       get_validated_string_input_mock,\
-                                                       get_validated_filepath_input_mock,\
-                                                       os_path_join_mock,\
-                                                       run_os_command_mock,\
-                                                       import_file_to_keystore_mock,\
-                                                       set_file_permissions_mock,\
-                                                       read_ambari_user_mock,\
-                                                       is_root_mock,\
-                                                       copy_file_mock,\
-                                                       open_mock):
-    get_validated_string_input_mock.return_value = "incorrect_password"
-    get_validated_filepath_input_mock.return_value = 'filename'
-    open_mock.return_value = MagicMock()
-
-    os_path_join_mock.return_value = ''
-    is_root_mock.return_value = True
-
-
-    #provided password doesn't match, openssl command returns an error
-    run_os_command_mock.return_value = (1, "",	"Some error message")
-
-    self.assertFalse(ambari_server.import_cert_and_key_action(*["key_dir", None]))
-    self.assertFalse(ambari_server.import_cert_and_key("key_dir"))
-
-  def test_is_valid_cert_exp(self):
-    
-    #No data in certInfo
-    certInfo = {}
-    is_valid = ambari_server.is_valid_cert_exp(certInfo)
-    self.assertFalse(is_valid)
-    
-    #Issued in future
-    issuedOn = (datetime.datetime.now() + datetime.timedelta(hours=1000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    expiresOn = (datetime.datetime.now() + datetime.timedelta(hours=2000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    certInfo = {ambari_server.NOT_BEFORE_ATTR : issuedOn,
-                ambari_server.NOT_AFTER_ATTR  : expiresOn}
-    is_valid = ambari_server.is_valid_cert_exp(certInfo)
-    self.assertFalse(is_valid)
-    
-    #Was expired
-    issuedOn = (datetime.datetime.now() - datetime.timedelta(hours=2000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    expiresOn = (datetime.datetime.now() - datetime.timedelta(hours=1000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    certInfo = {ambari_server.NOT_BEFORE_ATTR : issuedOn,
-                ambari_server.NOT_AFTER_ATTR  : expiresOn}
-    is_valid = ambari_server.is_valid_cert_exp(certInfo)
-    self.assertFalse(is_valid)
-    
-    #Valid
-    issuedOn = (datetime.datetime.now() - datetime.timedelta(hours=2000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    expiresOn = (datetime.datetime.now() + datetime.timedelta(hours=1000)).strftime(ambari_server.SSL_DATE_FORMAT)
-    certInfo = {ambari_server.NOT_BEFORE_ATTR : issuedOn,
-                ambari_server.NOT_AFTER_ATTR  : expiresOn}
-    is_valid = ambari_server.is_valid_cert_exp(certInfo)
-    self.assertTrue(is_valid)
-    
-  @patch.object(ambari_server, "get_fqdn")
-  def test_is_valid_cert_host(self, get_fqdn_mock):
-    
-    #No data in certInfo
-    certInfo = {}
-    is_valid = ambari_server.is_valid_cert_host(certInfo)
-    self.assertFalse(is_valid)
-    
-    #Failed to get FQDN
-    get_fqdn_mock.return_value = None
-    is_valid = ambari_server.is_valid_cert_host(certInfo)
-    self.assertFalse(is_valid)
-    
-    #FQDN and Common name in certificated don't correspond
-    get_fqdn_mock.return_value = 'host1'
-    certInfo = {ambari_server.COMMON_NAME_ATTR : 'host2'}
-    is_valid = ambari_server.is_valid_cert_host(certInfo)
-    self.assertFalse(is_valid)
-    
-    #FQDN and Common name in certificated correspond
-    get_fqdn_mock.return_value = 'host1'
-    certInfo = {ambari_server.COMMON_NAME_ATTR : 'host1'}
-    is_valid = ambari_server.is_valid_cert_host(certInfo)
-    self.assertTrue(is_valid)
-    
-
-  @patch.object(ambari_server, "get_ambari_properties")
-  def test_is_valid_https_port(self, get_ambari_properties_mock):
-    
-    #No ambari.properties
-    get_ambari_properties_mock.return_value = -1
-    is_valid = ambari_server.is_valid_https_port(1111)
-    self.assertEqual(is_valid, False)
-    
-    #User entered port used by one way auth
-    portOneWay = "1111"
-    portTwoWay = "2222"
-    validPort = "3333"
-    get_ambari_properties_mock.return_value = {ambari_server.SRVR_ONE_WAY_SSL_PORT_PROPERTY : portOneWay,
-                                               ambari_server.SRVR_TWO_WAY_SSL_PORT_PROPERTY : portTwoWay}
-    is_valid = ambari_server.is_valid_https_port(portOneWay)
-    self.assertEqual(is_valid, False)
-    
-    #User entered port used by two way auth
-    is_valid = ambari_server.is_valid_https_port(portTwoWay)
-    self.assertEqual(is_valid, False)
-    
-    #User entered valid port
-    get_ambari_properties_mock.return_value = {ambari_server.SRVR_ONE_WAY_SSL_PORT_PROPERTY : portOneWay,
-                                               ambari_server.SRVR_TWO_WAY_SSL_PORT_PROPERTY : portTwoWay}
-    is_valid = ambari_server.is_valid_https_port(validPort)
-    self.assertEqual(is_valid, True)
-
-  @patch("socket.getfqdn")
-  @patch("urllib2.urlopen")
-  @patch.object(ambari_server, "get_ambari_properties")
-  def test_get_fqdn(self, get_ambari_properties_mock, url_open_mock, getfqdn_mock):
-    
-    #No ambari.properties
-    get_ambari_properties_mock.return_value = -1
-    fqdn = ambari_server.get_fqdn()
-    self.assertEqual(fqdn, None)
-    
-    #Check mbari_server.GET_FQDN_SERVICE_URL property name (AMBARI-2612)
-    #property name should be server.fqdn.service.url
-    self.assertEqual(ambari_server.GET_FQDN_SERVICE_URL, "server.fqdn.service.url")
-    
-    #Read FQDN from service
-    p = MagicMock()
-    p[ambari_server.GET_FQDN_SERVICE_URL] = 'someurl'
-    get_ambari_properties_mock.return_value = p
-    
-    u = MagicMock()
-    host = 'host1.domain.com'
-    u.read.return_value = host
-    url_open_mock.return_value = u
-    
-    fqdn = ambari_server.get_fqdn()
-    self.assertEqual(fqdn, host)
-    
-    #Failed to read FQDN from service, getting from socket
-    u.reset_mock()
-    u.side_effect = Exception("Failed to read FQDN from service")
-    getfqdn_mock.return_value = host
-    fqdn = ambari_server.get_fqdn()
-    self.assertEqual(fqdn, host)
-    
-
-  @patch.object(ambari_server, "run_os_command")
-  def test_get_cert_info(self, run_os_command_mock):
-    # Error running openssl command
-    path = 'path/to/certificate'
-    run_os_command_mock.return_value = -1, None, None
-    cert_info = ambari_server.get_cert_info(path)
-    self.assertEqual(cert_info, None)
-    
-    #Empty result of openssl command
-    run_os_command_mock.return_value = 0, None, None
-    cert_info = ambari_server.get_cert_info(path)
-    self.assertEqual(cert_info, None)
-    
-    #Positive scenario
-    notAfter = 'Jul  3 14:12:57 2014 GMT'
-    notBefore = 'Jul  3 14:12:57 2013 GMT'
-    attr1_key = 'A'
-    attr1_value = 'foo'
-    attr2_key = 'B'
-    attr2_value = 'bar'
-    attr3_key = 'CN'
-    attr3_value = 'host.domain.com'
-    subject_pattern = '/{attr1_key}={attr1_value}/{attr2_key}={attr2_value}/{attr3_key}={attr3_value}'
-    subject = subject_pattern.format(attr1_key = attr1_key, attr1_value = attr1_value,
-                                     attr2_key = attr2_key, attr2_value = attr2_value,
-                                     attr3_key = attr3_key, attr3_value = attr3_value)
-    out_pattern = """
-notAfter={notAfter}
-notBefore={notBefore}
-subject={subject}
------BEGIN CERTIFICATE-----
-MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
-...
-5lqd8XxOGSYoMOf+70BLN2sB
------END CERTIFICATE-----
-    """
-    out = out_pattern.format(notAfter = notAfter, notBefore = notBefore, subject = subject)
-    run_os_command_mock.return_value = 0, out, None
-    cert_info = ambari_server.get_cert_info(path)
-    self.assertEqual(cert_info['notAfter'], notAfter)
-    self.assertEqual(cert_info['notBefore'], notBefore)
-    self.assertEqual(cert_info['subject'], subject)
-    self.assertEqual(cert_info[attr1_key], attr1_value)
-    self.assertEqual(cert_info[attr2_key], attr2_value)
-    self.assertEqual(cert_info[attr3_key], attr3_value)
-
-      
-  @patch('__builtin__.raw_input')
-  def test_get_validated_string_input(self, raw_input_mock):
-    prompt = 'prompt'
-    default_value = 'default'
-    description = 'desc'
-    validator = MagicMock()
-    validator.return_value = True
-    inputed_value1 = 'val1'
-    inputed_value2 = 'val2'
-    raw_input_mock.return_value = inputed_value1
-    input = ambari_server.get_validated_string_input(prompt, default_value, None,
-                                             description, False, False, validator)
-    self.assertTrue(validator.called)
-    self.assertEqual(inputed_value1, input)
-    
-    validator.side_effect = [False, True]
-    raw_input_mock.side_effect = [inputed_value1, inputed_value2]
-    input = ambari_server.get_validated_string_input(prompt, default_value, None,
-                                             description, False, False, validator)
-    self.assertEqual(inputed_value2, input)
-    
-    
-
-  @patch.object(ambari_server, "run_os_command")
-  @patch("__builtin__.open")
-  @patch("os.path.exists")
-  def test_is_server_runing(self, os_path_exists_mock, open_mock,\
-                            run_os_command_mock):
-    os_path_exists_mock.return_value = True
-    f = open_mock.return_value
-    f.readline.return_value = "111"
-    run_os_command_mock.return_value = 0, "", ""
-    status, pid = ambari_server.is_server_runing()
-    self.assertTrue(status)
-    self.assertEqual(111, pid)
-    os_path_exists_mock.return_value = False
-    status, pid = ambari_server.is_server_runing()
-    self.assertFalse(status)
-
-
-  @patch("os.chdir")
-  @patch.object(ambari_server, "run_os_command")
-  @patch("sys.exit")
-  @patch.object(ambari_server, "get_YN_input")
-  def test_install_jdk(self, get_YN_input_mock, exit_mock, run_os_command_mock, os_chdir_mock):
-    get_YN_input_mock.return_value = False
-    JDK_INSTALL_DIR = "JDK_INSTALL_DIR"
-    run_os_command_mock.return_value = 0, "", ""
-    ambari_server.install_jdk(MagicMock())
-    self.assertTrue(exit_mock.called)
-    exit_mock.reset()
-    run_os_command_mock.reset()
-    exit_mock.called = False
-    run_os_command_mock.call_count = 0
-    get_YN_input_mock.return_value = True
-    ambari_server.install_jdk(MagicMock())
-    self.assertFalse(exit_mock.called)
-    self.assertEquals(3, run_os_command_mock.call_count)
-    run_os_command_mock.return_value = 1, "", ""
-    failed = False
-    try:
-        ambari_server.install_jdk(MagicMock())
-        self.fail("Exception was not rised!")
-    except FatalException:
-        failed = True
-    self.assertTrue(failed)
-
-
-  @patch.object(ambari_server, "install_jce_manualy")
-  @patch("os.stat")
-  @patch("os.path.isfile")
-  @patch("os.path.exists")
-  @patch.object(ambari_server, "track_jdk")
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "write_property")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "get_JAVA_HOME")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch("shutil.copyfile")
-  def test_download_jdk(self, copyfile_mock, get_ambari_properties_mock, get_JAVA_HOME_mock,\
-                        print_info_msg_mock, write_property_mock,\
-                        run_os_command_mock, get_YN_input_mock, track_jdk_mock,
-                        path_existsMock, path_isfileMock, statMock,\
-                        install_jce_manualy_mock):
-    args = MagicMock()
-    args.java_home = "somewhere"
-    path_existsMock.return_value = False
-    get_JAVA_HOME_mock.return_value = False
-    get_ambari_properties_mock.return_value = -1
-    # Test case: ambari.properties not found
-    try:
-      ambari_server.download_jdk(args)
-      self.fail("Should throw exception because of not found ambari.properties")
-    except FatalException:
-      # Expected
-      self.assertTrue(get_ambari_properties_mock.called)
-      pass
-    # Test case: JDK already exists
-    p = MagicMock()
-    get_ambari_properties_mock.return_value = p
-    p.__getitem__.return_value = "somewhere"
-    get_JAVA_HOME_mock.return_value = True
-    path_existsMock.return_value = True
-    rcode = ambari_server.download_jdk(args)
-    self.assertEqual(0, rcode)
-    # Test case: java home setup
-    get_JAVA_HOME_mock.return_value = False
-    rcode = ambari_server.download_jdk(args)
-    self.assertEqual(0, rcode)
-    self.assertTrue(write_property_mock.called)
-    # Test case: JDK file does not exist, property not defined
-    path_existsMock.return_value = False
-    p = MagicMock()
-    get_ambari_properties_mock.return_value = p
-    p.__getitem__.side_effect = KeyError("test exception")
-    try:
-      ambari_server.download_jdk(args)
-      self.fail("Should throw exception")
-    except FatalException:
-      # Expected
-      pass
-    # Test case: JDK file does not exist, os command (curl) result does not
-    # contain Content-Length
-    p.__getitem__.return_value = "somewhere"
-    p.__getitem__.side_effect = None
-    path_existsMock.return_value = False
-    run_os_command_mock.return_value = (0, "Wrong out", None)
-    try:
-      ambari_server.download_jdk(args)
-      self.fail("Should throw exception")
-    except FatalException:
-      # Expected
-      pass
-    # Successful JDK download
-    ambari_server.JDK_INSTALL_DIR = os.getcwd()
-    get_YN_input_mock.return_value = True
-    run_os_command_mock.return_value = (0, "Creating jdk-1.2/jre"
-                                           "Content-Length: 32000\r\n"
-                                           , None)
-    statResult = MagicMock()
-    statResult.st_size = 32000
-    statMock.return_value = statResult
-    rcode = ambari_server.download_jdk(args)
-    self.assertEqual(0, rcode)
-    # Test case: JDK file does not exist, jdk-location argument passed
-    p.__getitem__.return_value = "somewhere"
-    p.__getitem__.side_effect = None
-    args.jdk_location = "/existing/jdk/file"
-    path_existsMock.side_effect = [False, False, True, False, False, False]
-    ambari_server.download_jdk(args)
-    self.assertTrue(copyfile_mock.called)
-
-    copyfile_mock.reset_mock()
-    # Negative test case: JDK file does not exist, jdk-location argument
-    # (non-accessible file) passed
-    p.__getitem__.return_value = "somewhere"
-    p.__getitem__.side_effect = None
-    args.jdk_location = "/existing/jdk/file"
-    path_existsMock.side_effect = [False, False, True, False, False, False]
-    def copyfile_side_effect(s, d):
-       raise Exception("TerribleException")
-    copyfile_mock.side_effect = copyfile_side_effect
-    try:
-      ambari_server.download_jdk(args)
-      self.fail("Should throw exception")
-    except FatalException:
-      # Expected
-      self.assertTrue(copyfile_mock.called)
-    copyfile_mock.reset_mock()
-    # Test case: jdk is already installed, ensure that JCE check is not skipped
-    p = MagicMock()
-    get_ambari_properties_mock.return_value = p
-    p.__getitem__.return_value = "somewhere"
-    get_JAVA_HOME_mock.return_value = True
-    path_existsMock.return_value = True
-    install_jce_manualy_mock.return_value = 1
-    with patch.object(ambari_server, "download_jce_policy") as download_jce_policy_mock:
-      rcode = ambari_server.download_jdk(args)
-      self.assertTrue(download_jce_policy_mock.called)
-
-    # Test case: Update JAVA_HOME location using command: ambari-server setup -j %NEW_LOCATION%
-    write_property_mock.reset_mock()
-    args.java_home = "somewhere"
-    path_existsMock.return_value = True
-    path_existsMock.side_effect = None
-    get_JAVA_HOME_mock.return_value = True
-    install_jce_manualy_mock.return_value = 0
-    rcode = ambari_server.download_jdk(args)
-    self.assertTrue(write_property_mock.called)
-
-
-  @patch.object(ambari_server, "run_os_command")
-  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)
-
-    run_os_command_mock.return_value = (1, "wrong", None)
-    result = ambari_server.get_postgre_status()
-    self.assertEqual(None, result)
-
-
-  @patch("time.sleep")
-  @patch("subprocess.Popen")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "get_postgre_status")
-  def test_check_postgre_up(self, get_postgre_status_mock, run_os_command_mock,
-                            popen_mock, sleep_mock):
-    p = MagicMock()
-    p.poll.return_value = 0
-    popen_mock.return_value = p
-    run_os_command_mock.return_value = (0, None, None)
-    rcode = ambari_server.check_postgre_up()
-    self.assertEqual(0, rcode)
-
-    p.poll.return_value = 4
-    get_postgre_status_mock.return_value = None
-    rcode = ambari_server.check_postgre_up()
-    self.assertEqual(4, rcode)
-
-
-
-  @patch("platform.linux_distribution")
-  @patch("platform.system")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "print_error_msg")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch.object(ambari_server, "write_property")
-  @patch.object(ambari_server, "get_conf_dir")
-  def test_configure_os_settings(self, get_conf_dir_mock, write_property_mock, get_ambari_properties_mock,
-                                 print_error_msg_mock, print_info_msg_mock,
-                                 systemMock, distMock):
-    get_ambari_properties_mock.return_value = -1
-    rcode = ambari_server.configure_os_settings()
-    self.assertEqual(-1, rcode)
-
-    p = MagicMock()
-    p[ambari_server.OS_TYPE_PROPERTY] = 'somevalue'
-    get_ambari_properties_mock.return_value = p
-    rcode = ambari_server.configure_os_settings()
-    self.assertEqual(0, rcode)
-
-    p.__getitem__.return_value = ""
-    systemMock.return_value = "NonLinux"
-    rcode = ambari_server.configure_os_settings()
-    self.assertEqual(-1, rcode)
-
-    systemMock.return_value = "Linux"
-    distMock.return_value = ("CentOS", "6.3", None)
-    rcode = ambari_server.configure_os_settings()
-    self.assertEqual(0, rcode)
-    self.assertTrue(write_property_mock.called)
-
-
-
-  @patch("__builtin__.open")
-  @patch.object(ambari_server, "Properties")
-  @patch.object(ambari_server, "search_file")
-  @patch.object(ambari_server, "get_conf_dir")
-  def test_get_JAVA_HOME(self, get_conf_dir_mock, search_file_mock,
-                         Properties_mock, openMock):
-    openMock.side_effect = Exception("exception")
-    result = ambari_server.get_JAVA_HOME()
-    self.assertEqual(None, result)
-
-    expected = os.path.dirname(__file__)
-    p = MagicMock()
-    p.__getitem__.return_value = expected
-    openMock.side_effect = None
-    Properties_mock.return_value = p
-    result = ambari_server.get_JAVA_HOME()
-    self.assertEqual(expected, result)
-
-  def test_prompt_db_properties_default(self):
-    args = MagicMock()
-    ambari_server.load_default_db_properties(args)
-    ambari_server.prompt_db_properties(args)
-    self.assertEqual(args.database, "postgres")
-    self.assertEqual(args.database_host, "localhost")
-    self.assertEqual(args.database_name, "ambari")
-    self.assertEqual(args.database_port, "5432")
-
-  @patch.object(ambari_server, "setup_master_key")
-  @patch.object(ambari_server, "read_password")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "get_YN_input")
-  def test_prompt_db_properties_oracle_sname(self, gyni_mock, gvsi_mock, rp_mock, smk_mock):
-    ambari_server.PROMPT_DATABASE_OPTIONS = True
-    gyni_mock.return_value = True
-    list_of_return_values= ["ambari-server", "ambari", "1", "1521", "localhost", "2"]
-    def side_effect(*args, **kwargs):
-      return list_of_return_values.pop()
-    gvsi_mock.side_effect = side_effect
-    rp_mock.return_value = "password"
-    smk_mock.return_value = (None, False, True)
-
-    args = MagicMock()
-    ambari_server.load_default_db_properties(args)
-    ambari_server.prompt_db_properties(args)
-    self.assertEqual(args.database, "oracle")
-    self.assertEqual(args.database_port, "1521")
-    self.assertEqual(args.database_host, "localhost")
-    self.assertEqual(args.database_name, "ambari")
-    self.assertEqual(args.database_username, "ambari-server")
-    self.assertEqual(args.sid_or_sname, "sname")
-
-  @patch.object(ambari_server, "setup_master_key")
-  @patch.object(ambari_server, "read_password")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "get_YN_input")
-  def test_prompt_db_properties_oracle_sid(self, gyni_mock, gvsi_mock, rp_mock, smk_mock):
-    ambari_server.PROMPT_DATABASE_OPTIONS = True
-    gyni_mock.return_value = True
-    list_of_return_values= ["ambari-server", "ambari", "2", "1521", "localhost", "2"]
-    def side_effect(*args, **kwargs):
-      return list_of_return_values.pop()
-    gvsi_mock.side_effect = side_effect
-    rp_mock.return_value = "password"
-    smk_mock.return_value = (None, False, True)
-
-    args = MagicMock()
-    ambari_server.load_default_db_properties(args)
-    ambari_server.prompt_db_properties(args)
-    self.assertEqual(args.database, "oracle")
-    self.assertEqual(args.database_port, "1521")
-    self.assertEqual(args.database_host, "localhost")
-    self.assertEqual(args.database_name, "ambari")
-    self.assertEqual(args.database_username, "ambari-server")
-    self.assertEqual(args.sid_or_sname, "sid")
-
-  @patch.object(ambari_server, "setup_master_key")
-  @patch.object(ambari_server, "read_password")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "get_YN_input")
-  def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, rp_mock, smk_mock):
-    ambari_server.PROMPT_DATABASE_OPTIONS = True
-    gyni_mock.return_value = True
-    list_of_return_values= ["ambari-server", "ambari", "1"]
-    def side_effect(*args, **kwargs):
-      return list_of_return_values.pop()
-    gvsi_mock.side_effect = side_effect
-    rp_mock.return_value = "password"
-    smk_mock.return_value = (None, False, True)
-
-    args = MagicMock()
-    ambari_server.load_default_db_properties(args)
-    ambari_server.prompt_db_properties(args)
-    self.assertEqual(args.database, "postgres")
-    self.assertEqual(args.database_port, "5432")
-    self.assertEqual(args.database_host, "localhost")
-    self.assertEqual(args.database_name, "ambari")
-    self.assertEqual(args.database_username, "ambari-server")
-    self.assertEqual(args.sid_or_sname, "sname")
-
-  @patch("glob.glob")
-  @patch.object(ambari_server, "get_JAVA_HOME")
-  def test_find_jdk(self, get_JAVA_HOME_mock, globMock):
-    get_JAVA_HOME_mock.return_value = "somewhere"
-    result = ambari_server.find_jdk()
-    self.assertEqual("somewhere", result)
-
-    get_JAVA_HOME_mock.return_value = None
-    globMock.return_value = []
-    result = ambari_server.find_jdk()
-    self.assertEqual(None, result)
-
-    globMock.return_value = ["one", "two"]
-    result = ambari_server.find_jdk()
-    self.assertNotEqual(None, result)
-
-  @patch("os.path.exists")
-  @patch.object(ambari_server, "remove_file")
-  @patch.object(ambari_server, "is_jdbc_user_changed")
-  @patch.object(ambari_server, 'verify_setup_allowed')
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "configure_os_settings")
-  @patch.object(ambari_server, "download_jdk")
-  @patch.object(ambari_server, "configure_postgres")
-  @patch.object(ambari_server, "setup_db")
-  @patch.object(ambari_server, "check_postgre_up")
-  @patch.object(ambari_server, "check_iptables")
-  @patch.object(ambari_server, "check_ambari_user")
-  @patch.object(ambari_server, "check_jdbc_drivers")
-  @patch.object(ambari_server, "check_selinux")
-  @patch.object(ambari_server, "setup_remote_db")
-  @patch.object(ambari_server, "store_remote_properties")
-  @patch.object(ambari_server, "is_local_database")
-  @patch.object(ambari_server, "store_local_properties")
-  @patch.object(ambari_server, "is_root")
-  def test_setup(self, is_root_mock, store_local_properties_mock, is_local_database_mock, store_remote_properties_mock,
-                 setup_remote_db_mock, check_selinux_mock, check_jdbc_drivers_mock, check_ambari_user_mock,
-                 check_iptables_mock, check_postgre_up_mock, setup_db_mock, configure_postgres_mock,
-                 download_jdk_mock, configure_os_settings_mock,get_YN_input,
-                 verify_setup_allowed_method, is_jdbc_user_changed_mock, remove_file_mock, exists_mock):
-    args = MagicMock()
-    failed = False
-    get_YN_input.return_value = False
-    verify_setup_allowed_method.return_value = 0
-    exists_mock.return_value = False
-    remove_file_mock.return_value = 0
-
-    def reset_mocks():
-      is_jdbc_user_changed_mock.reset_mock()
-      is_root_mock.reset_mock()
-      store_local_properties_mock.reset_mock()
-      store_remote_properties_mock.reset_mock()
-      is_local_database_mock.reset_mock()
-      setup_remote_db_mock.reset_mock()
-      check_selinux_mock.reset_mock()
-      check_jdbc_drivers_mock.reset_mock()
-      check_ambari_user_mock.reset_mock()
-      check_iptables_mock.reset_mock()
-      check_postgre_up_mock.reset_mock()
-      setup_db_mock.reset_mock()
-      configure_postgres_mock.reset_mock()
-      configure_os_settings_mock.reset_mock()
-      pass
-
-
-    # Testing call under non-root
-    is_root_mock.return_value = False
-    try:
-      ambari_server.setup(args)
-      self.fail("Should throw exception")
-    except FatalException as fe:
-      # Expected
-      self.assertTrue("root-level" in fe.reason)
-      pass
-
-    # Testing calls under root
-    # remote case
-    is_root_mock.return_value = True
-    check_selinux_mock.return_value = 0
-    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
-    setup_db_mock.return_value = 0
-    setup_remote_db_mock.return_value = 0
-    is_local_database_mock.return_value = False
-    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
-    store_local_properties_mock.return_value = 0
-
-    result = ambari_server.setup(args)
-
-    self.assertEqual(None, result)
-    self.assertTrue(check_ambari_user_mock.called)
-    self.assertEquals(True, store_remote_properties_mock.called)
-    self.assertEquals(False, store_local_properties_mock.called)
-
-
-    #Local case
-    reset_mocks()
-    is_local_database_mock.return_value = True
-    is_jdbc_user_changed_mock.return_value = False
-
-    try:
-      result = ambari_server.setup(args)
-    except FatalException:
-      self.fail("Setup should be successful")
-    self.assertEqual(None, result)
-    self.assertEquals(True, store_local_properties_mock.called)
-    self.assertEquals(False, store_remote_properties_mock.called)
-    self.assertEquals(True, is_jdbc_user_changed_mock.called)
-    self.assertEquals(False, remove_file_mock.called)
-
-    #if DB user name was changed
-    reset_mocks()
-    is_local_database_mock.return_value = True
-    is_jdbc_user_changed_mock.return_value = True
-
-    try:
-      result = ambari_server.setup(args)
-    except FatalException:
-      self.fail("Setup should be successful")
-    self.assertEqual(None, result)
-    self.assertEquals(True, store_local_properties_mock.called)
-    self.assertEquals(False, store_remote_properties_mock.called)
-    self.assertEquals(True, is_jdbc_user_changed_mock.called)
-    self.assertEquals(True, remove_file_mock.called)
-
-    #negative case
-    reset_mocks()
-    is_local_database_mock.return_value = False
-    setup_remote_db_mock.return_value = -1
-
-    try:
-      result = ambari_server.setup(args)
-      self.fail("Should throw exception")
-    except NonFatalException as fe:
-      self.assertTrue("cli was not found" in fe.reason)
-
-
-
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "setup_db")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "configure_database_username_password")
-  @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "execute_remote_script")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "check_database_name_property")
-  def test_reset(self, check_database_name_property_mock, is_root_mock, execute_remote_script_mock, parse_properties_file_mock, configure_database_username_password_mock,
-                 run_os_command_mock, print_info_msg_mock,
-                 setup_db_mock, get_YN_inputMock):
-
-    parse_properties_file_mock.return_value = 0
-    args = MagicMock()
-    args.persistence_type = "local"
-    get_YN_inputMock.return_value = False
-
-    # Testing call under non-root
-    is_root_mock.return_value = False
-    try:
-      ambari_server.reset(args)
-      self.fail("Should throw exception")
-    except FatalException as fe:
-      # Expected
-      self.assertTrue("root-level" in fe.reason)
-      pass
-
-    # Testing calls under root
-    is_root_mock.return_value = True
-    try:
-      ambari_server.reset(args)
-      self.fail("Should throw exception")
-    except FatalException as fe:
-      # Expected
-      self.assertFalse("root-level" in fe.reason)
-      pass
-
-    get_YN_inputMock.return_value = True
-    run_os_command_mock.return_value = (1, None, None)
-    try:
-      ambari_server.reset(args)
-      self.fail("Should throw exception")
-    except FatalException:
-      # Expected
-      pass
-
-    run_os_command_mock.return_value = (0, None, None)
-    ambari_server.reset(args)
-    self.assertTrue(setup_db_mock.called)
-    
-    #remote db case
-    args.persistence_type = "remote"
-    execute_remote_script_mock.return_value=(0, None, None)
-    rcode = ambari_server.reset(args)
-    self.assertEqual(None, rcode)
-    self.assertTrue(execute_remote_script_mock.called)
-
-
-  @patch.object(ambari_server, "setup_db")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "is_root")
-  @patch.object(ambari_server, "check_database_name_property")
-  def test_silent_reset(self, check_database_name_property_mock, is_root_mock, parse_properties_file_mock,
-                 run_os_command_mock, print_info_msg_mock,
-                 setup_db_mock):
-    is_root_mock.return_value = True
-
-    args = MagicMock()
-    ambari_server.SILENT = True
-    self.assertTrue(ambari_server.SILENT)
-    run_os_command_mock.return_value = (0, None, None)
-
-    def signal_handler(signum, frame):
-       self.fail("Timed out!")
-
-    signal.signal(signal.SIGALRM, signal_handler)
-    signal.alarm(5)
-    rcode = ambari_server.reset(args)
-    signal.alarm(0)
-    self.assertEqual(None, rcode)
-    self.assertTrue(setup_db_mock.called)
-
-  @patch("os.chown")
-  @patch("pwd.getpwnam")
-  @patch.object(ambari_server, 'get_master_key_location')
-  @patch.object(ambari_server, 'save_master_key')
-  @patch('os.chmod', autospec=True)
-  @patch.object(ambari_server, 'get_validated_string_input')
-  @patch("os.environ")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch("os.kill")
-  @patch("os.path.exists")
-  @patch("__builtin__.open")
-  @patch("subprocess.Popen")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "search_file")
-  @patch.object(ambari_server, "find_jdk")
-  @patch.object(ambari_server, "print_error_msg")
-  @patch.object(ambari_server, "check_postgre_up")
-  @patch.object(ambari_server, "check_iptables")
-  @patch.object(ambari_server, "parse_properties_file")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "is_root")
-  @patch("getpass.getuser")
-  @patch("os.chdir")
-  def test_start(self, chdir_mock, getuser_mock, is_root_mock, read_ambari_user_mock,
-                 parse_properties_file_mock, check_iptables_mock, check_postgre_up_mock,
-                 print_error_msg_mock, find_jdk_mock, search_file_mock,
-                 print_info_msg_mock, popenMock, openMock, pexistsMock,
-                 killMock, get_ambari_properties_mock, os_environ_mock,
-                 get_validated_string_input_method, os_chmod_method,
-                 save_master_key_method, get_master_key_location_method,
-                 getpwnam_mock, os_chown_mock):
-    args = MagicMock()
-
-    f = MagicMock()
-    f.readline.return_value = 42
-    openMock.return_value = f
-
-    p = get_ambari_properties_mock.return_value
-    p.get_property.return_value = 'False'
-    search_file_mock.return_value = None
-    pw = MagicMock()
-    pw.setattr('pw_uid', 0)
-    pw.setattr('pw_gid', 0)
-    getpwnam_mock.return_value = pw
-    os_chown_mock.return_value = None
-    # Checking "server is running"
-    pexistsMock.return_value = True
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'Server is running'")
-    except FatalException:
-      # Expected
-      pass
-    self.assertTrue(killMock.called)
-
-    killMock.reset_mock()
-    parse_properties_file_mock.reset_mock()
-
-    pexistsMock.return_value = False
-
-    # Checking situation when ambari user is not set up
-    read_ambari_user_mock.return_value = None
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'Can not detect a system user for Ambari'")
-    except FatalException as e:
-      # Expected
-      self.assertTrue('Unable to detect a system user for Ambari Server.' in e.reason)
-
-    parse_properties_file_mock.reset_mock()
-
-    # Checking start from non-root when current user is not the same as a
-    # custom user
-    read_ambari_user_mock.return_value = "dummy-user"
-    getuser_mock.return_value = "non_custom_user"
-    is_root_mock.return_value = False
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'Can not start ambari-server as user...'")
-    except FatalException as e:
-      # Expected
-      self.assertTrue('Unable to start Ambari Server as user' in e.reason)
-      self.assertFalse(parse_properties_file_mock.called)
-
-    parse_properties_file_mock.reset_mock()
-
-    # Checking "jdk not found"
-    is_root_mock.return_value = True
-    find_jdk_mock.return_value = None
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'No JDK found'")
-    except FatalException as e:
-      # Expected
-      self.assertTrue('No JDK found' in e.reason)
-
-    find_jdk_mock.return_value = "somewhere"
-
-    parse_properties_file_mock.reset_mock()
-
-    ## Testing workflow under root
-    is_root_mock.return_value = True
-
-    # Remote DB
-    args.persistence_type="remote"
-    check_iptables_mock.return_value = (0, None)
-    try:
-      ambari_server.start(args)
-    except FatalException as e:
-      # Ignored
-      pass
-
-    self.assertFalse('Unable to start PostgreSQL server' in e.reason)
-    self.assertFalse(check_postgre_up_mock.called)
-
-    check_postgre_up_mock.reset_mock()
-    parse_properties_file_mock.reset_mock()
-
-    # Local DB
-    args.persistence_type="local"
-
-    # case: postgres failed to start
-    check_postgre_up_mock.return_value = 1
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'Unable to start PostgreSQL server'")
-    except FatalException as e:
-      # Expected
-      self.assertTrue('Unable to start PostgreSQL server' in e.reason)
-      self.assertTrue(check_postgre_up_mock.called)
-
-    parse_properties_file_mock.reset_mock()
-
-    # case: iptables failed to stop
-    check_postgre_up_mock.return_value = 0
-    check_iptables_mock.return_value = (1, ambari_server.IP_TBLS_ENABLED)
-    try:
-      ambari_server.start(args)
-      self.fail("Should fail with 'Failed to stop iptables'")
-    except FatalException as e:
-      # Expected
-      self.assertTrue('Failed to stop iptables' in e.reason)
-
-    parse_properties_file_mock.reset_mock()
-
-    check_iptables_mock.return_value = (0, None)
-    # Case: custom user is "root"
-    read_ambari_user_mock.return_value = "root"
-    ambari_server.start(args)
-    self.assertTrue(popenMock.called)
-    popen_arg = popenMock.call_args[0][0]
-    self.assertTrue(popen_arg[0] == "/bin/sh")
-    popenMock.reset_mock()
-
-    parse_properties_file_mock.reset_mock()
-
-    # Case: custom user is  not "root"
-    read_ambari_user_mock.return_value = "not-root-user"
-    ambari_server.start(args)
-    self.assertTrue(chdir_mock.called)
-    self.assertTrue(popenMock.called)
-    popen_arg = pop

<TRUNCATED>

Mime
View raw message