瀏覽代碼

Add exception handling when whoami_s in ldaptest fails (#2813)

Jira: CDPD-17465
Mahesh Balakrishnan 3 年之前
父節點
當前提交
04381aa7aa
共有 1 個文件被更改,包括 14 次插入11 次删除
  1. 14 11
      desktop/core/src/desktop/management/commands/ldaptest.py

+ 14 - 11
desktop/core/src/desktop/management/commands/ldaptest.py

@@ -43,7 +43,6 @@ if sys.version_info[0] > 2:
 else:
   from django.utils.translation import ugettext as _
 
-
 LOG = logging.getLogger(__name__)
 LOG.setLevel(logging.DEBUG)
 ch = logging.StreamHandler(sys.stdout)
@@ -142,6 +141,7 @@ will typically work with Active Directory/LDAP. Typically this is member
 for Active Directory and LDAP.
 """
 
+
 class Command(BaseCommand):
   def print_ldap_global_settings(self, cfg, is_multi_ldap):
     LOG.info('[desktop]')
@@ -205,7 +205,7 @@ class Command(BaseCommand):
       return err_code
 
     if not ((ldap_url.startswith("ldap") and
-          "://" in ldap_url)):
+                 "://" in ldap_url)):
       LOG.info(_(ldap_url_msg))
       LOG.warning("Check your ldap_url=%s" % ldap_url)
       return err_code
@@ -231,12 +231,12 @@ class Command(BaseCommand):
       user_name_attr = ldap_config.USERS.USER_NAME_ATTR.get()
       user_filter = ldap_config.USERS.USER_FILTER.get()
       bind_password = ldap_config.BIND_PASSWORD.get()
-      if user_name_attr=='' or ' ' in user_name_attr:
+      if user_name_attr == '' or ' ' in user_name_attr:
         LOG.info(_(user_name_attr_msg))
         LOG.warning("Could not find user_name_attr in hue.ini")
         return err_code
 
-      if user_filter=='':
+      if user_filter == '':
         LOG.info(_(user_filter_msg))
         LOG.warning("Could not find user_filter in hue.ini required for authentication")
         return err_code
@@ -303,7 +303,7 @@ class Command(BaseCommand):
     if users:
       for user in users:
         LOG.info('%s' % user)
-        if user.get('username', '')=='':
+        if user.get('username', '') == '':
           LOG.info(_(user_name_attr_msg))
           LOG.warning('hints: check user_name_attr="%s"' % ldap_config.USERS.USER_NAME_ATTR.get())
           err_code = 1
@@ -344,7 +344,7 @@ class Command(BaseCommand):
       LOG.warning(ldap_obj.ldapsearch_cmd())
       return err_code
     else:
-     LOG.info(ldap_obj.ldapsearch_cmd())
+      LOG.info(ldap_obj.ldapsearch_cmd())
 
     if groups:
       for grp in groups:
@@ -387,7 +387,7 @@ class Command(BaseCommand):
     if groups:
       for grp in groups:
         LOG.info('%s' % grp)
-        if grp.get('members', [])==[]:
+        if grp.get('members', []) == []:
           LOG.info(_(group_member_attr_msg))
           LOG.warning('hints: check group_member_attr="%s"' % ldap_config.GROUPS.GROUP_MEMBER_ATTR.get())
           err_code = 1
@@ -429,7 +429,7 @@ class Command(BaseCommand):
     if groups:
       for grp in groups:
         LOG.info('%s' % grp)
-        if grp.get('members',[])==[]:
+        if grp.get('members', []) == []:
           LOG.info(_(group_member_attr_msg))
           LOG.warning('hints: check group_member_attr="%s"' % ldap_config.GROUPS.GROUP_MEMBER_ATTR.get())
           err_code = 1
@@ -439,7 +439,7 @@ class Command(BaseCommand):
     return err_code
 
   def sys_exit(self, exit_code):
-    if exit_code!=0:
+    if exit_code != 0:
       LOG.warning('LDAP Test Command failed')
     sys.exit(exit_code)
 
@@ -471,7 +471,6 @@ class Command(BaseCommand):
 
     self.sys_exit(err_code)
 
-
   def check_single_ldap_setting(self, ldap_config, is_multi_ldap=False):
     self.print_ldap_setting(ldap_config, is_multi_ldap)
     # Basic validation check for hue.ini's ldap parameters [desktop] > [[ldap]]
@@ -506,7 +505,11 @@ class Command(BaseCommand):
         LOG.warning(ldapsearch)
         self.sys_exit(err_code)
 
-      LOG.info('LDAP whoami_s() %s' % (connection.ldap_handle.whoami_s()))
+      try:
+        LOG.info('LDAP whoami_s() %s' % (connection.ldap_handle.whoami_s()))
+      except:
+        LOG.warn('Not able to execute whoami_s() command')
+
       if ldap_config.TEST_LDAP_USER.get() is not None:
         err_code = self.find_ldapusers(ldap_config, connection)
         if err_code: