You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/01/13 22:46:27 UTC

[1/3] ambari git commit: AMBARI-8317 Refactor the OS-dependent Ambari Server Windows components

Repository: ambari
Updated Branches:
  refs/heads/trunk fb947b0cc -> 16bee3858


http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/test/python/custom_actions/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
index f910d06..cb4c540 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -23,7 +23,7 @@ import json
 import os
 import socket
 import subprocess
-from ambari_commons import inet_utils
+from ambari_commons import inet_utils, OSCheck
 from resource_management import Script, ConfigDictionary
 from mock.mock import patch
 from mock.mock import MagicMock
@@ -31,6 +31,13 @@ from unittest import TestCase
 
 from check_host import CheckHost
 
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+  os_distro_value = ('Suse','11','Final')
+else:
+  os_distro_value = ('win2012serverr2','6.3','WindowsServer')
+
 
 class TestCheckHost(TestCase):
 
@@ -232,7 +239,7 @@ class TestCheckHost(TestCase):
     structured_out_mock.assert_called_with({})
 
 
-  @patch("platform.linux_distribution")
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("platform.system")
   @patch.object(Script, 'get_config')
   @patch.object(Script, 'get_tmp_dir')
@@ -246,12 +253,7 @@ class TestCheckHost(TestCase):
   @patch('time.time')
   def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkIptables_mock, getTransparentHugePage_mock,
                        getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock,
-                       get_tmp_dir_mock, get_config_mock, systemMock, distMock):
-
-
-    systemMock.return_value = "Linux"
-    distMock.return_value = ("CentOS", "6.3", None)
-
+                       get_tmp_dir_mock, get_config_mock, systemmock):
     jsonFilePath = os.path.join("../resources/custom_actions", "check_last_agent_env.json")
     with open(jsonFilePath, "r") as jsonFile:
       jsonPayload = json.load(jsonFile)


[2/3] ambari git commit: AMBARI-8317 Refactor the OS-dependent Ambari Server Windows components

Posted by fb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index e7014fc..71d57a0 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -15,38 +15,48 @@ 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 stacks.utils.RMFTestCase import *
 
-import StringIO
-import re
-from unittest import TestCase
 import sys
-from mock.mock import patch, MagicMock, create_autospec
-import os, errno, tempfile
-import signal
-import stat
+import os
 import datetime
-import operator
+import errno
 import json
+from mock.mock import patch, MagicMock, create_autospec
+import operator
 from optparse import OptionParser
 import platform
+import re
 import shutil
-from pwd import getpwnam
+import signal
+import stat
+import StringIO
+import tempfile
+from unittest import TestCase
+
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+from ambari_commons import Firewall, OSCheck, OSConst, FirewallChecks
+from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode
 from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
 from ambari_server import BackupRestore
- 
-# We have to use this import HACK because the filename contains a dash
-from ambari_commons import Firewall, OSCheck, OSConst, FirewallChecks
 
-with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
+if get_platform() != PLATFORM_WINDOWS:
+  os_distro_value = ('Suse','11','Final')
+  from pwd import getpwnam
+else:
+  #No Windows tests for now, but start getting prepared
+  os_distro_value = ('win2012serverr2','6.3','WindowsServer')
+
+# We have to use this import HACK because the filename contains a dash
+with patch("platform.linux_distribution", return_value = os_distro_value):
   with patch("os.symlink"):
     with patch("__builtin__.open"):
       with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']):
-        ambari_server = __import__('ambari-server')
+        _ambari_server_ = __import__('ambari-server')
 
-FatalException = ambari_server.FatalException
-NonFatalException = ambari_server.NonFatalException
+FatalException = _ambari_server_.FatalException
+NonFatalException = _ambari_server_.NonFatalException
 CURR_AMBARI_VERSION = "2.0.0"
 
 class TestAmbariServer(TestCase):
@@ -59,8 +69,8 @@ class TestAmbariServer(TestCase):
     sys.stdout = sys.__stdout__
 
 
-  @patch.object(ambari_server, 'configure_database_username_password')
-  @patch.object(ambari_server, 'run_os_command')
+  @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,
@@ -70,15 +80,15 @@ class TestAmbariServer(TestCase):
     opvm = OptParseValuesMock.return_value
     opvm.database_username = "ffdf"
     tf1 = tempfile.NamedTemporaryFile()
-    ambari_server.PG_HBA_CONF_FILE = tf1.name
+    _ambari_server_.PG_HBA_CONF_FILE = tf1.name
     # Run test
-    ambari_server.configure_pg_hba_ambaridb_users()
+    _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)
+    string_actual = self.get_file_string(_ambari_server_.PG_HBA_CONF_FILE)
     self.assertEquals(string_expected, string_actual)
     pass
 
@@ -86,9 +96,9 @@ class TestAmbariServer(TestCase):
   def test_servicename_regex(self, raw_input_method):
 
     ''' Test to make sure the service name can contain digits '''
-    ambari_server.SILENT = False
+    set_silent(False)
     raw_input_method.return_value = "OT100"
-    result = ambari_server.get_validated_service_name("ambari", 1)
+    result = _ambari_server_.get_validated_service_name("ambari", 1)
     self.assertEqual("OT100", result, "Not accepting digits")
     pass
 
@@ -96,31 +106,31 @@ class TestAmbariServer(TestCase):
   def test_dbname_regex(self, raw_input_method):
 
     ''' Test to make sure the service name can contain digits '''
-    ambari_server.SILENT = False
+    set_silent(False)
     raw_input_method.return_value = "OT100"
-    result = ambari_server.get_validated_db_name("ambari")
+    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
+    _ambari_server_.PG_HBA_CONF_FILE = tf1.name
 
-    with open(ambari_server.PG_HBA_CONF_FILE, 'w') as fout:
+    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()
+    _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)
+    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])
+    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")
 
@@ -134,7 +144,7 @@ class TestAmbariServer(TestCase):
     # test first input
     raw_input_method.return_value = "Y"
 
-    result = ambari_server.get_choice_string_input(prompt, default,
+    result = _ambari_server_.get_choice_string_input(prompt, default,
                                                    firstChoice, secondChoice)
     self.assertEquals(result, True)
     raw_input_method.reset_mock()
@@ -142,7 +152,7 @@ class TestAmbariServer(TestCase):
 
     raw_input_method.return_value = "N"
 
-    result = ambari_server.get_choice_string_input(prompt, default,
+    result = _ambari_server_.get_choice_string_input(prompt, default,
                                                    firstChoice, secondChoice)
     self.assertEquals(result, False)
 
@@ -152,7 +162,7 @@ class TestAmbariServer(TestCase):
 
     raw_input_method.return_value = ""
 
-    result = ambari_server.get_choice_string_input(prompt, default,
+    result = _ambari_server_.get_choice_string_input(prompt, default,
                                                    firstChoice, secondChoice)
     self.assertEquals(result, default)
 
@@ -166,7 +176,7 @@ class TestAmbariServer(TestCase):
 
     raw_input_method.side_effect = side_effect
 
-    result = ambari_server.get_choice_string_input(prompt, default,
+    result = _ambari_server_.get_choice_string_input(prompt, default,
                                                    firstChoice, secondChoice)
     self.assertEquals(result, True)
     self.assertEquals(raw_input_method.call_count, 3)
@@ -184,11 +194,11 @@ class TestAmbariServer(TestCase):
     pattern = "pattern_pp"
     description = "blabla2"
     # check password input
-    self.assertFalse(False, ambari_server.SILENT)
+    self.assertFalse(False, get_silent())
     is_pass = True
     get_pass_method.return_value = "dfdsfdsfds"
 
-    result = ambari_server.get_validated_string_input(prompt, default,
+    result = _ambari_server_.get_validated_string_input(prompt, default,
                                                       pattern, description, is_pass)
 
     self.assertEquals(get_pass_method.return_value, result)
@@ -201,7 +211,7 @@ class TestAmbariServer(TestCase):
     is_pass = False
     raw_input_method.return_value = "dkf90ewuf0"
 
-    result = ambari_server.get_validated_string_input(prompt, default,
+    result = _ambari_server_.get_validated_string_input(prompt, default,
                                                       pattern, description, is_pass)
 
     self.assertEquals(raw_input_method.return_value, result)
@@ -210,12 +220,12 @@ class TestAmbariServer(TestCase):
 
 
   def test_get_pass_file_path(self):
-    result = ambari_server.get_pass_file_path("/etc/ambari/conf_file")
+    result = _ambari_server_.get_pass_file_path("/etc/ambari/conf_file")
     self.assertEquals("/etc/ambari/password.dat", result)
     pass
 
 
-  @patch.object(ambari_server, 'setup_security')
+  @patch.object(_ambari_server_, 'setup_security')
   @patch('optparse.OptionParser')
   def test_main_test_setup_security(self, OptionParserMock,
                                     setup_security_method):
@@ -227,46 +237,46 @@ class TestAmbariServer(TestCase):
     options.sid_or_sname = "sid"
     setup_security_method.return_value = None
 
-    ambari_server.main()
+    _ambari_server_.main()
 
-    ambari_server.main()
+    _ambari_server_.main()
     self.assertTrue(setup_security_method.called)
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
-
-  @patch.object(ambari_server, 'setup_ambari_krb5_jaas')
-  @patch.object(ambari_server, 'setup_master_key')
-  @patch.object(ambari_server, 'setup_component_https')
-  @patch.object(ambari_server, 'setup_https')
-  @patch.object(ambari_server, 'get_validated_string_input')
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
+
+  @patch.object(_ambari_server_, 'setup_ambari_krb5_jaas')
+  @patch.object(_ambari_server_, 'setup_master_key')
+  @patch.object(_ambari_server_, 'setup_component_https')
+  @patch.object(_ambari_server_, 'setup_https')
+  @patch.object(_ambari_server_, 'get_validated_string_input')
   def test_setup_security(self, get_validated_string_input_mock, setup_https,
                           setup_component_https, setup_master_key,
                           setup_ambari_krb5_jaas):
 
     args = {}
     get_validated_string_input_mock.return_value = '1'
-    ambari_server.setup_security(args)
+    _ambari_server_.setup_security(args)
     self.assertTrue(setup_https.called)
 
     get_validated_string_input_mock.return_value = '2'
-    ambari_server.setup_security(args)
+    _ambari_server_.setup_security(args)
     self.assertTrue(setup_component_https.called)
     setup_component_https.assert_called_with("Ganglia", "setup-ganglia-https",
-                          ambari_server.GANGLIA_HTTPS, "ganglia_cert")
+                          _ambari_server_.GANGLIA_HTTPS, "ganglia_cert")
 
     get_validated_string_input_mock.return_value = '3'
-    ambari_server.setup_security(args)
+    _ambari_server_.setup_security(args)
     self.assertTrue(setup_master_key.called)
 
     get_validated_string_input_mock.return_value = '4'
-    ambari_server.setup_security(args)
+    _ambari_server_.setup_security(args)
     self.assertTrue(setup_ambari_krb5_jaas.called)
 
 
   @patch('re.sub')
   @patch('fileinput.FileInput')
-  @patch.object(ambari_server, 'get_validated_string_input')
-  @patch.object(ambari_server, 'search_file')
+  @patch.object(_ambari_server_, 'get_validated_string_input')
+  @patch.object(_ambari_server_, 'search_file')
   @patch('os.path.exists')
   def test_setup_ambari_krb5_jaas(self, exists_mock, search_mock,
                                   get_validated_string_input_mock,
@@ -277,7 +287,7 @@ class TestAmbariServer(TestCase):
 
     # Negative case
     try:
-      ambari_server.setup_ambari_krb5_jaas()
+      _ambari_server_.setup_ambari_krb5_jaas()
       self.fail("Should throw exception")
     except NonFatalException as fe:
       # Expected
@@ -292,17 +302,17 @@ class TestAmbariServer(TestCase):
 
     fileinput_mock.return_value = [ 'keyTab=xyz', 'principal=xyz' ]
 
-    ambari_server.setup_ambari_krb5_jaas()
+    _ambari_server_.setup_ambari_krb5_jaas()
 
     self.assertTrue(fileinput_mock.called)
     self.assertTrue(re_sub_mock.called)
     self.assertTrue(re_sub_mock.call_args_list, [('aaa@aaa.cnn'),
                                                  ('pathtokeytab')])
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -313,21 +323,21 @@ class TestAmbariServer(TestCase):
 
     options.dbms = None
     options.sid_or_sname = "sid"
-    ambari_server.main()
+    _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)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -338,21 +348,21 @@ class TestAmbariServer(TestCase):
 
     options.dbms = None
     options.sid_or_sname = "sname"
-    ambari_server.main()
+    _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)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -364,20 +374,20 @@ class TestAmbariServer(TestCase):
     options.dbms = None
     options.sid_or_sname = "sid"
 
-    ambari_server.main()
+    _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)
+    self.assertTrue(get_debug_mode())
 
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -388,21 +398,21 @@ class TestAmbariServer(TestCase):
     options.dbms = None
     options.sid_or_sname = "sid"
 
-    ambari_server.main()
+    _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)
+    self.assertTrue(get_debug_mode())
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch.object(ambari_server, 'backup')
-  @patch.object(ambari_server, 'restore')
+  @patch.object(_ambari_server_, 'setup')
+  @patch.object(_ambari_server_, 'start')
+  @patch.object(_ambari_server_, 'stop')
+  @patch.object(_ambari_server_, 'reset')
+  @patch.object(_ambari_server_, 'backup')
+  @patch.object(_ambari_server_, 'restore')
   @patch('optparse.OptionParser')
   def test_main_test_backup(self, OptionParserMock, restore_mock, backup_mock, reset_method, stop_method,
                            start_method, setup_method):
@@ -413,7 +423,7 @@ class TestAmbariServer(TestCase):
 
     options.dbms = None
     options.sid_or_sname = "sname"
-    ambari_server.main()
+    _ambari_server_.main()
 
     self.assertTrue(backup_mock.called)
     self.assertFalse(restore_mock.called)
@@ -422,15 +432,15 @@ class TestAmbariServer(TestCase):
     self.assertFalse(stop_method.called)
     self.assertFalse(reset_method.called)
 
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
-  @patch.object(ambari_server, 'backup')
-  @patch.object(ambari_server, 'restore')
+  @patch.object(_ambari_server_, 'setup')
+  @patch.object(_ambari_server_, 'start')
+  @patch.object(_ambari_server_, 'stop')
+  @patch.object(_ambari_server_, 'reset')
+  @patch.object(_ambari_server_, 'backup')
+  @patch.object(_ambari_server_, 'restore')
   @patch('optparse.OptionParser')
   def test_main_test_restore(self, OptionParserMock, restore_mock, backup_mock, reset_method, stop_method,
                             start_method, setup_method):
@@ -441,7 +451,7 @@ class TestAmbariServer(TestCase):
 
     options.dbms = None
     options.sid_or_sname = "sname"
-    ambari_server.main()
+    _ambari_server_.main()
 
     self.assertTrue(restore_mock.called)
     self.assertFalse(backup_mock.called)
@@ -450,13 +460,13 @@ class TestAmbariServer(TestCase):
     self.assertFalse(stop_method.called)
     self.assertFalse(reset_method.called)
 
-    self.assertFalse(False, ambari_server.VERBOSE)
-    self.assertFalse(False, ambari_server.SILENT)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -468,21 +478,21 @@ class TestAmbariServer(TestCase):
     options.dbms = None
     options.sid_or_sname = "sid"
 
-    ambari_server.main()
+    _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)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
 
-  @patch.object(ambari_server, 'setup')
-  @patch.object(ambari_server, 'start')
-  @patch.object(ambari_server, 'stop')
-  @patch.object(ambari_server, 'reset')
+  @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):
@@ -494,42 +504,42 @@ class TestAmbariServer(TestCase):
     options.dbms = None
     options.sid_or_sname = "sid"
 
-    ambari_server.main()
+    _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)
+    self.assertFalse(False, get_verbose())
+    self.assertFalse(False, get_silent())
 
 
   def test_configure_postgresql_conf(self):
     tf1 = tempfile.NamedTemporaryFile()
-    ambari_server.POSTGRESQL_CONF_FILE = tf1.name
+    _ambari_server_.POSTGRESQL_CONF_FILE = tf1.name
 
-    with open(ambari_server.POSTGRESQL_CONF_FILE, 'w') as f:
+    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()
+    _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)
+    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])
+    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")
+  @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,
@@ -537,65 +547,65 @@ class TestAmbariServer(TestCase):
                               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
+    _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
-    retcode, out1, err = ambari_server.configure_postgres()
+    retcode, out1, err = _ambari_server_.configure_postgres()
     sys.stdout = sys.__stdout__
     self.assertEqual(0, retcode)
     self.assertEqual("Backup for pg_hba found, reconfiguration not required\n",
                      out.getvalue())
 
-    ambari_server.PG_HBA_CONF_FILE_BACKUP = tempfile.mktemp()
-    get_postgre_status_mock.return_value = ambari_server.PG_STATUS_RUNNING, 0, "", ""
+    _ambari_server_.PG_HBA_CONF_FILE_BACKUP = tempfile.mktemp()
+    get_postgre_status_mock.return_value = _ambari_server_.PG_STATUS_RUNNING, 0, "", ""
     restart_postgres_mock.return_value = 0, "", ""
 
-    rcode, out, err = ambari_server.configure_postgres()
+    rcode, out, err = _ambari_server_.configure_postgres()
 
-    self.assertTrue(os.path.isfile(ambari_server.PG_HBA_CONF_FILE_BACKUP),
+    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])
+    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)
+    os.unlink(_ambari_server_.PG_HBA_CONF_FILE_BACKUP)
     get_postgre_status_mock.return_value = "stopped", 0, "", ""
-    rcode, out, err = ambari_server.configure_postgres()
+    rcode, out, err = _ambari_server_.configure_postgres()
     self.assertEqual(0, rcode)
-    os.unlink(ambari_server.PG_HBA_CONF_FILE_BACKUP)
+    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")
+  @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
-    retcode, out, err = ambari_server.restart_postgres()
+    retcode, out, err = _ambari_server_.restart_postgres()
     self.assertEqual(0, retcode)
 
     p.poll.return_value = None
     get_postgre_status_mock.return_value = "stopped", 0, "", ""
     run_os_command_mock.return_value = (1, None, None)
-    retcode, out, err = ambari_server.restart_postgres()
+    retcode, out, err = _ambari_server_.restart_postgres()
     self.assertEqual(1, retcode)
 
 
   @patch("shlex.split")
   @patch("subprocess.Popen")
-  @patch.object(ambari_server, "print_info_msg")
+  @patch.object(_ambari_server_, "print_info_msg")
   def test_run_os_command(self, printInfoMsg_mock, popenMock, splitMock):
 
     p = MagicMock()
@@ -605,151 +615,151 @@ class TestAmbariServer(TestCase):
 
     # with list arg
     cmd = ["exec", "arg"]
-    ambari_server.run_os_command(cmd)
+    _ambari_server_.run_os_command(cmd)
     self.assertFalse(splitMock.called)
 
     # with str arg
-    resp = ambari_server.run_os_command("runme")
+    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")
+  @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")
+    _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")
+  @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())
+    result = _ambari_server_.setup_db(MagicMock())
     self.assertTrue(configure_database_username_password_mock.called)
     self.assertEqual((0, None, None), result)
 
-  @patch.object(ambari_server, "configure_database_username_password")
+  @patch.object(_ambari_server_, "configure_database_username_password")
   @patch("time.sleep")
-  @patch.object(ambari_server, "run_os_command")
+  @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())
+    result = _ambari_server_.setup_db(MagicMock())
     self.assertTrue(run_os_command_mock.called)
     self.assertEqual((1, 'error', 'error') , result)
     self.assertEqual(2, sleep_mock.call_count)
     pass
 
-  @patch.object(ambari_server, "configure_database_username_password")
+  @patch.object(_ambari_server_, "configure_database_username_password")
   @patch("time.sleep")
-  @patch.object(ambari_server, "run_os_command")
+  @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())
+    result = _ambari_server_.setup_db(MagicMock())
     self.assertTrue(run_os_command_mock.called)
     self.assertEqual((0, None, None) , result)
     self.assertEqual(1, sleep_mock.call_count)
     pass
 
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "run_os_command")
+  @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,
+    run_os_command_mock.return_value = (0, _ambari_server_.SE_STATUS_DISABLED,
                                         None)
-    rcode = ambari_server.check_selinux()
+    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,
+                                           + _ambari_server_.SE_MODE_ENFORCING,
                                         None)
-    rcode = ambari_server.check_selinux()
+    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")
+  @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()
+    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()
+    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")
+  @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()
+    result = _ambari_server_.get_share_jars()
     self.assertEqual(expected, result)
     globMock.return_value = []
     expected = ""
-    result = ambari_server.get_share_jars()
+    result = _ambari_server_.get_share_jars()
     self.assertEqual(expected, result)
 
 
   @patch("glob.glob")
-  @patch.object(ambari_server, "print_info_msg")
+  @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)
+    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)
+    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")
+  @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()
+    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()
+    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)
+    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)
+    result = _ambari_server_.search_file("non_existent_file", path)
     self.assertEqual(None, result)
 
 
-  @patch.object(ambari_server, "search_file")
+  @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()
+      _ambari_server_.find_properties_file()
       self.fail("File not found'")
     except FatalException:
       # Expected
@@ -759,11 +769,11 @@ class TestAmbariServer(TestCase):
     # Testing case when file is found
     value = MagicMock()
     search_file_mock.return_value = value
-    result = ambari_server.find_properties_file()
+    result = _ambari_server_.find_properties_file()
     self.assertTrue(result is value)
 
 
-  @patch.object(ambari_server, "find_properties_file")
+  @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):
@@ -771,19 +781,19 @@ class TestAmbariServer(TestCase):
     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()
+    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()
+    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.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,
@@ -791,39 +801,39 @@ class TestAmbariServer(TestCase):
     # Testing boostrap dir wipe
     properties_mock = MagicMock()
     get_value_from_properties_mock.return_value = "dummy_bootstrap_dir"
-    ambari_server.adjust_directory_permissions("user")
+    _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
+    old_list = _ambari_server_.NR_ADJUST_OWNERSHIP_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")
+    _ambari_server_.adjust_directory_permissions("user")
     self.assertTrue(len(set_file_permissions_mock.call_args_list) ==
-                    len(ambari_server.NR_ADJUST_OWNERSHIP_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
+    _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")
+  @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",
+    _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)
@@ -834,7 +844,7 @@ class TestAmbariServer(TestCase):
     # 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",
+    _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)
@@ -844,7 +854,7 @@ class TestAmbariServer(TestCase):
 
     # Testing first command fail
     run_os_command_mock.side_effect = [(1, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
+    _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)
@@ -854,7 +864,7 @@ class TestAmbariServer(TestCase):
 
     # Testing second command fail
     run_os_command_mock.side_effect = [(0, "", ""), (1, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
+    _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)
@@ -866,7 +876,7 @@ class TestAmbariServer(TestCase):
 
     exists_mock.return_value = True
     run_os_command_mock.side_effect = [(0, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
+    _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])
@@ -880,7 +890,7 @@ class TestAmbariServer(TestCase):
 
     exists_mock.return_value = True
     run_os_command_mock.side_effect = [(0, "", ""), (0, "", "")]
-    ambari_server.set_file_permissions("dummy-file", "dummy-mod",
+    _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])
@@ -891,10 +901,10 @@ class TestAmbariServer(TestCase):
     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")
+  @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"
@@ -902,7 +912,7 @@ class TestAmbariServer(TestCase):
 
     # Testing scenario: absent user
     run_os_command_mock.side_effect = [(0, "", "")]
-    result = ambari_server.create_custom_user()
+    result = _ambari_server_.create_custom_user()
     self.assertFalse(print_warning_msg_mock.called)
     self.assertEquals(result, (0, user))
 
@@ -912,7 +922,7 @@ class TestAmbariServer(TestCase):
 
     # Testing scenario: existing user
     run_os_command_mock.side_effect = [(9, "", "")]
-    result = ambari_server.create_custom_user()
+    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))
 
@@ -922,17 +932,17 @@ class TestAmbariServer(TestCase):
 
     # Testing scenario: os command fail
     run_os_command_mock.side_effect = [(1, "", "")]
-    result = ambari_server.create_custom_user()
+    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")
+  @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):
@@ -940,7 +950,7 @@ class TestAmbariServer(TestCase):
     # 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()
+    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)
@@ -957,7 +967,7 @@ class TestAmbariServer(TestCase):
     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()
+    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")
@@ -976,7 +986,7 @@ class TestAmbariServer(TestCase):
     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()
+    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)
@@ -992,7 +1002,7 @@ class TestAmbariServer(TestCase):
     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()
+    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)
@@ -1010,7 +1020,7 @@ class TestAmbariServer(TestCase):
     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()
+    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)
@@ -1027,7 +1037,7 @@ class TestAmbariServer(TestCase):
     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()
+    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)
@@ -1042,7 +1052,7 @@ class TestAmbariServer(TestCase):
     # 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()
+    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)
@@ -1051,15 +1061,15 @@ class TestAmbariServer(TestCase):
     self.assertEqual(result, 0)
 
 
-  @patch.object(ambari_server, "search_file")
+  @patch.object(_ambari_server_, "search_file")
   @patch("__builtin__.open")
-  @patch.object(ambari_server, "read_ambari_user")
-  @patch.object(ambari_server, "set_file_permissions")
+  @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")
+    _ambari_server_.store_password_file("password", "passfile")
     self.assertTrue(set_file_permissions_mock.called)
 
   @patch("subprocess.Popen")
@@ -1129,14 +1139,14 @@ class TestAmbariServer(TestCase):
 
     out = StringIO.StringIO()
     sys.stdout = out
-    ambari_server.dlprogress("filename", 10, 2, 100)
+    _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")
+  @patch.object(_ambari_server_, "dlprogress")
   def test_track_jdk(self, dlprogress_mock, openMock, urlopenMock):
 
     u = MagicMock()
@@ -1152,7 +1162,7 @@ class TestAmbariServer(TestCase):
     f = MagicMock()
     openMock.return_value = f
 
-    ambari_server.track_jdk("base", "url", "local")
+    _ambari_server_.track_jdk("base", "url", "local")
 
     self.assertEqual(0, len(chunks))
     self.assertTrue(f.write.called)
@@ -1164,7 +1174,7 @@ class TestAmbariServer(TestCase):
   @patch("os.path.join")
   @patch("os.path.exists")
   @patch("os.path.isdir")
-  @patch.object(ambari_server, "get_ambari_properties")
+  @patch.object(_ambari_server_, "get_ambari_properties")
   def test_install_jce_manualy(self, get_ambari_properties_mock, \
                                os_path_isdir_mock, os_path_exists_mock, os_path_join_mock, \
                                shutil_copy_mock):
@@ -1178,7 +1188,7 @@ class TestAmbariServer(TestCase):
     # Case when JCE path doesn't exists
     os_path_exists_mock.return_value = False
     try:
-      ambari_server.install_jce_manualy(args)
+      _ambari_server_.install_jce_manualy(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -1190,7 +1200,7 @@ class TestAmbariServer(TestCase):
     os_path_exists_mock.return_value = True
     os_path_isdir_mock.return_value = True
     try:
-      ambari_server.install_jce_manualy(args)
+      _ambari_server_.install_jce_manualy(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -1201,12 +1211,12 @@ class TestAmbariServer(TestCase):
     os_path_isdir_mock.return_value = False
     os_path_join_mock.return_value = \
       "/var/lib/ambari-server/resources/jce_policy-6.zip"
-    ambari_server.install_jce_manualy(args)
+    _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)
+      _ambari_server_.install_jce_manualy(args)
       self.fail("Should throw exception because of not found jce_policy-6.zip")
     except Exception:
     # Expected
@@ -1215,20 +1225,20 @@ class TestAmbariServer(TestCase):
 
     shutil_copy_mock.side_effect = None
     args.jce_policy = None
-    ambari_server.install_jce_manualy(args)
+    _ambari_server_.install_jce_manualy(args)
 
-  @patch.object(ambari_server, "get_validated_filepath_input")
-  @patch.object(ambari_server, "run_os_command")
-  @patch.object(ambari_server, "get_truststore_type")
+  @patch.object(_ambari_server_, "get_validated_filepath_input")
+  @patch.object(_ambari_server_, "run_os_command")
+  @patch.object(_ambari_server_, "get_truststore_type")
   @patch("__builtin__.open")
-  @patch.object(ambari_server, "find_properties_file")
-  @patch.object(ambari_server, "run_component_https_cmd")
-  @patch.object(ambari_server, "get_delete_cert_command")
-  @patch.object(ambari_server, "get_truststore_password")
-  @patch.object(ambari_server, "get_truststore_path")
-  @patch.object(ambari_server, "get_YN_input")
-  @patch.object(ambari_server, "get_ambari_properties")
-  @patch.object(ambari_server, "find_jdk")
+  @patch.object(_ambari_server_, "find_properties_file")
+  @patch.object(_ambari_server_, "run_component_https_cmd")
+  @patch.object(_ambari_server_, "get_delete_cert_command")
+  @patch.object(_ambari_server_, "get_truststore_password")
+  @patch.object(_ambari_server_, "get_truststore_path")
+  @patch.object(_ambari_server_, "get_YN_input")
+  @patch.object(_ambari_server_, "get_ambari_properties")
+  @patch.object(_ambari_server_, "find_jdk")
   def test_setup_component_https(self, find_jdk_mock, get_ambari_properties_mock, get_YN_input_mock,
                                  get_truststore_path_mock, get_truststore_password_mock,
                                  get_delete_cert_command_mock, run_component_https_cmd_mock,
@@ -1242,18 +1252,18 @@ class TestAmbariServer(TestCase):
     property = "use_ssl"
     alias = "alias"
     #Silent mode
-    ambari_server.SILENT = True
-    ambari_server.setup_component_https(component, command, property, alias)
+    set_silent(True)
+    _ambari_server_.setup_component_https(component, command, property, alias)
     self.assertEqual('command is not enabled in silent mode.\n', out.getvalue())
     sys.stdout = sys.__stdout__
     #Verbouse mode and jdk_path is None
-    ambari_server.SILENT = False
+    set_silent(False)
     p = get_ambari_properties_mock.return_value
     # Use ssl
     p.get_property.side_effect = ["true"]
     # Dont disable ssl
     get_YN_input_mock.side_effect = [False]
-    ambari_server.setup_component_https(component, command, property, alias)
+    _ambari_server_.setup_component_https(component, command, property, alias)
     self.assertTrue(p.get_property.called)
     self.assertTrue(get_YN_input_mock.called)
     p.get_property.reset_mock()
@@ -1262,7 +1272,7 @@ class TestAmbariServer(TestCase):
     p.get_property.side_effect = ["false"]
     # Dont enable ssl
     get_YN_input_mock.side_effect = [False]
-    ambari_server.setup_component_https(component, command, property, alias)
+    _ambari_server_.setup_component_https(component, command, property, alias)
     self.assertTrue(p.get_property.called)
     self.assertTrue(get_YN_input_mock.called)
     p.get_property.reset_mock()
@@ -1270,7 +1280,7 @@ class TestAmbariServer(TestCase):
     # Cant find jdk
     find_jdk_mock.return_value = None
     try:
-        ambari_server.setup_component_https(component, command, property, alias)
+        _ambari_server_.setup_component_https(component, command, property, alias)
         self.fail("Should throw exception")
     except FatalException as fe:
         # Expected
@@ -1284,7 +1294,7 @@ class TestAmbariServer(TestCase):
     get_truststore_path_mock.return_value = "/truststore_path"
     get_truststore_password_mock.return_value = "/truststore_password"
     get_delete_cert_command_mock.return_value = "rm -f"
-    ambari_server.setup_component_https(component, command, property, alias)
+    _ambari_server_.setup_component_https(component, command, property, alias)
 
     self.assertTrue(p.process_pair.called)
     self.assertTrue(get_truststore_path_mock.called)
@@ -1305,7 +1315,7 @@ class TestAmbariServer(TestCase):
     #Verbouse mode and jdk_path is not None (use_https = false) and import cert
     p.get_property.side_effect = ["false"]
     get_YN_input_mock.side_effect = [True]
-    ambari_server.setup_component_https(component, command, property, alias)
+    _ambari_server_.setup_component_https(component, command, property, alias)
 
     self.assertTrue(p.process_pair.called)
     self.assertTrue(get_truststore_type_mock.called)
@@ -1330,19 +1340,19 @@ class TestAmbariServer(TestCase):
     run_os_command_mock.reset_mock()
     get_validated_filepath_input_mock.reset_mock()
 
-  @patch.object(ambari_server, 'adjust_directory_permissions')
-  @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.object(_ambari_server_, 'adjust_directory_permissions')
+  @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")
+  @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,
@@ -1360,7 +1370,7 @@ class TestAmbariServer(TestCase):
     # Testing call under non-root
     is_root_mock.return_value = False
     try:
-      ambari_server.setup_https(args)
+      _ambari_server_.setup_https(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -1379,8 +1389,8 @@ class TestAmbariServer(TestCase):
                             " 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)
+    set_silent(False)
+    _ambari_server_.setup_https(args)
 
     self.assertTrue(p.process_pair.called)
     self.assertTrue(p.get_property.call_count == 4)
@@ -1401,7 +1411,7 @@ class TestAmbariServer(TestCase):
     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)
+    _ambari_server_.setup_https(args)
 
     self.assertTrue(p.process_pair.called)
     self.assertTrue(p.get_property.call_count == 3)
@@ -1423,7 +1433,7 @@ class TestAmbariServer(TestCase):
     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)
+    _ambari_server_.setup_https(args)
 
     self.assertTrue(p.process_pair.called)
     self.assertTrue(p.get_property.call_count == 3)
@@ -1445,7 +1455,7 @@ class TestAmbariServer(TestCase):
     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)
+    _ambari_server_.setup_https(args)
 
     self.assertFalse(p.process_pair.called)
     self.assertTrue(p.get_property.call_count == 3)
@@ -1467,7 +1477,7 @@ class TestAmbariServer(TestCase):
     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')]"
-    self.assertFalse(ambari_server.setup_https(args))
+    self.assertFalse(_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)
@@ -1481,9 +1491,9 @@ class TestAmbariServer(TestCase):
     import_cert_and_key_action_mock.reset_mock()
 
     #Case #6: if silent mode is enabled
-    ambari_server.SILENT = True
+    set_silent(True)
     try:
-      ambari_server.setup_https(args)
+      _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)
@@ -1494,18 +1504,18 @@ class TestAmbariServer(TestCase):
     import_cert_and_key_action_mock.reset_mock()
 
     #Case #7: read property throw exception
-    ambari_server.SILENT = False
+    set_silent(False)
     find_properties_file_mock.return_value = "propertyFile"
     p.get_property.side_effect = KeyError("Failed to read property")
     try:
-        ambari_server.setup_https(args)
+        _ambari_server_.setup_https(args)
         self.fail("Should throw exception")
     except FatalException as fe:
         self.assertTrue("Failed to read property" in fe.reason)
 
 
 
-  @patch.object(ambari_server, "import_cert_and_key")
+  @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()
@@ -1514,24 +1524,24 @@ class TestAmbariServer(TestCase):
     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)
+    _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.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.object(_ambari_server_, "run_os_command")
   @patch("os.path.join")
   @patch("os.path.isfile")
   @patch('__builtin__.raw_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")
+  @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, \
@@ -1563,7 +1573,7 @@ class TestAmbariServer(TestCase):
                                      " call('key_file_path'," + \
                                      " 'keystore_cert_key_file_path')]"
 
-    ambari_server.import_cert_and_key("key_dir")
+    _ambari_server_.import_cert_and_key("key_dir")
     self.assertTrue(raw_input_mock.call_count == 2)
     self.assertTrue(get_validated_string_input_mock.called)
     self.assertEqual(os_path_join_mock.call_count, 8)
@@ -1571,19 +1581,19 @@ class TestAmbariServer(TestCase):
     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.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.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")
+  @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, \
@@ -1613,7 +1623,7 @@ class TestAmbariServer(TestCase):
                                      " call('key_file_path.secured'," + \
                                      " 'keystore_cert_key_file_path')]"
 
-    ambari_server.import_cert_and_key("key_dir")
+    _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)
@@ -1623,15 +1633,15 @@ class TestAmbariServer(TestCase):
     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.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")
+  @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, \
@@ -1654,110 +1664,110 @@ class TestAmbariServer(TestCase):
     #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"))
+    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)
+    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)
+    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)
+    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)
+    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")
+  @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)
+    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)
+    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)
+    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)
+    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")
+  @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)
+    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)
+    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)
+    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)
+    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")
+  @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()
+    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")
+    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'
+    p[_ambari_server_.GET_FQDN_SERVICE_URL] = 'someurl'
     get_ambari_properties_mock.return_value = p
 
     u = MagicMock()
@@ -1765,57 +1775,57 @@ class TestAmbariServer(TestCase):
     u.read.return_value = host
     url_open_mock.return_value = u
 
-    fqdn = ambari_server.get_fqdn()
+    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()
+    fqdn = _ambari_server_.get_fqdn()
     self.assertEqual(fqdn, host)
 
 
-  @patch.object(ambari_server, "find_properties_file")
+  @patch.object(_ambari_server_, "find_properties_file")
   def test_get_ulimit_open_files(self, find_properties_file_mock):
 
     # 1 - No ambari.properties
     find_properties_file_mock.return_value = None
-    open_files = ambari_server.get_fqdn()
+    open_files = _ambari_server_.get_fqdn()
     self.assertEqual(open_files, None)
 
     # 2 - With ambari.properties - ok
     tf1 = tempfile.NamedTemporaryFile()
     prop_value = 65000
     with open(tf1.name, 'w') as fout:
-      fout.write(ambari_server.ULIMIT_OPEN_FILES_KEY + '=' + str(prop_value))
+      fout.write(_ambari_server_.ULIMIT_OPEN_FILES_KEY + '=' + str(prop_value))
     fout.close()
     find_properties_file_mock.return_value = tf1.name
-    open_files = ambari_server.get_ulimit_open_files()
+    open_files = _ambari_server_.get_ulimit_open_files()
     self.assertEqual(open_files, 65000)
 
     # 2 - With ambari.properties - default
     tf1 = tempfile.NamedTemporaryFile()
     prop_value = 0
     with open(tf1.name, 'w') as fout:
-      fout.write(ambari_server.ULIMIT_OPEN_FILES_KEY + '=' + str(prop_value))
+      fout.write(_ambari_server_.ULIMIT_OPEN_FILES_KEY + '=' + str(prop_value))
     fout.close()
     find_properties_file_mock.return_value = tf1.name
-    open_files = ambari_server.get_ulimit_open_files()
-    self.assertEqual(open_files, ambari_server.ULIMIT_OPEN_FILES_DEFAULT)
+    open_files = _ambari_server_.get_ulimit_open_files()
+    self.assertEqual(open_files, _ambari_server_.ULIMIT_OPEN_FILES_DEFAULT)
 
 
-  @patch.object(ambari_server, "run_os_command")
+  @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)
+    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)
+    cert_info = _ambari_server_.get_cert_info(path)
     self.assertEqual(cert_info, None)
 
     #Positive scenario
@@ -1843,7 +1853,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     """
     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)
+    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)
@@ -1862,19 +1872,19 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     inputed_value1 = 'val1'
     inputed_value2 = 'val2'
     raw_input_mock.return_value = inputed_value1
-    input = ambari_server.get_validated_string_input(prompt, default_value, None,
+    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,
+    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.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, \
@@ -1883,15 +1893,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     f = open_mock.return_value
     f.readline.return_value = "111"
     run_os_command_mock.return_value = 0, "", ""
-    status, pid = ambari_server.is_server_runing()
+    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()
+    status, pid = _ambari_server_.is_server_runing()
     self.assertFalse(status)
 
 
-  @patch.object(ambari_server, "run_os_command")
+  @patch.object(_ambari_server_, "run_os_command")
   @patch("__builtin__.open")
   @patch("os.path.exists")
   def test_is_server_runing_bad_file(self, os_path_exists_mock, open_mock, \
@@ -1900,19 +1910,19 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     f = open_mock.return_value
     f.readline.return_value = "" # empty file content
     run_os_command_mock.return_value = 0, "", ""
-    self.assertRaises(NonFatalException, ambari_server.is_server_runing)
+    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)
+    self.assertRaises(FatalException, _ambari_server_.is_server_runing)
 
 
   @patch("os.chdir")
-  @patch.object(ambari_server, "run_os_command")
+  @patch.object(_ambari_server_, "run_os_command")
   def test_install_jdk(self, run_os_command_mock, os_chdir_mock):
     run_os_command_mock.return_value = 1, "", ""
     failed = False
     try:
-      ambari_server.install_jdk(MagicMock())
+      _ambari_server_.install_jdk(MagicMock())
       self.fail("Exception was not rised!")
     except FatalException:
       failed = True
@@ -1922,15 +1932,15 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @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, "remove_property")
-  @patch.object(ambari_server, "get_validated_string_input")
-  @patch.object(ambari_server, "print_info_msg")
-  @patch.object(ambari_server, "get_JAVA_HOME")
-  @patch.object(ambari_server, "get_ambari_properties")
+  @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_, "remove_property")
+  @patch.object(_ambari_server_, "get_validated_string_input")
+  @patch.object(_ambari_server_, "print_info_msg")
+  @patch.object(_ambari_server_, "get_JAVA_HOME")
+  @patch.object(_ambari_server_, "get_ambari_properties")
   @patch("shutil.copyfile")
   @patch("sys.exit")
   def test_download_jdk(self, exit_mock, copyfile_mock, get_ambari_properties_mock, get_JAVA_HOME_mock, \
@@ -1944,7 +1954,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_ambari_properties_mock.return_value = -1
     # Test case: ambari.properties not found
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception because of not found ambari.properties")
     except FatalException:
       # Expected
@@ -1959,13 +1969,13 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_JAVA_HOME_mock.return_value = True
     get_YN_input_mock.return_value = False
     path_existsMock.side_effect = [False,False]
-    rcode = ambari_server.download_jdk(args)
+    rcode = _ambari_server_.download_jdk(args)
     self.assertEqual(0, rcode)
     # Test case: java home setup
     args.java_home = "somewhere"
     path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = False
-    rcode = ambari_server.download_jdk(args)
+    rcode = _ambari_server_.download_jdk(args)
     self.assertEqual(0, rcode)
     self.assertTrue(write_property_mock.called)
     self.assertTrue(remove_property_mock.call_count == 2)
@@ -1976,7 +1986,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_ambari_properties_mock.return_value = p
     p.__getitem__.side_effect = KeyError("test exception")
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException:
       # Expected
@@ -1990,7 +2000,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_validated_string_input_mock.return_value = "1"
     run_os_command_mock.return_value = (0, "Wrong out", None)
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException:
       # Expected
@@ -1999,21 +2009,21 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     args.java_home = None
     path_isfileMock.return_value = False
     args.jdk_location = None
-    ambari_server.JDK_INSTALL_DIR = os.getcwd()
+    _ambari_server_.JDK_INSTALL_DIR = os.getcwd()
     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)
+    rcode = _ambari_server_.download_jdk(args)
     self.assertEqual(0, rcode)
 
     # Test case: not accept the license"
     p.__getitem__.return_value = "somewhere"
     p.__getitem__.side_effect = None
     get_YN_input_mock.return_value = False
-    ambari_server.download_jdk(args)
+    _ambari_server_.download_jdk(args)
     self.assertTrue(exit_mock.called)
 
     # Test case: jdk is already installed, ensure that JCE check is skipped if -j option is not supplied.
@@ -2024,8 +2034,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_JAVA_HOME_mock.return_value = True
     get_YN_input_mock.return_value = False
     path_existsMock.return_value = False
-    with patch.object(ambari_server, "download_jce_policy") as download_jce_policy_mock:
-      rcode = ambari_server.download_jdk(args)
+    with patch.object(_ambari_server_, "download_jce_policy") as download_jce_policy_mock:
+      rcode = _ambari_server_.download_jdk(args)
       self.assertFalse(download_jce_policy_mock.called)
 
     # Test case: Update JAVA_HOME location using command: ambari-server setup -j %NEW_LOCATION%
@@ -2035,7 +2045,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = True
     path_isfileMock.return_value = True
-    ambari_server.download_jdk(args)
+    _ambari_server_.download_jdk(args)
     self.assertTrue(write_property_mock.call_count == 1)
     self.assertTrue(remove_property_mock.call_count == 2)
 
@@ -2047,7 +2057,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     #path_existsMock.return_value = True
     #get_JAVA_HOME_mock.return_value = True
     #try:
-    #  ambari_server.download_jdk(args)
+    #  _ambari_server_.download_jdk(args)
     #  self.fail("Should throw exception")
     #except FatalException as fe:
       # Expected
@@ -2061,7 +2071,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     path_existsMock.return_value = True
     get_validated_string_input_mock.return_value = "3"
     get_JAVA_HOME_mock.return_value = False
-    rcode = ambari_server.download_jdk(args)
+    rcode = _ambari_server_.download_jdk(args)
     self.assertEqual(0, rcode)
     self.assertTrue(write_property_mock.called)
     self.assertTrue(remove_property_mock.call_count == 2)
@@ -2072,7 +2082,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_validated_string_input_mock.return_value = "3"
     get_JAVA_HOME_mock.return_value = False
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -2087,7 +2097,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_JAVA_HOME_mock.return_value = False
     flag = False
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       # Expected
@@ -2098,29 +2108,29 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     args.java_home = "somewhere"
     path_existsMock.return_value = False
     try:
-      ambari_server.download_jdk(args)
+      _ambari_server_.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException as fe:
       self.assertTrue("Path to java home somewhere or java binary file does not exists" in fe.reason)
       pass
 
 
-  @patch.object(ambari_server, "run_os_command")
+  @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)
-    pg_status, retcode, out, err = ambari_server.get_postgre_status()
+    pg_status, retcode, out, err = _ambari_server_.get_postgre_status()
     self.assertEqual("running", pg_status)
 
     run_os_command_mock.return_value = (1, "wrong", None)
-    pg_status, retcode, out, err = ambari_server.get_postgre

<TRUNCATED>

[3/3] ambari git commit: AMBARI-8317 Refactor the OS-dependent Ambari Server Windows components

Posted by fb...@apache.org.
AMBARI-8317 Refactor the OS-dependent Ambari Server Windows components

+Fixed ambari_server import in TestAmbariServer.py, to allow future imports from modules in the ambari_server subdir
+Moved SILENT, VERBOSE and DEBUG_MODE to logging_utils.py, to allow future use from modular code
+Moved run_os_command to os_utils
+Extended the set of test platform primitives
+Optimized imports


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

Branch: refs/heads/trunk
Commit: 16bee3858711178dd4025b56211f03b11fa75954
Parents: fb947b0
Author: Florian Barca <fb...@hortonworks.com>
Authored: Tue Jan 13 13:46:04 2015 -0800
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Tue Jan 13 13:46:04 2015 -0800

----------------------------------------------------------------------
 .../test/python/ambari_agent/TestHostInfo.py    |   40 +-
 .../python/ambari_agent/TestRegistration.py     |    6 +-
 .../src/main/python/ambari_commons/firewall.py  |   21 +-
 .../main/python/ambari_commons/logging_utils.py |   32 +-
 .../src/main/python/ambari_commons/os_linux.py  |   14 +-
 .../src/main/python/ambari_commons/os_utils.py  |   21 +-
 .../main/python/ambari_commons/os_windows.py    |  168 +-
 .../core/providers/windows/system.py            |    4 +-
 .../functions/get_unique_id_and_date.py         |    2 +-
 .../src/test/python/only_for_platform.py        |   12 +
 ambari-server/conf/windows/ambari.properties    |    1 +
 .../src/main/python/ambari-server-windows.py    |   22 +-
 ambari-server/src/main/python/ambari-server.py  |   57 +-
 .../ambari_server/dbConfiguration_linux.py      |    8 +-
 .../python/ambari_server/serverConfiguration.py |    8 +
 .../main/python/ambari_server/serverSetup.py    |    5 +-
 .../python/ambari_server/serverSetup_linux.py   |    5 +-
 .../python/ambari_server/serverSetup_windows.py |    2 +-
 .../main/python/ambari_server/setupSecurity.py  |    6 +-
 .../src/main/python/ambari_server/userInput.py  |   12 +-
 .../custom_actions/scripts/install_packages.py  |    8 +-
 .../src/test/python/TestAmbariServer.py         | 2614 +++++++++---------
 .../test/python/custom_actions/TestCheckHost.py |   18 +-
 23 files changed, 1574 insertions(+), 1512 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
index 338d080..adeb798 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
@@ -31,7 +31,7 @@ from mock.mock import create_autospec
 import ambari_commons
 from ambari_commons import OSCheck
 import os
-from only_for_platform import only_for_platform, get_platform, PLATFORM_WINDOWS, PLATFORM_LINUX
+from only_for_platform import not_for_platform, get_platform, PLATFORM_WINDOWS, PLATFORM_LINUX
 
 if get_platform() != PLATFORM_WINDOWS:
   os_distro_value = ('Suse','11','Final')
@@ -51,7 +51,7 @@ with patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_
 @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
 class TestHostInfo(TestCase):
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, 'get_os_family')
   @patch('resource_management.libraries.functions.packages_analyzer.subprocessWithTimeout')
   def test_analyze_zypper_out(self, spwt_mock, get_os_family_mock):
@@ -82,7 +82,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(installedPackages[3][2], "HDP")
     self.assertTrue(installedPackages[6][1], "11-38.13.9")
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   def test_getReposToRemove(self):
     l1 = ["Hortonworks Data Platform Utils Version - HDP-UTILS-1.1.0.15", "Ambari 1.x", "HDP"]
     l2 = ["Ambari", "HDP-UTIL"]
@@ -96,7 +96,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(1, len(l3))
     self.assertEqual(l3[0], "HDP-1.3.0")
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   def test_perform_package_analysis(self):
     installedPackages = [
       ["hadoop-a", "2.3", "HDP"], ["zk", "3.1", "HDP"], ["webhcat", "3.1", "HDP"],
@@ -143,7 +143,7 @@ class TestHostInfo(TestCase):
     for package in expected:
       self.assertTrue(package in allPackages)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, 'get_os_family')
   @patch('resource_management.libraries.functions.packages_analyzer.subprocessWithTimeout')
   def test_analyze_yum_output(self, subprocessWithTimeout_mock, get_os_family_mock):
@@ -199,7 +199,7 @@ class TestHostInfo(TestCase):
                                               "koji-override-0/$releasever"])
       self.assertFalse(package['repoName'] in ["AMBARI.dev-1.x"])
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, 'get_os_family')
   @patch('resource_management.libraries.functions.packages_analyzer.subprocessWithTimeout')
   def test_analyze_yum_output_err(self, subprocessWithTimeout_mock, get_os_family_mock):
@@ -230,7 +230,7 @@ class TestHostInfo(TestCase):
 
       self.assertTrue(item in names)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch('os.path.exists')
   @patch('__builtin__.open')
@@ -253,7 +253,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(newlist[1]['status'], "Invalid home directory")
     print(path_mock.mock_calls)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "get_os_type")
   @patch('os.umask')
   @patch.object(HostCheckReportFileHandler, 'writeHostCheckFile')
@@ -296,7 +296,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(0 < len(dict['installedPackages']))
     self.assertTrue('agentTimeStampAtReporting' in dict['hostHealth'])
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "get_os_type")
   @patch('os.umask')
   @patch.object(HostCheckReportFileHandler, 'writeHostCheckFile')
@@ -399,7 +399,7 @@ class TestHostInfo(TestCase):
     result = host.dirType("/home")
     self.assertEquals(result, 'unknown')
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch("os.path.exists")
   @patch("glob.glob")
   def test_hadoopVarRunCount(self, glob_glob_mock, os_path_exists_mock):
@@ -414,7 +414,7 @@ class TestHostInfo(TestCase):
     result = hostInfo.hadoopVarRunCount()
     self.assertEquals(result, 0)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch("os.path.exists")
   @patch("glob.glob")
   def test_hadoopVarLogCount(self, glob_glob_mock, os_path_exists_mock):
@@ -429,7 +429,7 @@ class TestHostInfo(TestCase):
     result = hostInfo.hadoopVarLogCount()
     self.assertEquals(result, 0)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = ('redhat','11','Final')))
   @patch("os.listdir", create=True, autospec=True)
   @patch("__builtin__.open", create=True, autospec=True)
@@ -451,7 +451,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(list[0]['hadoop'])
     self.assertEquals(list[0]['user'], 'user')
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch("subprocess.Popen")
   @patch.object(Hardware, 'extractMountInfo')
   def test_osdiskAvailableSpace(self, extract_mount_info_mock, subproc_popen_mock):
@@ -469,7 +469,7 @@ class TestHostInfo(TestCase):
 
     self.assertEquals(result, {})
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "get_os_type")
   @patch("subprocess.Popen")
   def test_checkLiveServices(self, subproc_popen, get_os_type_method):
@@ -513,7 +513,7 @@ class TestHostInfo(TestCase):
     self.assertEquals(result[0]['name'], 'service1')
     self.assertTrue(len(result[0]['desc']) > 0)
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = ('redhat','11','Final')))
   @patch("os.path.exists")
   @patch("os.listdir", create=True, autospec=True)
@@ -536,11 +536,11 @@ class TestHostInfo(TestCase):
     self.assertEquals(result[0]['name'], 'config1')
     self.assertEquals(result[0]['target'], 'real_path_to_conf')
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "get_os_family")
   @patch.object(OSCheck, "get_os_type")
   @patch.object(OSCheck, "get_os_major_version")
-  @patch.object(FirewallChecks, "run_os_command")
+  @patch("ambari_commons.firewall.run_os_command")
   def test_IpTablesRunning(self, run_os_command_mock, get_os_major_version_mock, get_os_type_mock, get_os_family_mock):
     get_os_type_mock.return_value = ""
     get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
@@ -572,18 +572,18 @@ class TestHostInfo(TestCase):
 
     self.assertFalse(hostInfo.checkReverseLookup())
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "get_os_family")
   @patch.object(OSCheck, "get_os_type")
   @patch.object(OSCheck, "get_os_major_version")
-  @patch.object(FirewallChecks, "run_os_command")
+  @patch("ambari_commons.firewall.run_os_command")
   def test_IpTablesStopped(self, run_os_command_mock, get_os_major_version_mock, get_os_type_mock, get_os_family_mock):
     get_os_type_mock.return_value = ""
     get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
     run_os_command_mock.return_value = 3, "", ""
     self.assertFalse(Firewall().getFirewallObject().check_iptables())
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = ('redhat','11','Final')))
   @patch("os.path.isfile")
   @patch('__builtin__.open')

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
index 41f9880..92e4b36 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
@@ -23,7 +23,7 @@ import os
 import tempfile
 from mock.mock import patch
 from mock.mock import MagicMock
-from only_for_platform import only_for_platform, PLATFORM_LINUX
+from only_for_platform import not_for_platform, PLATFORM_WINDOWS
 
 with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
   from ambari_agent.Register import Register
@@ -33,9 +33,9 @@ with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
 
 class TestRegistration(TestCase):
 
-  @only_for_platform(PLATFORM_LINUX)
+  @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(Hardware, "_chk_mount", new = MagicMock(return_value=True))
-  @patch.object(FirewallChecks, "run_os_command")
+  @patch("ambari_commons.firewall.run_os_command")
   @patch.object(OSCheck, "get_os_type")
   @patch.object(OSCheck, "get_os_version")
   def test_registration_build(self, get_os_version_mock, get_os_type_mock, run_os_cmd_mock):

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/ambari_commons/firewall.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/firewall.py b/ambari-common/src/main/python/ambari_commons/firewall.py
index b73cc0c..76d9890 100644
--- a/ambari-common/src/main/python/ambari_commons/firewall.py
+++ b/ambari-common/src/main/python/ambari_commons/firewall.py
@@ -18,10 +18,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
-import subprocess
-import shlex
 from ambari_commons import OSCheck, OSConst
-
+from ambari_commons.os_utils import run_os_command
 
 class Firewall(object):
   def __init__(self):
@@ -64,24 +62,11 @@ class FirewallChecks(object):
 
   def check_iptables(self):
     try:
-      retcode, out, err = self.run_os_command(self.get_command())
-      return self.check_result(retcode, out, err)
+      self.returncode, self.stdoutdata, self.stderrdata = run_os_command(self.get_command())
+      return self.check_result(self.returncode, self.stdoutdata, self.stderrdata)
     except OSError:
       return False
 
-  def run_os_command(self, cmd):
-    if type(cmd) == str:
-      cmd = shlex.split(cmd)
-
-    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-                               stderr=subprocess.PIPE)
-    (stdoutdata, stderrdata) = process.communicate()
-    self.returncode = process.returncode
-    self.stdoutdata = stdoutdata
-    self.stderrdata = stderrdata
-    return self.returncode, self.stdoutdata, self.stderrdata
-
-
 
 class UbuntuFirewallChecks(FirewallChecks):
   def __init__(self):

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/ambari_commons/logging_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/logging_utils.py b/ambari-common/src/main/python/ambari_commons/logging_utils.py
index 9d45fdb..af1390c 100644
--- a/ambari-common/src/main/python/ambari_commons/logging_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/logging_utils.py
@@ -18,19 +18,43 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
-VERBOSE = False
-SILENT = False
-DEBUG_MODE = False
+_VERBOSE = False
+_SILENT = False
+_DEBUG_MODE = False
 
 # terminal styles
 BOLD_ON = '\033[1m'
 BOLD_OFF = '\033[0m'
 
+def get_verbose():
+  global _VERBOSE
+  return _VERBOSE
+
+def set_verbose(newVal):
+  global _VERBOSE
+  _VERBOSE = newVal
+
+def get_silent():
+  global _SILENT
+  return _SILENT
+
+def set_silent(newVal):
+  global _SILENT
+  _SILENT = newVal
+
+def get_debug_mode():
+  global _DEBUG_MODE
+  return _DEBUG_MODE
+
+def set_debug_mode(newVal):
+  global _DEBUG_MODE
+  _DEBUG_MODE = newVal
+
 #
 # Prints an "info" messsage.
 #
 def print_info_msg(msg):
-  if VERBOSE:
+  if _VERBOSE:
     print("INFO: " + msg)
 
 #

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/ambari_commons/os_linux.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_linux.py b/ambari-common/src/main/python/ambari_commons/os_linux.py
index 38f3fb9..8599a0d 100644
--- a/ambari-common/src/main/python/ambari_commons/os_linux.py
+++ b/ambari-common/src/main/python/ambari_commons/os_linux.py
@@ -24,7 +24,7 @@ import pwd
 import shlex
 import subprocess
 
-from logging_utils import *
+from ambari_commons.logging_utils import print_info_msg, print_warning_msg
 
 
 NR_CHMOD_CMD = 'chmod {0} {1} {2}'
@@ -33,14 +33,16 @@ NR_CHOWN_CMD = 'chown {0} {1} {2}'
 ULIMIT_CMD = "ulimit -n"
 
 
-def run_os_command(cmd):
+def os_run_os_command(cmd, env=None, shell=False):
   print_info_msg('about to run command: ' + str(cmd))
   if type(cmd) == str:
     cmd = shlex.split(cmd)
   process = subprocess.Popen(cmd,
                              stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE,
-                             stderr=subprocess.PIPE
+                             stderr=subprocess.PIPE,
+                             env=env,
+                             shell=shell
                              )
   (stdoutdata, stderrdata) = process.communicate()
   return process.returncode, stdoutdata, stderrdata
@@ -64,17 +66,17 @@ def os_set_file_permissions(file, mod, recursive, user):
   else:
     params = ""
   command = NR_CHMOD_CMD.format(params, mod, file)
-  retcode, out, err = run_os_command(command)
+  retcode, out, err = os_run_os_command(command)
   if retcode != 0:
     print_warning_msg(WARN_MSG.format(command, file, err))
   command = NR_CHOWN_CMD.format(params, user, file)
-  retcode, out, err = run_os_command(command)
+  retcode, out, err = os_run_os_command(command)
   if retcode != 0:
     print_warning_msg(WARN_MSG.format(command, file, err))
 
 def os_set_open_files_limit(maxOpenFiles):
   command = "%s %s" % (ULIMIT_CMD, str(maxOpenFiles))
-  run_os_command(command)
+  os_run_os_command(command)
 
 
 def os_getpass(prompt):

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/ambari_commons/os_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_utils.py b/ambari-common/src/main/python/ambari_commons/os_utils.py
index 942a920..c6a3832 100644
--- a/ambari-common/src/main/python/ambari_commons/os_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/os_utils.py
@@ -18,20 +18,23 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
+import os
 import shutil
 import string
-import os
 
-from os_check import *
+from ambari_commons import OSCheck
 
 if OSCheck.is_windows_family():
-  from os_windows import *
+  from ambari_commons.os_windows import os_change_owner, os_getpass, os_is_root, os_run_os_command, \
+    os_set_open_files_limit, os_set_file_permissions
 else:
   # MacOS not supported
-  from os_linux import *
+  from ambari_commons.os_linux import os_change_owner, os_getpass, os_is_root, os_run_os_command, \
+    os_set_open_files_limit, os_set_file_permissions
+  pass
 
-from logging_utils import *
-from exceptions import FatalException
+from ambari_commons.exceptions import FatalException
+from ambari_commons.logging_utils import print_info_msg, print_warning_msg
 
 
 def is_valid_filepath(filepath):
@@ -91,6 +94,12 @@ def set_file_permissions(file, mod, user, recursive):
   else:
     print_info_msg("File %s does not exist" % file)
 
+def run_os_command(cmd, env=None):
+  return os_run_os_command(cmd, env, False)
+
+def run_in_shell(cmd, env=None):
+  return os_run_os_command(cmd, env, True)
+
 def is_root():
   return os_is_root()
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/ambari_commons/os_windows.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_windows.py b/ambari-common/src/main/python/ambari_commons/os_windows.py
index 7918a2f..e413b8e 100644
--- a/ambari-common/src/main/python/ambari_commons/os_windows.py
+++ b/ambari-common/src/main/python/ambari_commons/os_windows.py
@@ -17,41 +17,35 @@ 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
 import getpass
+import os
+import random
 import shlex
 import subprocess
 import sys
+import tempfile
 import time
-import win32api
-import win32event
-import win32service
-import win32con
-import win32serviceutil
-import wmi
-import random
 import string
 
 import ctypes
 
-from win32security import *
-from win32api import *
-from winerror import ERROR_INVALID_HANDLE
-from win32process import GetExitCodeProcess, STARTF_USESTDHANDLES, STARTUPINFO, CreateProcessAsUser
-from win32event import WaitForSingleObject, INFINITE
 import msvcrt
-import tempfile
-from win32event import *
-from win32api import CloseHandle
-
-from ambari_commons.exceptions import *
-from logging_utils import *
 
-from win32security import LsaOpenPolicy, POLICY_CREATE_ACCOUNT, POLICY_LOOKUP_NAMES, LookupAccountName, \
-  LsaAddAccountRights, LsaRemoveAccountRights, SE_SERVICE_LOGON_NAME
-from win32net import NetUserAdd
-from win32netcon import USER_PRIV_USER, UF_NORMAL_ACCOUNT, UF_SCRIPT
 import pywintypes
+import winerror
+import win32api
+import win32con
+import win32event
+import win32net
+import win32netcon
+import win32process
+import win32security
+import win32service
+import win32serviceutil
+import wmi
+
+from ambari_commons.exceptions import FatalException
+from ambari_commons.logging_utils import print_info_msg, print_warning_msg
 
 SERVICE_STATUS_UNKNOWN = "unknown"
 SERVICE_STATUS_STARTING = "starting"
@@ -63,6 +57,27 @@ SERVICE_STATUS_NOT_INSTALLED = "not installed"
 WHOAMI_GROUPS = "whoami /groups"
 ADMIN_ACCOUNT = "BUILTIN\\Administrators"
 
+#
+# os.symlink is not implemented in Windows. Patch it.
+#
+__CSL = None
+def symlink(source, link_name):
+  '''symlink(source, link_name)
+     Creates a symbolic link pointing to source named link_name'''
+  global __CSL
+  if __CSL is None:
+    csl = ctypes.windll.kernel32.CreateSymbolicLinkW
+    csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
+    csl.restype = ctypes.c_ubyte
+    __CSL = csl
+  flags = 0
+  if source is not None and os.path.isdir(source):
+    flags = 1
+  if __CSL(link_name, source, flags) == 0:
+    raise ctypes.WinError()
+
+os.symlink = symlink
+
 class OSVERSIONINFOEXW(ctypes.Structure):
     _fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
                 ('dwMajorVersion', ctypes.c_ulong),
@@ -77,17 +92,17 @@ class OSVERSIONINFOEXW(ctypes.Structure):
                 ('wReserved', ctypes.c_byte)]
 
 def get_windows_version():
-    """
-    Get's the OS major and minor versions.  Returns a tuple of
-    (OS_MAJOR, OS_MINOR).
-    """
-    os_version = OSVERSIONINFOEXW()
-    os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
-    retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
-    if retcode != 0:
-        raise Exception("Failed to get OS version")
-
-    return os_version.dwMajorVersion, os_version.dwMinorVersion, os_version.dwBuildNumber
+  """
+  Gets the OS major and minor versions.  Returns a tuple of
+  (OS_MAJOR, OS_MINOR).
+  """
+  os_version = OSVERSIONINFOEXW()
+  os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
+  retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
+  if retcode != 0:
+    raise Exception("Failed to get OS version")
+
+  return os_version.dwMajorVersion, os_version.dwMinorVersion, os_version.dwBuildNumber
 
 CHECK_FIREWALL_SCRIPT = """[string]$CName = $env:computername
 $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$computer)
@@ -116,25 +131,25 @@ def _get_files_output(out, err):
 
 def _safe_duplicate_handle(h):
   try:
-    h = DuplicateHandle(GetCurrentProcess(),
-                        h,
-                        GetCurrentProcess(),
-                        0,
-                        True,
-                        win32con.DUPLICATE_SAME_ACCESS)
+    h = win32api.DuplicateHandle(win32process.GetCurrentProcess(),
+                                 h,
+                                 win32process.GetCurrentProcess(),
+                                 0,
+                                 True,
+                                 win32con.DUPLICATE_SAME_ACCESS)
     return True, h
   except Exception as exc:
-    if exc.winerror == ERROR_INVALID_HANDLE:
+    if exc.winerror == winerror.ERROR_INVALID_HANDLE:
       return True, None
   return False, None
 
 
 def run_os_command_impersonated(cmd, user, password, domain='.'):
-  si = STARTUPINFO()
+  si = win32process.STARTUPINFO()
 
   out_handle, err_handle, out_file, err_file = _create_tmp_files()
 
-  ok, si.hStdInput = _safe_duplicate_handle(GetStdHandle(STD_INPUT_HANDLE))
+  ok, si.hStdInput = _safe_duplicate_handle(win32api.GetStdHandle(win32api.STD_INPUT_HANDLE))
 
   if not ok:
     raise Exception("Unable to create StdInput for child process")
@@ -145,27 +160,29 @@ def run_os_command_impersonated(cmd, user, password, domain='.'):
   if not ok:
     raise Exception("Unable to create StdErr for child process")
 
-  si.dwFlags = STARTF_USESTDHANDLES
+  si.dwFlags = win32process.STARTF_USESTDHANDLES
   si.lpDesktop = ""
 
-  user_token = LogonUser(user, domain, password, win32con.LOGON32_LOGON_SERVICE, win32con.LOGON32_PROVIDER_DEFAULT)
-  primary_token = DuplicateTokenEx(user_token, SecurityImpersonation, 0, TokenPrimary)
-  info = CreateProcessAsUser(primary_token, None, cmd, None, None, 1, 0, None, None, si)
+  user_token = win32security.LogonUser(user, domain, password,
+                                       win32con.LOGON32_LOGON_SERVICE, win32con.LOGON32_PROVIDER_DEFAULT)
+  primary_token = win32security.DuplicateTokenEx(user_token,
+                                                 win32security.SecurityImpersonation, 0, win32security.TokenPrimary)
+  info = win32process.CreateProcessAsUser(primary_token, None, cmd, None, None, 1, 0, None, None, si)
 
   hProcess, hThread, dwProcessId, dwThreadId = info
   hThread.Close()
 
   try:
-    WaitForSingleObject(hProcess, INFINITE)
+    win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
   except KeyboardInterrupt:
     pass
 
   out, err = _get_files_output(out_file, err_file)
-  exitcode = GetExitCodeProcess(hProcess)
+  exitcode = win32process.GetExitCodeProcess(hProcess)
 
   return exitcode, out, err
 
-def run_os_command(cmd, env=None):
+def os_run_os_command(cmd, env=None, shell=False):
   if isinstance(cmd,basestring):
     cmd = cmd.replace("\\", "\\\\")
     cmd = shlex.split(cmd)
@@ -173,7 +190,8 @@ def run_os_command(cmd, env=None):
                              stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE,
                              stderr=subprocess.PIPE,
-                             env=env
+                             env=env,
+                             shell=shell
   )
   (stdoutdata, stderrdata) = process.communicate()
   return process.returncode, stdoutdata, stderrdata
@@ -186,13 +204,13 @@ def run_powershell_script(script_content):
   script_file = open(os.path.join(tmp_dir,random_filename+".ps1"),"w")
   script_file.write(script_content)
   script_file.close()
-  result = run_os_command("powershell  -ExecutionPolicy unrestricted -File {0}".format(script_file.name))
+  result = os_run_os_command("powershell  -ExecutionPolicy unrestricted -File {0}".format(script_file.name))
   os.remove(script_file.name)
   return result
 
 def os_change_owner(filePath, user):
   cmd = ['icacls', filePath, '/setowner', user]
-  retcode, outdata, errdata = run_os_command(cmd)
+  retcode, outdata, errdata = os_run_os_command(cmd)
   return retcode
 
 def os_is_root():
@@ -200,9 +218,10 @@ def os_is_root():
   Checks whether the current user is a member of the Administrators group
   Returns True if yes, otherwise False
   '''
-  retcode, out, err = run_os_command(WHOAMI_GROUPS)
+  retcode, out, err = os_run_os_command(WHOAMI_GROUPS)
   if retcode != 0:
-    err_msg = "Unable to check the current user's group memberships. Command {0} returned exit code {1} with message: {2}".format(WHOAMI_GROUPS, retcode, err)
+    err_msg = "Unable to check the current user's group memberships. " \
+              "Command {0} returned exit code {1} with message: {2}".format(WHOAMI_GROUPS, retcode, err)
     print_warning_msg(err_msg)
     raise FatalException(retcode, err_msg)
 
@@ -221,20 +240,20 @@ def os_set_file_permissions(file, mod, recursive, user):
   #else:
   #  params = ""
   #command = NR_CHMOD_CMD.format(params, mod, file)
-  #retcode, out, err = run_os_command(command)
+  #retcode, out, err = os_run_os_command(command)
   #if retcode != 0:
   #  print_warning_msg(WARN_MSG.format(command, file, err))
   #command = NR_CHOWN_CMD.format(params, user, file)
-  #retcode, out, err = run_os_command(command)
+  #retcode, out, err = os_run_os_command(command)
   #if retcode != 0:
   #  print_warning_msg(WARN_MSG.format(command, file, err))
 
   # rights = mod
   # acls_remove_cmd = "icacls {0} /remove {1}".format(file, user)
-  # retcode, out, err = run_os_command(acls_remove_cmd)
+  # retcode, out, err = os_run_os_command(acls_remove_cmd)
   # if retcode == 0:
   #   acls_modify_cmd = "icacls {0} /grant {1}:{2}".format(file, user, rights)
-  #   retcode, out, err = run_os_command(acls_modify_cmd)
+  #   retcode, out, err = os_run_os_command(acls_modify_cmd)
   return retcode
 
 
@@ -248,8 +267,6 @@ def os_getpass(prompt, stream=None):
   if sys.stdin is not sys.__stdin__:
     return getpass.fallback_getpass(prompt, stream)
 
-  import msvcrt
-
   for c in prompt:
     msvcrt.putch(c)
 
@@ -506,24 +523,24 @@ class WinService(win32serviceutil.ServiceFramework):
 class SystemWideLock(object):
 
   def __init__(self, name):
-    self._mutex = CreateMutex(None, 0, name)
+    self._mutex = win32event.CreateMutex(None, 0, name)
 
   def lock(self, timeout=0):
-    result = WaitForSingleObject(self._mutex, timeout)
-    if result in [WAIT_TIMEOUT, WAIT_ABANDONED, WAIT_FAILED]:
+    result = win32event.WaitForSingleObject(self._mutex, timeout)
+    if result in [win32event.WAIT_TIMEOUT, win32event.WAIT_ABANDONED, win32event.WAIT_FAILED]:
       return False
-    elif result == WAIT_OBJECT_0:
+    elif result == win32event.WAIT_OBJECT_0:
       return True
 
   def unlock(self):
     try:
-      ReleaseMutex(self._mutex)
+      win32event.ReleaseMutex(self._mutex)
       return True
     except:
       return False
 
   def __del__(self):
-    CloseHandle(self._mutex)
+    win32api.CloseHandle(self._mutex)
 
 class UserHelper(object):
   ACTION_OK = 0
@@ -531,17 +548,18 @@ class UserHelper(object):
   ACTION_FAILED = -1
 
   def __init__(self):
-    self._policy = LsaOpenPolicy(None, POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES)
+    self._policy = win32security.LsaOpenPolicy(None,
+                                               win32security.POLICY_CREATE_ACCOUNT | win32security.POLICY_LOOKUP_NAMES)
 
   def create_user(self, name, password, comment="Ambari user"):
     user_info = {}
     user_info['name'] = name
     user_info['password'] = password
-    user_info['priv'] = USER_PRIV_USER
+    user_info['priv'] = win32netcon.USER_PRIV_USER
     user_info['comment'] = comment
-    user_info['flags'] = UF_NORMAL_ACCOUNT | UF_SCRIPT
+    user_info['flags'] = win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT
     try:
-      NetUserAdd(None, 1, user_info)
+      win32net.NetUserAdd(None, 1, user_info)
     except pywintypes.error as e:
       if e.winerror == 2224:
         return UserHelper.USER_EXISTS, e.strerror
@@ -551,16 +569,16 @@ class UserHelper(object):
 
   def add_user_privilege(self, name, privilege):
     try:
-      acc_sid = LookupAccountName(None, name)[0]
-      LsaAddAccountRights(self._policy, acc_sid, (privilege,))
+      acc_sid = win32security.LookupAccountName(None, name)[0]
+      win32security.LsaAddAccountRights(self._policy, acc_sid, (privilege,))
     except pywintypes.error as e:
       return UserHelper.ACTION_FAILED, e.strerror
     return UserHelper.ACTION_OK, "Privilege added."
 
   def remove_user_privilege(self, name, privilege):
     try:
-      acc_sid = LookupAccountName(None, name)[0]
-      LsaRemoveAccountRights(self._policy, acc_sid, 0, (privilege,))
+      acc_sid = win32security.LookupAccountName(None, name)[0]
+      win32security.LsaRemoveAccountRights(self._policy, acc_sid, 0, (privilege,))
     except pywintypes.error as e:
       return UserHelper.ACTION_FAILED, e.strerror
     return UserHelper.ACTION_OK, "Privilege removed."

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/providers/windows/system.py b/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
index e7a98fc..dac44ec 100644
--- a/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
+++ b/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
@@ -140,7 +140,7 @@ def QueryPrivilegeState(hToken, priv):
   for (id, attr) in privList:
     if id == privId:
       privState = attr
-  Logger.debug('Privilege state: {}={} ({}) Enabled={}'.format(privId, priv, LookupPrivilegeDisplayName(None, priv), privState))
+  Logger.debug('Privilege state: {0}={1} ({2}) Enabled={3}'.format(privId, priv, LookupPrivilegeDisplayName(None, priv), privState))
   return privState
 
 # Execute command. As windows hdp stack heavily relies on proper environment it is better to reload fresh environment
@@ -182,7 +182,7 @@ def _call_command(command, logoutput=False, cwd=None, env=None, wait_for_finish=
     if not ok:
       raise Exception("Unable to create StdErr for child process")
 
-    Logger.debug("Redirecting stdout to '{}', stderr to '{}'".format(out_file.name, err_file.name))
+    Logger.debug("Redirecting stdout to '{0}', stderr to '{1}'".format(out_file.name, err_file.name))
 
     si.dwFlags = win32con.STARTF_USESTDHANDLES
     si.lpDesktop = ""

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/main/python/resource_management/libraries/functions/get_unique_id_and_date.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/get_unique_id_and_date.py b/ambari-common/src/main/python/resource_management/libraries/functions/get_unique_id_and_date.py
index afc82bb..c428a6d 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/get_unique_id_and_date.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/get_unique_id_and_date.py
@@ -26,7 +26,7 @@ from resource_management.core import shell
 from ambari_commons import os_check
 def get_unique_id_and_date():
   if os_check.OSCheck.is_windows_family():
-    from ambari_commons.os_windows import run_os_command
+    from ambari_commons.os_utils import run_os_command
     code, out, err = run_os_command("cmd /c vol C:")
     for line in out.splitlines():
       if line.startswith(" Volume Serial Number is"):

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-common/src/test/python/only_for_platform.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/test/python/only_for_platform.py b/ambari-common/src/test/python/only_for_platform.py
index a0b5442..1b08db5 100644
--- a/ambari-common/src/test/python/only_for_platform.py
+++ b/ambari-common/src/test/python/only_for_platform.py
@@ -33,3 +33,15 @@ def only_for_platform(system):
     if platform.system() == system:
       return obj
   return decorator
+
+def not_for_platform(system):
+  def decorator(obj):
+    if platform.system() != system:
+      return obj
+  return decorator
+
+def for_specific_platforms(systems):
+  def decorator(obj):
+    if platform.system() in systems:
+      return obj
+  return decorator

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/conf/windows/ambari.properties
----------------------------------------------------------------------
diff --git a/ambari-server/conf/windows/ambari.properties b/ambari-server/conf/windows/ambari.properties
index 3982bb9..ec4da55 100644
--- a/ambari-server/conf/windows/ambari.properties
+++ b/ambari-server/conf/windows/ambari.properties
@@ -30,6 +30,7 @@ jdk1.7.67.dest-file=jdk-7u67-windows-x64.exe
 jdk1.7.67.jcpol-url=http://public-repo-1.hortonworks.com/ARTIFACTS/UnlimitedJCEPolicyJDK7.zip
 jdk1.7.67.jcpol-file=UnlimitedJCEPolicyJDK7.zip
 jdk1.7.67.home=C:\\jdk1.7.0_67
+jdk1.7.67.re=(jdk.*)/jre
 
 metadata.path=resources\\stacks
 common.services.path=resources\\common-services

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari-server-windows.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server-windows.py b/ambari-server/src/main/python/ambari-server-windows.py
index 6c4f894..5f9d58f 100644
--- a/ambari-server/src/main/python/ambari-server-windows.py
+++ b/ambari-server/src/main/python/ambari-server-windows.py
@@ -19,10 +19,10 @@ limitations under the License.
 '''
 
 import optparse
+import subprocess
 
 from ambari_commons.ambari_service import AmbariService, ENV_PYTHON_PATH
-from ambari_commons.logging_utils import *
-from ambari_commons.os_utils import remove_file
+from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, set_debug_mode
 from ambari_commons.os_windows import SvcStatusCallback
 
 from ambari_server import utils
@@ -42,11 +42,6 @@ SUSPEND_START_MODE = False
 ambari_provider_module_option = ""
 ambari_provider_module = os.environ.get('AMBARI_PROVIDER_MODULE')
 
-#Common setup or upgrade message
-SETUP_OR_UPGRADE_MSG = "- If this is a new setup, then run the \"ambari-server setup\" command to create the user\n" \
-"- If this is an upgrade of an existing setup, run the \"ambari-server upgrade\" command.\n" \
-"Refer to the Ambari documentation for more information on setup and upgrade."
-
 AMBARI_SERVER_DIE_MSG = "Ambari Server java process died with exitcode {0}. Check {1} for more information."
 
 if ambari_provider_module is not None:
@@ -173,22 +168,19 @@ def svcstart():
 def server_process_main(options, scmStatus=None):
   # set verbose
   try:
-    global VERBOSE
-    VERBOSE = options.verbose
+    set_verbose(options.verbose)
   except AttributeError:
     pass
 
   # set silent
   try:
-    global SILENT
-    SILENT = options.silent
+    set_silent(options.silent)
   except AttributeError:
     pass
 
   # debug mode
   try:
-    global DEBUG_MODE
-    DEBUG_MODE = options.debug
+    set_debug_mode(options.debug)
   except AttributeError:
     pass
 
@@ -242,7 +234,7 @@ def server_process_main(options, scmStatus=None):
 
   java_exe = jdk_path + os.sep + JAVA_EXE_SUBPATH
   pidfile = PID_DIR + os.sep + PID_NAME
-  command_base = SERVER_START_CMD_DEBUG if (DEBUG_MODE or SERVER_START_DEBUG) else SERVER_START_CMD
+  command_base = SERVER_START_CMD_DEBUG if (get_debug_mode() or SERVER_START_DEBUG) else SERVER_START_CMD
   suspend_mode = 'y' if SUSPEND_START_MODE else 'n'
   command = command_base.format(conf_dir, suspend_mode)
   if not os.path.exists(PID_DIR):
@@ -305,7 +297,7 @@ def ensure_resources_are_organized(properties):
   resource_files_keeper = ResourceFilesKeeper(resources_location)
   try:
     print "Organizing resource files at {0}...".format(resources_location,
-                                                       verbose=VERBOSE)
+                                                       verbose=get_verbose())
     resource_files_keeper.perform_housekeeping()
   except KeeperException, ex:
     msg = "Can not organize resource files at {0}: {1}".format(

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index a6366e7..6388dc6 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -39,16 +39,17 @@ import datetime
 import tempfile
 import random
 import pwd
+
+from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \
+  set_debug_mode
 from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException
 import json
 import base64
-from threading import Thread
+
 from ambari_commons import OSCheck, OSConst, Firewall
 from ambari_server import utils, BackupRestore
 
 # debug settings
-VERBOSE = False
-SILENT = False
 SERVER_START_DEBUG = False
 
 # ldap settings
@@ -1390,7 +1391,7 @@ def execute_remote_script(args, scriptPath):
   tool = get_db_cli_tool(args)
   if not tool:
     # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    if VERBOSE:
+    if get_verbose():
       print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
     return -1, "Client wasn't found", "Client wasn't found"
   CMD = get_remote_script_line(args, scriptPath, False)
@@ -1405,7 +1406,7 @@ def get_remote_script_line(args, scriptPath, forPrint=True):
   tool = get_db_cli_tool(args)
   if not tool:
     # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-    if VERBOSE or args.persistence_type == "remote":
+    if get_verbose() or args.persistence_type == "remote":
       print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
     return None
   if args.dbms == "postgres":
@@ -2205,7 +2206,7 @@ def check_jdbc_drivers(args):
         JAVA_SHARE_PATH)
 
   if result == -1:
-    if SILENT:
+    if get_silent():
       print_error_msg(msg)
       raise FatalException(-1, msg)
     else:
@@ -2251,7 +2252,7 @@ def verify_setup_allowed():
 
   isSecure = get_is_secure(properties)
   (isPersisted, masterKeyFile) = get_is_persisted(properties)
-  if isSecure and not isPersisted and SILENT:
+  if isSecure and not isPersisted and get_silent():
     print "ERROR: Cannot run silent 'setup' with password encryption enabled " \
           "and Master Key not persisted."
     print "Ambari Server 'setup' exiting."
@@ -2432,8 +2433,7 @@ def proceedJDBCProperties(args):
 #
 def reset(args):
   #force reset if silent option provided
-  global SILENT
-  if SILENT:
+  if get_silent():
     default = "yes"
   else:
     default = "no"
@@ -2452,7 +2452,7 @@ def reset(args):
                      "You will be required to re-configure the Ambari server "
                      "and re-run the cluster wizard. \n"
                      "Are you SURE you want to perform the reset "
-                     "[yes/no] ({0})? ".format(default), SILENT)
+                     "[yes/no] ({0})? ".format(default), get_silent())
   okToRun = choice
 
   if not okToRun:
@@ -2480,7 +2480,7 @@ def reset(args):
       raise NonFatalException("Please replace '*' symbols with password before running DDL`s!")
   else:
     # Run automatic reset only for embedded DB
-    okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), SILENT)
+    okToRun = get_YN_input("Confirm server reset [yes/no]({0})? ".format(default), get_silent())
 
     if not okToRun:
       err = "Ambari Server 'reset' cancelled"
@@ -2499,14 +2499,14 @@ def reset(args):
       raise FatalException(1, drop_errdata)
     if drop_errdata and PG_ERROR_BLOCKED in drop_errdata:
       raise FatalException(1, "Database is in use. Please, make sure all connections to the database are closed")
-    if drop_errdata and VERBOSE:
+    if drop_errdata and get_verbose():
       print_warning_msg(drop_errdata)
     print_info_msg("About to run database setup")
     retcode, outdata, errdata = setup_db(args)
-    if errdata and VERBOSE:
+    if errdata and get_verbose():
       print_warning_msg(errdata)
     if (errdata and 'ERROR' in errdata.upper()) or (drop_errdata and 'ERROR' in drop_errdata.upper()):
-      if not VERBOSE:
+      if not get_verbose():
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
       else:
         raise NonFatalException("Non critical error in DDL")
@@ -2625,7 +2625,7 @@ def start(args):
         environ[SECURITY_MASTER_KEY_LOCATION] = tempFilePath
 
   pidfile = PID_DIR + os.sep + PID_NAME
-  command_base = SERVER_START_CMD_DEBUG if (SERVER_DEBUG_MODE or SERVER_START_DEBUG) else SERVER_START_CMD
+  command_base = SERVER_START_CMD_DEBUG if (get_debug_mode() or SERVER_START_DEBUG) else SERVER_START_CMD
   command = "%s %s; %s" % (ULIMIT_CMD, str(get_ulimit_open_files()),
                            command_base.format(jdk_path,
                                                conf_dir,
@@ -2797,7 +2797,7 @@ def change_objects_owner(args):
   command[-1] = command[-1].format(database_name, 'ambari', new_owner)
   retcode, stdout, stderr = run_os_command(command)
   if not retcode == 0:
-    if VERBOSE:
+    if get_verbose():
       if stdout:
         print_error_msg(stdout.strip())
       if stderr:
@@ -2968,7 +2968,7 @@ def status(args):
 # Prints an "info" messsage.
 #
 def print_info_msg(msg):
-  if VERBOSE:
+  if get_verbose():
     print("INFO: " + msg)
 
 
@@ -3001,7 +3001,7 @@ def get_YN_input(prompt, default):
 
 
 def get_choice_string_input(prompt, default, firstChoice, secondChoice):
-  if SILENT:
+  if get_silent():
     print(prompt)
     return default
   choice = raw_input(prompt).lower()
@@ -3021,7 +3021,7 @@ def get_validated_string_input(prompt, default, pattern, description,
 
   input = ""
   while not input:
-    if SILENT:
+    if get_silent():
       print (prompt)
       input = default
     elif is_pass:
@@ -3126,7 +3126,7 @@ def sync_ldap():
       new_specs = [{"principal_type":"groups","sync_type":"specific","names":""}]
       get_ldap_event_spec_names(LDAP_SYNC_GROUPS, specs, new_specs)
 
-  if VERBOSE:
+  if get_verbose():
     sys.stdout.write('\nCalling API ' + SERVER_API_LDAP_URL + ' : ' + str(bodies) + '\n')
 
   request.add_data(json.dumps(bodies))
@@ -3834,7 +3834,7 @@ def setup_https(args):
           'root-level privileges'
     raise FatalException(4, err)
   args.exit_message = None
-  if not SILENT:
+  if not get_silent():
     properties = get_ambari_properties()
     try:
       security_server_keys_dir = properties.get_property(SSL_KEY_DIR)
@@ -3912,7 +3912,7 @@ def is_server_runing():
 
 def setup_component_https(component, command, property, alias):
 
-  if not SILENT:
+  if not get_silent():
 
     jdk_path = find_jdk()
     if jdk_path is None:
@@ -4149,7 +4149,7 @@ def generate_random_string(length=SSL_KEY_PASSWORD_LENGTH):
 def get_validated_filepath_input(prompt, description, default=None):
   input = False
   while not input:
-    if SILENT:
+    if get_silent():
       print (prompt)
       return default
     else:
@@ -4380,7 +4380,7 @@ def refresh_stack_hash():
 
   try:
     print "Organizing resource files at {0}...".format(resources_location,
-                                                       verbose=VERBOSE)
+                                                       verbose=get_verbose())
     resource_files_keeper.perform_housekeeping()
   except KeeperException, ex:
     msg = "Can not organize resource files at {0}: {1}".format(
@@ -4464,16 +4464,13 @@ def main():
   (options, args) = parser.parse_args()
 
   # set verbose
-  global VERBOSE
-  VERBOSE = options.verbose
+  set_verbose(options.verbose)
 
   # set silent
-  global SILENT
-  SILENT = options.silent
+  set_silent(options.silent)
 
   # debug mode
-  global SERVER_DEBUG_MODE
-  SERVER_DEBUG_MODE = options.debug
+  set_debug_mode(options.debug)
 
   # set ldap_sync_all
   global LDAP_SYNC_ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
index ce47fae..62853b7 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -513,14 +513,14 @@ class PGConfig(DBMSConfig):
       raise FatalException(1, drop_errdata)
     if drop_errdata and PG_ERROR_BLOCKED in drop_errdata:
       raise FatalException(1, "Database is in use. Please, make sure all connections to the database are closed")
-    if drop_errdata and VERBOSE:
+    if drop_errdata and get_verbose():
       print_warning_msg(drop_errdata)
     print_info_msg("About to run database setup")
     retcode, outdata, errdata = setup_db(args)
-    if errdata and VERBOSE:
+    if errdata and get_verbose():
       print_warning_msg(errdata)
     if (errdata and 'ERROR' in errdata.upper()) or (drop_errdata and 'ERROR' in drop_errdata.upper()):
-      if not VERBOSE:
+      if not get_verbose():
         raise NonFatalException("Non critical error in DDL, use --verbose for more information")
       else:
         raise NonFatalException("Non critical error in DDL")
@@ -631,7 +631,7 @@ class PGDatabase:
     tool = get_db_cli_tool(args)
     if not tool:
       # args.warnings.append('{0} not found. Please, run DDL script manually'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
-      if VERBOSE:
+      if get_verbose():
         print_warning_msg('{0} not found'.format(DATABASE_CLI_TOOLS[DATABASE_INDEX]))
       return -1, "Client wasn't found", "Client wasn't found"
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/serverConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
index 5e5c440..6c43669 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -21,6 +21,7 @@ limitations under the License.
 import datetime
 import glob
 import re
+import tempfile
 
 from ambari_commons.os_utils import *
 from ambari_commons.logging_utils import print_warning_msg, print_info_msg, print_error_msg
@@ -120,6 +121,13 @@ STACK_LOCATION_DEFAULT = "resources" + os.sep + "stacks"
 # JDK
 JDK_RELEASES="java.releases"
 
+#Common setup or upgrade message
+SETUP_OR_UPGRADE_MSG = "- If this is a new setup, then run the \"ambari-server setup\" command to create the user\n" \
+                       "- If this is an upgrade of an existing setup, run the \"ambari-server upgrade\" command.\n" \
+                       "Refer to the Ambari documentation for more information on setup and upgrade."
+
+DEFAULT_DB_NAME = "ambari"
+
 # configuration backup
 back_up_file_path = None
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/serverSetup.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py b/ambari-server/src/main/python/ambari_server/serverSetup.py
index 2b9c950..b541ffc 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -50,7 +50,7 @@ def verify_setup_allowed():
 
   isSecure = get_is_secure(properties)
   (isPersisted, masterKeyFile) = get_is_persisted(properties)
-  if isSecure and not isPersisted and SILENT:
+  if isSecure and not isPersisted and get_silent():
     print "ERROR: Cannot run silent 'setup' with password encryption enabled " \
           "and Master Key not persisted."
     print "Ambari Server 'setup' exiting."
@@ -526,6 +526,9 @@ def reset(options, serviceClass):
 
 def is_server_running(serviceClass):
   statusStr = serviceClass.QueryStatus()
+  from ambari_commons.os_windows import SERVICE_STATUS_STARTING, SERVICE_STATUS_RUNNING, SERVICE_STATUS_STOPPING, \
+    SERVICE_STATUS_STOPPED, SERVICE_STATUS_NOT_INSTALLED
+
   if statusStr in(SERVICE_STATUS_STARTING, SERVICE_STATUS_RUNNING, SERVICE_STATUS_STOPPING):
     return True, ""
   elif statusStr == SERVICE_STATUS_STOPPED:

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/serverSetup_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup_linux.py b/ambari-server/src/main/python/ambari_server/serverSetup_linux.py
index b5436e0..ea92a7d 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup_linux.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup_linux.py
@@ -131,9 +131,6 @@ JDBC_DB_DEFAULT_DRIVER = {"postgresql" : "postgresql-jdbc.jar", "mysql" : "mysql
 ORACLE_DB_ID_TYPES = ["Service Name", "SID"]
 
 
-DEFAULT_DB_NAME = "ambari"
-
-
 MESSAGE_ERROR_NOT_ROOT = 'Ambari-server setup should be run with root-level privileges'
 
 MESSAGE_CHECK_FIREWALL = 'Checking iptables...'
@@ -360,7 +357,7 @@ def os_setup_jdbc_drivers(args):
         JAVA_SHARE_PATH)
 
   if result == -1:
-    if SILENT:
+    if get_silent():
       print_error_msg(msg)
       raise FatalException(-1, msg)
     else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/serverSetup_windows.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup_windows.py b/ambari-server/src/main/python/ambari_server/serverSetup_windows.py
index a906ef5..00b7d0b 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup_windows.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup_windows.py
@@ -30,7 +30,7 @@ from ambari_commons import os_utils
 
 from ambari_commons.exceptions import *
 from ambari_commons.logging_utils import *
-from ambari_commons.os_windows import run_os_command, UserHelper
+from ambari_commons.os_windows import run_powershell_script, UserHelper, CHECK_FIREWALL_SCRIPT
 from ambari_server.dbConfiguration import DBMSConfig
 from ambari_server.serverConfiguration import *
 from ambari_server.serverConfiguration_windows import OUT_DIR

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/setupSecurity.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupSecurity.py b/ambari-server/src/main/python/ambari_server/setupSecurity.py
index 57a3231..e6879b9 100644
--- a/ambari-server/src/main/python/ambari_server/setupSecurity.py
+++ b/ambari-server/src/main/python/ambari_server/setupSecurity.py
@@ -23,9 +23,11 @@ import random
 import socket
 import stat
 import sys
+import tempfile
 import urllib2
 
 from ambari_commons.exceptions import *
+from ambari_commons.os_utils import run_os_command
 from serverConfiguration import *
 from setupActions import *
 from userInput import *
@@ -774,7 +776,7 @@ def setup_https(args):
           'root-level privileges'
     raise FatalException(4, err)
   args.exit_message = None
-  if not SILENT:
+  if not get_silent():
     properties = get_ambari_properties()
     try:
       security_server_keys_dir = properties.get_property(SSL_KEY_DIR)
@@ -824,7 +826,7 @@ def setup_https(args):
 
 def setup_component_https(component, command, property, alias):
 
-  if not SILENT:
+  if not get_silent():
     jdk_path = find_jdk()
     if jdk_path is None:
       err = "No JDK found, please run the \"ambari-server setup\" " \

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/python/ambari_server/userInput.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/userInput.py b/ambari-server/src/main/python/ambari_server/userInput.py
index 7a35831..54ad6c8 100644
--- a/ambari-server/src/main/python/ambari_server/userInput.py
+++ b/ambari-server/src/main/python/ambari_server/userInput.py
@@ -22,7 +22,8 @@ import os
 import getpass
 import re
 
-from ambari_commons.logging_utils import *
+from ambari_commons.logging_utils import get_silent
+from ambari_commons.os_utils import get_password
 
 
 #
@@ -30,9 +31,6 @@ from ambari_commons.logging_utils import *
 #
 # return True if 'y' or False if 'n'
 #
-from ambari_commons.os_utils import get_password
-
-
 def get_YN_input(prompt, default):
   yes = set(['yes', 'ye', 'y'])
   no = set(['no', 'n'])
@@ -40,7 +38,7 @@ def get_YN_input(prompt, default):
 
 
 def get_choice_string_input(prompt, default, firstChoice, secondChoice):
-  if SILENT:
+  if get_silent():
     print(prompt)
     return default
   choice = raw_input(prompt).lower()
@@ -60,7 +58,7 @@ def get_validated_string_input(prompt, default, pattern, description,
 
   input = ""
   while not input:
-    if SILENT:
+    if get_silent():
       print (prompt)
       input = default
     elif is_pass:
@@ -96,7 +94,7 @@ def get_validated_string_input(prompt, default, pattern, description,
 def get_validated_filepath_input(prompt, description, default=None):
   input = False
   while not input:
-    if SILENT:
+    if get_silent():
       print (prompt)
       return default
     else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/16bee385/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
index 3221cdb..83c8037 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
@@ -24,9 +24,9 @@ import json
 import sys
 import traceback
 from resource_management import *
-from resource_management.libraries.functions.list_ambari_managed_repos import *
+from resource_management.libraries.functions.list_ambari_managed_repos import list_ambari_managed_repos
 from ambari_commons.os_check import OSCheck, OSConst
-from resource_management.libraries.functions import packages_analyzer
+from resource_management.libraries.functions.packages_analyzer import allInstalledPackages
 
 
 class InstallPackages(Script):
@@ -81,7 +81,7 @@ class InstallPackages(Script):
       packages_were_checked = False
       try:
         packages_installed_before = []
-        packages_analyzer.allInstalledPackages(packages_installed_before)
+        allInstalledPackages(packages_installed_before)
         packages_installed_before = [package[0] for package in packages_installed_before]
         packages_were_checked = True
         for package in package_list:
@@ -95,7 +95,7 @@ class InstallPackages(Script):
         # Remove already installed packages in case of fail
         if packages_were_checked and packages_installed_before:
           packages_installed_after = []
-          packages_analyzer.allInstalledPackages(packages_installed_after)
+          allInstalledPackages(packages_installed_after)
           packages_installed_after = [package[0] for package in packages_installed_after]
           packages_installed_before = set(packages_installed_before)
           new_packages_installed = [package for package in packages_installed_after if package not in packages_installed_before]