ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fba...@apache.org
Subject ambari git commit: AMBARI-10491 [WinTP2] Ambari server: Ensure the service can be configured to run under a domain account
Date Fri, 17 Apr 2015 22:34:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk bdf5effbe -> 180640d94


AMBARI-10491 [WinTP2] Ambari server: Ensure the service can be configured to run under a domain
account

+Fixed service username handling at registration.
+Fixed service registration workflow.
+Updated unit tests.


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

Branch: refs/heads/trunk
Commit: 180640d943736b90ca2bc03f3ed6512e73e8d5e6
Parents: bdf5eff
Author: Florian Barca <fbarca@hortonworks.com>
Authored: Fri Apr 17 15:33:59 2015 -0700
Committer: Florian Barca <fbarca@hortonworks.com>
Committed: Fri Apr 17 15:33:59 2015 -0700

----------------------------------------------------------------------
 .../main/python/ambari_commons/os_windows.py    |  12 +-
 ambari-server/src/main/python/ambari-server.py  |  17 +-
 .../python/ambari_server/serverConfiguration.py |   3 -
 .../main/python/ambari_server/serverSetup.py    | 154 ++++++++++++-------
 .../src/main/python/ambari_windows_service.py   |  17 +-
 .../src/test/python/TestAmbariServer.py         | 142 ++++++++---------
 6 files changed, 201 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/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 edbcc7b..38db310 100644
--- a/ambari-common/src/main/python/ambari_commons/os_windows.py
+++ b/ambari-common/src/main/python/ambari_commons/os_windows.py
@@ -629,7 +629,7 @@ class WinService(win32serviceutil.ServiceFramework):
       installArgs.append("--perfmondll=" + perfMonDll)
     installArgs.append("install")
 
-    win32serviceutil.HandleCommandLine(cls, classPath, installArgs)
+    return win32serviceutil.HandleCommandLine(cls, classPath, installArgs)
 
   @classmethod
   def Start(cls, waitSecs = 30):
@@ -740,6 +740,16 @@ class UserHelper(object):
         return UserHelper.ACTION_FAILED, e.strerror
     return UserHelper.ACTION_OK, "User created."
 
+  def find_user(self):
+    try:
+      user_info = win32net.NetUserGetInfo(self.dcName, self.userName, 0)
+    except pywintypes.error as e:
+      if e.winerror == 2221:
+        return False
+      else:
+        raise
+    return True
+
   def add_user_privilege(self, privilege):
     try:
       acc_sid = win32security.LookupAccountName(self.dcName, self.userName)[0]

http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/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 f1f005d..749a965 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -69,12 +69,6 @@ class UserActionRestart(UserAction):
     self.need_restart = self.fn(*self.args, **self.kwargs)
 
 
-def winsetup(options):
-  from ambari_windows_service import svcsetup
-
-  setup(options)
-  svcsetup()
-
 #
 # Starts the Ambari Server as a standalone process.
 # Ensures only one instance of the process is running.
@@ -269,6 +263,13 @@ def restore(args):
 
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 def init_parser_options(parser):
+  parser.add_option('-k', '--service-user-name', dest="svc_user",
+                    default=None,
+                    help="User account under which the Ambari Server service will run")
+  parser.add_option('-x', '--service-user-password', dest="svc_password",
+                    default=None,
+                    help="Password for the Ambari Server service user account")
+
   parser.add_option('-f', '--init-script-file', dest="init_db_script_file",
                     default="resources" + os.sep + "Ambari-DDL-SQLServer-CREATE.sql",
                     help="File with database setup script")
@@ -302,7 +303,7 @@ def init_parser_options(parser):
                     help="Database user password")
   parser.add_option('--jdbc-driver', default=None, dest="jdbc_driver",
                     help="Specifies the path to the JDBC driver JAR file")
-  # -b, -i, -k and -x the remaining available short options
+  # -b and -i the remaining available short options
   # -h reserved for help
 
 @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
@@ -475,7 +476,7 @@ def fix_database_options(options, parser):
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 def create_user_action_map(args, options):
   action_map = {
-    SETUP_ACTION: UserAction(winsetup, options),
+    SETUP_ACTION: UserAction(setup, options),
     START_ACTION: UserAction(svcstart),
     PSTART_ACTION: UserAction(start, options),
     STOP_ACTION: UserAction(stop),

http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/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 c13202c..26ee4b0 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -126,9 +126,6 @@ JDBC_RCA_USE_INTEGRATED_AUTH_PROPERTY = "server.jdbc.rca.use.integrated.auth"
 
 ### # End Windows-specific # ###
 
-SERVICE_USERNAME_KEY = "TMP_AMBARI_USERNAME"
-SERVICE_PASSWORD_KEY = "TMP_AMBARI_PASSWORD"
-
 # resources repo configuration
 RESOURCES_DIR_PROPERTY = "resources.dir"
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/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 ddb44fd..89e3afd 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -27,7 +27,7 @@ import sys
 from ambari_commons.exceptions import FatalException
 from ambari_commons.firewall import Firewall
 from ambari_commons.inet_utils import force_download_file, download_progress
-from ambari_commons.logging_utils import get_silent, print_info_msg, print_warning_msg, print_error_msg
+from ambari_commons.logging_utils import get_silent, print_info_msg, print_warning_msg, print_error_msg,
get_verbose
 from ambari_commons.os_check import OSConst
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
 from ambari_commons.os_utils import copy_files, run_os_command, is_root
@@ -38,7 +38,7 @@ from ambari_server.serverConfiguration import configDefaults, JDKRelease,
\
   get_resources_location, get_value_from_properties, read_ambari_user, update_properties,
validate_jdk, write_property, \
   JAVA_HOME, JAVA_HOME_PROPERTY, JCE_NAME_PROPERTY, JDBC_RCA_URL_PROPERTY, JDBC_URL_PROPERTY,
\
   JDK_NAME_PROPERTY, JDK_RELEASES, NR_USER_PROPERTY, OS_FAMILY, OS_FAMILY_PROPERTY, OS_TYPE,
OS_TYPE_PROPERTY, OS_VERSION, \
-  SERVICE_PASSWORD_KEY, SERVICE_USERNAME_KEY, VIEWS_DIR_PROPERTY, JDBC_DATABASE_PROPERTY
+  VIEWS_DIR_PROPERTY, JDBC_DATABASE_PROPERTY
 from ambari_server.serverUtils import is_server_runing
 from ambari_server.setupSecurity import adjust_directory_permissions
 from ambari_server.userInput import get_YN_input, get_validated_string_input
@@ -161,29 +161,34 @@ class AmbariUserChecks(object):
     self.NR_DEFAULT_USER = ""
     self.NR_USER_COMMENT = "Ambari user"
 
+    self.register_service = False
+    self.user = None
+    self.password = None
+
   def do_checks(self):
     try:
       user = read_ambari_user()
-      create_user = False
-      update_user_setting = False
-      if user is not None:
-        create_user = get_YN_input(self.NR_USER_CHANGE_PROMPT.format(user), False)
-        update_user_setting = create_user  # Only if we will create another user
-      else:  # user is not configured yet
-        update_user_setting = True  # Write configuration anyway
-        create_user = get_YN_input(self.NR_USER_CUSTOMIZE_PROMPT, False)
-        if not create_user:
-          user = self.NR_DEFAULT_USER
-
-      if create_user:
-        (retcode, user) = self._create_custom_user()
+      if not user:
+        user = self.NR_DEFAULT_USER
+
+      if self.user is not None:   #Command-line parameter is the default
+        update_user_setting = True
+        prompt_msg = self.NR_USER_CUSTOMIZE_PROMPT.format('y')
+      else:
+        update_user_setting = False
+        if user != self.NR_DEFAULT_USER:
+          prompt_msg = self.NR_USER_CHANGE_PROMPT.format(user, 'n')
+        else:
+          prompt_msg = self.NR_USER_CUSTOMIZE_PROMPT.format('n')
+        self.user = user if user else self.NR_DEFAULT_USER
+
+      self.register_service = get_YN_input(prompt_msg, update_user_setting)
+      if self.register_service:
+        retcode = self._create_custom_user()
         if retcode != 0:
           return retcode
 
-      if update_user_setting:
-        write_property(NR_USER_PROPERTY, user)
-
-      adjust_directory_permissions(user)
+      adjust_directory_permissions(self.user)
     except OSError as e:
       print_error_msg("Failed: %s" % str(e))
       return 4
@@ -197,62 +202,79 @@ class AmbariUserChecks(object):
 
 @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)
 class AmbariUserChecksWindows(AmbariUserChecks):
-  def __init__(self):
+  def __init__(self, options):
     super(AmbariUserChecksWindows, self).__init__()
 
-    self.NR_USER_CHANGE_PROMPT = "Ambari-server service is configured to run under user '{0}'.
Change this setting [y/n] (n)? "
-    self.NR_USER_CUSTOMIZE_PROMPT = "Customize user account for ambari-server service [y/n]
(n)? "
-    self.NR_DEFAULT_USER = "NT AUTHORITY\SYSTEM"
+    self.NR_USER_CHANGE_PROMPT = "Ambari-server service is configured to run under user '{0}'.
Change this setting [y/n] ({1})? "
+    self.NR_USER_CUSTOMIZE_PROMPT = "Customize user account for ambari-server service [y/n]
({0})? "
+    self.NR_DEFAULT_USER = "NT AUTHORITY\\SYSTEM"
+    self.NR_SYSTEM_USERS = ["NT AUTHORITY\\SYSTEM", "NT AUTHORITY\\NetworkService", "NT AUTHORITY\\LocalService"]
+
+    self.username = options.svc_user
+    self.password = options.svc_password
 
   def _create_custom_user(self):
     user = get_validated_string_input(
-      "Enter user account for ambari-server service ({0}):".format(self.NR_DEFAULT_USER),
-      self.NR_DEFAULT_USER, None,
+      "Enter user account for ambari-server service ({0}):".format(self.username),
+      self.username, None,
       "Invalid username.",
       False
     )
-    if user == self.NR_DEFAULT_USER:
-      return 0, user
-    password = get_validated_string_input("Enter password for user {0}:".format(user), "",
None, "Password", True, False)
+    if user in self.NR_SYSTEM_USERS:
+      self.username = user
+      return 0
 
     from ambari_commons.os_windows import UserHelper
 
     uh = UserHelper(user)
 
-    status, message = uh.create_user(password)
-    if status == UserHelper.USER_EXISTS:
-      print_info_msg("User {0} already exists, make sure that you typed correct password
for user, "
-                     "skipping user creation".format(user))
+    if not uh.find_user():
+      if get_silent():
+        password = self.password
+      else:
+        password = get_validated_string_input("Enter password for user {0}:".format(user),
"", None, "Password", True, False)
+
+      status, message = uh.create_user(password)
+      if status == UserHelper.USER_EXISTS:
+        print_info_msg("User {0} already exists, make sure that you typed correct password
for user, "
+                       "skipping user creation".format(user))
 
-    elif status == UserHelper.ACTION_FAILED:  # fail
-      print_warning_msg("Can't create user {0}. Failed with message {1}".format(user, message))
-      return UserHelper.ACTION_FAILED, None
+      elif status == UserHelper.ACTION_FAILED:  # fail
+        print_warning_msg("Can't create user {0}. Failed with message {1}".format(user, message))
+        return UserHelper.ACTION_FAILED
 
-    # setting SeServiceLogonRight to user
+      self.password = password
 
+    # setting SeServiceLogonRight and SeBatchLogonRight to user
+    #This is unconditional
     status, message = uh.add_user_privilege('SeServiceLogonRight')
     if status == UserHelper.ACTION_FAILED:
       print_warning_msg("Can't add SeServiceLogonRight to user {0}. Failed with message {1}".format(user,
message))
-      return UserHelper.ACTION_FAILED, None
+      return UserHelper.ACTION_FAILED
+
+    status, message = uh.add_user_privilege('SeBatchLogonRight')
+    if status == UserHelper.ACTION_FAILED:
+      print_warning_msg("Can't add SeBatchLogonRight to user {0}. Failed with message {1}".format(user,
message))
+      return UserHelper.ACTION_FAILED
 
     print_info_msg("User configuration is done.")
     print_warning_msg("When using non SYSTEM user make sure that your user has read\write
access to log directories and "
                       "all server directories. In case of integrated authentication for SQL
Server make sure that your "
-                      "user is properly configured to use the ambari database.")
-    #storing username and password in os.environ temporary to pass them to service
-    if uh.domainName:
-      user = uh.domainName + '\\' + user
-    os.environ[SERVICE_USERNAME_KEY] = user
-    os.environ[SERVICE_PASSWORD_KEY] = password
-    return 0, user
+                      "user is properly configured to access the ambari database.")
+
+    if user.find('\\') == -1:
+      user = '.\\' + user
+
+    self.username = user
+    return 0
 
 @OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
 class AmbariUserChecksLinux(AmbariUserChecks):
-  def __init__(self):
+  def __init__(self, options):
     super(AmbariUserChecksLinux, self).__init__()
 
-    self.NR_USER_CHANGE_PROMPT = "Ambari-server daemon is configured to run under user '{0}'.
Change this setting [y/n] (n)? "
-    self.NR_USER_CUSTOMIZE_PROMPT = "Customize user account for ambari-server daemon [y/n]
(n)? "
+    self.NR_USER_CHANGE_PROMPT = "Ambari-server daemon is configured to run under user '{0}'.
Change this setting [y/n] ({1})? "
+    self.NR_USER_CUSTOMIZE_PROMPT = "Customize user account for ambari-server daemon [y/n]
({0})? "
     self.NR_DEFAULT_USER = "root"
 
     self.NR_USERADD_CMD = 'useradd -M --comment "{1}" ' \
@@ -261,7 +283,7 @@ class AmbariUserChecksLinux(AmbariUserChecks):
   def _create_custom_user(self):
     user = get_validated_string_input(
       "Enter user account for ambari-server daemon (root):",
-      "root",
+      self.user,
       "^[a-z_][a-z0-9_-]{1,31}$",
       "Invalid username.",
       False
@@ -277,13 +299,36 @@ class AmbariUserChecksLinux(AmbariUserChecks):
     elif retcode != 0:  # fail
       print_warning_msg("Can't create user {0}. Command {1} "
                         "finished with {2}: \n{3}".format(user, command, retcode, err))
-      return retcode, None
+      return retcode
 
     print_info_msg("User configuration is done.")
-    return 0, user
 
-def check_ambari_user():
-  return AmbariUserChecks().do_checks()
+    self.user = user
+
+    return 0
+
+def check_ambari_user(options):
+  uc = AmbariUserChecks(options)
+  retcode = uc.do_checks()
+  return retcode, uc.register_service, uc.user, uc.password
+
+
+#
+# Windows service setup
+#
+
+@OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
+def service_setup(register_service, svc_user, svc_password):
+  from ambari_windows_service import svcsetup
+
+  result = svcsetup(register_service, svc_user, svc_password)
+  if result == 0:
+    write_property(NR_USER_PROPERTY, svc_user)
+
+@OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
+def service_setup(register_service, svc_user, svc_password):
+  #Nothing else to do in Linux
+  write_property(NR_USER_PROPERTY, svc_user)
 
 
 #
@@ -971,7 +1016,7 @@ def setup(options):
     raise FatalException(retcode, err)
 
   #Create ambari user, if needed
-  retcode = check_ambari_user()
+  (retcode, register_service, svc_user, svc_password) = check_ambari_user(options)
   if not retcode == 0:
     err = 'Failed to create user. Exiting.'
     raise FatalException(retcode, err)
@@ -1012,8 +1057,9 @@ def setup(options):
     raise FatalException(retcode, err)
 
   # we've already done this, but new files were created so run it one time.
-  adjust_directory_permissions(read_ambari_user())
+  adjust_directory_permissions(svc_user)
 
+  service_setup(register_service, svc_user, svc_password)
 
 #
 # Setup the JCE policy for Ambari Server.

http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/ambari-server/src/main/python/ambari_windows_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_windows_service.py b/ambari-server/src/main/python/ambari_windows_service.py
index 8e86163..502aeb9 100644
--- a/ambari-server/src/main/python/ambari_windows_service.py
+++ b/ambari-server/src/main/python/ambari_windows_service.py
@@ -27,8 +27,7 @@ from ambari_commons.logging_utils import set_silent, set_verbose, print_info_msg
 from ambari_commons.os_utils import remove_file
 from ambari_commons.os_windows import SvcStatusCallback
 from ambari_server.serverConfiguration import configDefaults, get_ambari_properties, get_value_from_properties,
\
-  DEBUG_MODE_KEY, PID_NAME, SERVER_OUT_FILE_KEY, SERVICE_PASSWORD_KEY, SERVICE_USERNAME_KEY,
SUSPEND_START_MODE_KEY, \
-  VERBOSE_OUTPUT_KEY
+  DEBUG_MODE_KEY, PID_NAME, SERVER_OUT_FILE_KEY, SUSPEND_START_MODE_KEY, VERBOSE_OUTPUT_KEY
 
 
 class AmbariServerService(AmbariService):
@@ -86,15 +85,15 @@ def ctrlHandler(ctrlType):
   AmbariServerService.DefCtrlCHandler()
   return True
 
-def svcsetup():
+def svcsetup(register_service, username=None, password=None):
   AmbariServerService.set_ctrl_c_handler(ctrlHandler)
 
   scriptFile, ext = os.path.splitext(__file__.replace('/', os.sep))
   classPath = scriptFile + "." + AmbariServerService.__name__
 
-  # we don't save password between 'setup' runs, so we can't run Install every time. We run
'setup' only if user and
-  # password provided or if service not installed
-  if (SERVICE_USERNAME_KEY in os.environ and SERVICE_PASSWORD_KEY in os.environ):
-    AmbariServerService.Install(classPath=classPath, username=os.environ[SERVICE_USERNAME_KEY],
password=os.environ[SERVICE_PASSWORD_KEY])
-  elif AmbariServerService.QueryStatus() == "not installed":
-    AmbariServerService.Install(classPath)
+  # We don't save the password between 'setup' runs, so we can't run Install every time.
We run Install only if the
+  # operator acknowledged changing the username or if the service is not yet installed
+  if (register_service or AmbariServerService.QueryStatus() == "not installed"):
+    return AmbariServerService.Install(classPath=classPath, username=username, password=password)
+  else:
+    return 0

http://git-wip-us.apache.org/repos/asf/ambari/blob/180640d9/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 17e8aea..5c05ad3 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1122,16 +1122,19 @@ class TestAmbariServer(TestCase):
   @patch("ambari_server.serverSetup.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):
+    options = MagicMock()
+
     user = "dummy-user"
     get_validated_string_input_mock.return_value = user
 
-    userChecks = AmbariUserChecks()
+    userChecks = AmbariUserChecks(options)
 
     # Testing scenario: absent user
     run_os_command_mock.side_effect = [(0, "", "")]
     result = userChecks._create_custom_user()
     self.assertFalse(print_warning_msg_mock.called)
-    self.assertEquals(result, (0, user))
+    self.assertEquals(result, 0)
+    self.assertEquals(userChecks.user, user)
 
     print_info_msg_mock.reset_mock()
     print_warning_msg_mock.reset_mock()
@@ -1141,7 +1144,8 @@ class TestAmbariServer(TestCase):
     run_os_command_mock.side_effect = [(9, "", "")]
     result = userChecks._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))
+    self.assertEquals(result, 0)
+    self.assertEquals(userChecks.user, user)
 
     print_info_msg_mock.reset_mock()
     print_warning_msg_mock.reset_mock()
@@ -1151,139 +1155,138 @@ class TestAmbariServer(TestCase):
     run_os_command_mock.side_effect = [(1, "", "")]
     result = userChecks._create_custom_user()
     self.assertTrue(print_warning_msg_mock.called)
-    self.assertEquals(result, (1, None))
+    self.assertEquals(result, 1)
     pass
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("ambari_server.serverSetup.read_ambari_user")
   @patch("ambari_server.serverSetup.get_YN_input")
-  @patch.object(AmbariUserChecksLinux, "_create_custom_user")
-  @patch.object(AmbariUserChecksWindows, "_create_custom_user")
-  @patch("ambari_server.serverSetup.write_property")
+  @patch("ambari_server.serverSetup.get_validated_string_input")
   @patch("ambari_server.serverSetup.adjust_directory_permissions")
+  @patch("ambari_server.serverSetup.run_os_command")
   @patch("ambari_server.serverSetup.print_error_msg")
-  def test_check_ambari_user(self, print_error_msg_mock,
-                             adjust_directory_permissions_mock, write_property_mock,
-                             create_custom_user_mock, create_custom_user_2_mock, get_YN_input_mock,
read_ambari_user_mock):
+  @patch("ambari_server.serverSetup.print_warning_msg")
+  @patch("ambari_server.serverSetup.print_info_msg")
+  def test_check_ambari_user(self, print_info_msg_mock, print_warning_msg_mock, print_error_msg_mock,
+                             run_os_command_mock, adjust_directory_permissions_mock,
+                             get_validated_string_input_mock, get_YN_input_mock, read_ambari_user_mock):
+
+    options = MagicMock()
+
+    run_os_command_mock.return_value = (0, "", "")
 
     # 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 = check_ambari_user()
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertFalse(write_property_mock.called)
-    self.assertFalse(create_custom_user_mock.called or create_custom_user_2_mock.called)
+    self.assertFalse(get_validated_string_input_mock.called)
+    self.assertFalse(run_os_command_mock.called)
     self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
+    self.assertEqual(result[0], 0)
 
     get_YN_input_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
 
     # Scenario: user is already defined, but user wants to reconfigure it
 
     read_ambari_user_mock.return_value = "dummy-user"
-    create_custom_user_2_mock.return_value = create_custom_user_mock.return_value = (0, "new-dummy-user")
+    get_validated_string_input_mock.return_value = "new-dummy-user"
     get_YN_input_mock.return_value = True
-    result = check_ambari_user()
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "new-dummy-user")
-    self.assertTrue(create_custom_user_mock.called or create_custom_user_2_mock.called)
+    self.assertTrue(result[2] == "new-dummy-user")
+    self.assertTrue(get_validated_string_input_mock.called)
     self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
+    self.assertEqual(result[0], 0)
 
     get_YN_input_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
 
     # Negative scenario: user is already defined, but user wants
     # to reconfigure it, user creation failed
 
     read_ambari_user_mock.return_value = "dummy-user"
-    create_custom_user_2_mock.return_value = create_custom_user_mock.return_value = (1, None)
+    run_os_command_mock.return_value = (1, "", "")
     get_YN_input_mock.return_value = True
-    result = check_ambari_user()
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called or create_custom_user_2_mock.called)
-    self.assertFalse(write_property_mock.called)
+    self.assertTrue(get_validated_string_input_mock.called)
+    self.assertTrue(run_os_command_mock.called)
     self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
+    self.assertEqual(result[0], 1)
 
     get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
 
     # Scenario: user is not defined (setup process)
     read_ambari_user_mock.return_value = None
     get_YN_input_mock.return_value = True
-    create_custom_user_2_mock.return_value = create_custom_user_mock.return_value = (0, "dummy-user")
-    result = check_ambari_user()
+    get_validated_string_input_mock.return_value = "dummy-user"
+    run_os_command_mock.return_value = (0, "", "")
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called or create_custom_user_2_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "dummy-user")
+    self.assertTrue(get_validated_string_input_mock.called)
+    self.assertTrue(run_os_command_mock.called)
+    self.assertTrue(result[2] == "dummy-user")
     self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
+    self.assertEqual(result[0], 0)
 
     get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
 
     # Scenario: user is not defined (setup process), user creation failed
 
     read_ambari_user_mock.return_value = None
     get_YN_input_mock.return_value = True
-    create_custom_user_2_mock.return_value = create_custom_user_mock.return_value = (1, None)
-    result = check_ambari_user()
+    run_os_command_mock.return_value = (1, "", "")
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called or create_custom_user_2_mock.called)
-    self.assertFalse(write_property_mock.called)
+    self.assertTrue(get_validated_string_input_mock.called)
+    self.assertTrue(run_os_command_mock.called)
     self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
+    self.assertEqual(result[0], 1)
 
     get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
 
     # negative scenario: user is not defined (setup process), user creation failed
 
     read_ambari_user_mock.return_value = None
     get_YN_input_mock.return_value = True
-    create_custom_user_2_mock.return_value = create_custom_user_mock.return_value = (1, None)
-    result = check_ambari_user()
+    run_os_command_mock.return_value = (1, "", "")
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertTrue(create_custom_user_mock.called or create_custom_user_2_mock.called)
-    self.assertFalse(write_property_mock.called)
+    self.assertTrue(get_validated_string_input_mock.called)
+    self.assertTrue(run_os_command_mock.called)
     self.assertFalse(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 1)
+    self.assertEqual(result[0], 1)
 
     get_YN_input_mock.reset_mock()
-    create_custom_user_mock.reset_mock()
-    create_custom_user_2_mock.reset_mock()
-    write_property_mock.reset_mock()
+    get_validated_string_input_mock.reset_mock()
+    run_os_command_mock.reset_mock()
     adjust_directory_permissions_mock.reset_mock()
 
     # Scenario: user is not defined and left to be root
     read_ambari_user_mock.return_value = None
     get_YN_input_mock.return_value = False
-    result = check_ambari_user()
+    result = check_ambari_user(options)
     self.assertTrue(get_YN_input_mock.called)
-    self.assertFalse(create_custom_user_mock.called or create_custom_user_2_mock.called)
-    self.assertTrue(write_property_mock.called)
-    self.assertTrue(write_property_mock.call_args[0][1] == "root")
+    self.assertFalse(get_validated_string_input_mock.called)
+    self.assertFalse(run_os_command_mock.called)
+    self.assertTrue(result[2] == "root")
     self.assertTrue(adjust_directory_permissions_mock.called)
-    self.assertEqual(result, 0)
+    self.assertEqual(result[0], 0)
     pass
 
   @patch("ambari_server.serverConfiguration.search_file")
@@ -2866,10 +2869,11 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverSetup.proceedJDBCProperties")
   @patch("ambari_server.serverSetup.extract_views")
   @patch("ambari_server.serverSetup.adjust_directory_permissions")
+  @patch("ambari_server.serverSetup.service_setup")
   @patch("ambari_server.serverSetup.read_ambari_user")
   @patch("ambari_server.serverSetup.expand_jce_zip_file")
-  def test_setup(self, expand_jce_zip_file_mock,
-                 read_ambari_user_mock, adjust_dirs_mock, extract_views_mock, proceedJDBCProperties_mock,
is_root_mock,
+  def test_setup(self, expand_jce_zip_file_mock, read_ambari_user_mock,
+                 service_setup_mock, adjust_dirs_mock, extract_views_mock, proceedJDBCProperties_mock,
is_root_mock,
                  disable_security_enhancements_mock, check_jdbc_drivers_mock, check_ambari_user_mock,
                  download_jdk_mock, configure_os_settings_mock, get_ambari_properties_mock,
                  get_YN_input_mock, gvsi_mock, gvsi_1_mock,
@@ -2969,7 +2973,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     # remote case
     is_root_mock.return_value = True
     disable_security_enhancements_mock.return_value = (0, "")
-    check_ambari_user_mock.return_value = 0
+    check_ambari_user_mock.return_value = (0, False, 'user', None)
     check_jdbc_drivers_mock.return_value = 0
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0
@@ -4752,7 +4756,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     read_password_mock.return_value = "encrypted_bigdata"
     ensure_jdbc_driver_installed_mock.return_value = True
     check_jdbc_drivers_mock.return_value = 0
-    check_ambari_user_mock.return_value = 0
+    check_ambari_user_mock.return_value = (0, False, 'user', None)
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0
     verify_setup_allowed_method.return_value = 0
@@ -6429,7 +6433,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     verify_setup_allowed_method.return_value = 0
     is_root_mock.return_value = True
     check_selinux_mock.return_value = 0
-    check_ambari_user_mock.return_value = 0
+    check_ambari_user_mock.return_value = (0, False, 'user', None)
     check_jdbc_drivers_mock.return_value = 0
     check_postgre_up_mock.return_value = "running", 0, "", ""
     #is_local_database_mock.return_value = True


Mime
View raw message