浏览代码

HUE-3917 [core] Catch missing Oracle connector in is_db_alive command

Will print something like:
JDBC driver cannot be found. Unable to find the JDBC database jar on host
Romain Rigaux 9 年之前
父节点
当前提交
6619cb7
共有 2 个文件被更改,包括 13 次插入6 次删除
  1. 12 6
      desktop/core/src/desktop/manage_entry.py
  2. 1 0
      desktop/core/src/desktop/management/commands/is_db_alive.py

+ 12 - 6
desktop/core/src/desktop/manage_entry.py

@@ -34,6 +34,7 @@ def _deprecation_check(arg0):
 def entry():
   _deprecation_check(sys.argv[0])
 
+  from django.core.exceptions import ImproperlyConfigured
   from django.core.management import execute_from_command_line, find_commands, find_management_module
   from django.core.management import LaxOptionParser
   from django.core.management.base import BaseCommand
@@ -50,12 +51,17 @@ def entry():
   else:
     prof_id = str(os.getpid())
 
-  # Let django handle the normal execution
-  if os.getenv("DESKTOP_PROFILE"):
-    _profile(prof_id, lambda: execute_from_command_line(sys.argv))
-  else:
-    execute_from_command_line(sys.argv)
-
+  try:
+    # Let django handle the normal execution
+    if os.getenv("DESKTOP_PROFILE"):
+      _profile(prof_id, lambda: execute_from_command_line(sys.argv))
+    else:
+      execute_from_command_line(sys.argv)
+  except ImproperlyConfigured, e:
+    if len(sys.argv) > 1 and sys.argv[1] == 'is_db_alive' and 'oracle' in str(e).lower():
+      sys.exit(3)
+    else:
+      raise e
 
 def _profile(prof_id, func):
   """

+ 1 - 0
desktop/core/src/desktop/management/commands/is_db_alive.py

@@ -93,6 +93,7 @@ class Command(NoArgsCommand):
       error = str(e)
 
       # Oracle
+      # Note: we catch missing Oracle_cx module in manage_entry.py
       if 'ORA-12545' in error: # Connect failed because target host or object does not exist
         sys.exit(5)
       elif 'ORA-12541' in error: # TNS:no listener