浏览代码

HUE-8017 [core] Check config error on hue.ini validation check

Roohi 7 年之前
父节点
当前提交
a0ba2a1c91

+ 7 - 6
desktop/core/src/desktop/lib/config_spec_dump.py

@@ -16,7 +16,7 @@
 # limitations under the License.
 import desktop.appmanager
 
-from desktop.lib.conf import BoundContainer, is_anonymous
+from desktop.lib.conf import BoundContainer, UnspecifiedConfigSection, is_anonymous
 
 class ConfigSpec():
   def __init__(self, configspec):
@@ -35,8 +35,6 @@ class ConfigSpec():
     if isinstance(config_obj, BoundContainer):
       if is_anonymous(config_obj.config.key):
         key = "__many__"
-        if 'notebook.interpreters.' in config_obj.prefix:
-          key = config_obj.prefix.split('notebook.interpreters.')[1]
       else:
         key = config_obj.config.key
       if self.level != 0:
@@ -48,10 +46,13 @@ class ConfigSpec():
         if isinstance(v, BoundContainer):
           sections.append(v)
         else:
-          self.p("%s=%s" % (v.config.key, v.get()))
+          self.p("%s=" % (v.config.key))
 
-      for sec in sections:
-        self.recurse(sec)
+      if isinstance(config_obj.config, UnspecifiedConfigSection) and sections:
+        self.recurse(sections[0])
+      else:
+        for sec in sections:
+          self.recurse(sec)
 
       self.indent -= 2
       self.level -= 1

+ 8 - 2
desktop/core/src/desktop/tests.py

@@ -57,6 +57,8 @@ from desktop.lib.paginator import Paginator
 from desktop.lib.conf import validate_path
 from desktop.lib.django_util import TruncatingModel
 from desktop.lib.exceptions_renderable import PopupException
+from desktop.lib.conf import _configs_from_dir
+from desktop.lib.paths import get_desktop_root
 from desktop.lib.test_utils import grant_access
 from desktop.models import Directory, Document, Document2, get_data_link, _version_from_properties, HUE_VERSION,\
   ClusterConfig
@@ -67,6 +69,7 @@ from desktop.auth.backend import rewrite_user
 from dashboard.conf import HAS_SQL_ENABLED
 
 
+
 def setup_test_environment():
   """
   Sets up mako to signal template rendering.
@@ -1391,12 +1394,14 @@ def test_get_dn():
   assert_equal(['.hue.com'], desktop.conf.get_dn('finance.sql.hue.com'))
   assert_equal(['.hue.com'], desktop.conf.get_dn('bank.finance.sql.hue.com'))
 
+
 def test_collect_validation_messages_default():
   try:
     # Generate the spec file
     configspec = generate_configspec()
     # Load the .ini files
-    conf = load_confs(configspec.name)
+    config_dir = os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))
+    conf = load_confs(configspec.name, _configs_from_dir(config_dir))
     # This is for the hue.ini file only
     error_list = []
     collect_validation_messages(conf, error_list)
@@ -1409,7 +1414,8 @@ def test_collect_validation_messages_extras():
     # Generate the spec file
     configspec = generate_configspec()
     # Load the .ini files
-    conf = load_confs(configspec.name)
+    config_dir = os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))
+    conf = load_confs(configspec.name, _configs_from_dir(config_dir))
 
     test_conf = ConfigObj()
     test_conf['extrasection'] = {

+ 25 - 5
desktop/core/src/desktop/views.py

@@ -621,16 +621,25 @@ def validate_by_spec(error_list):
   try:
     # Generate the spec file
     configspec = generate_configspec()
+    config_dir = os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))
     # Load the .ini files
-    conf = load_confs(configspec.name)
+    conf = load_confs(configspec.name, _configs_from_dir(config_dir))
     # Validate after merging all the confs
     collect_validation_messages(conf, error_list)
   finally:
     os.remove(configspec.name)
 
+def load_confs(configspecpath, conf_source=None):
+  """Loads and merges all of the configurations passed in,
+  returning a ConfigObj for the result.
+
+  @param conf_source if not specified, reads conf/ from
+                     desktop/conf/. Otherwise should be a generator
+                     of ConfigObjs
+  """
+  if conf_source is None:
+    conf_source = _configs_from_dir(get_desktop_root("conf"))
 
-def load_confs(configspecpath):
-  conf_source = _configs_from_dir(get_desktop_root("conf"))
   conf = ConfigObj(configspec=configspecpath)
   for in_conf in conf_source:
     conf.merge(in_conf)
@@ -648,7 +657,18 @@ def collect_validation_messages(conf, error_list):
   validator = validate.Validator()
   conf.validate(validator, preserve_errors=True)
   message = []
-  for sections, name in get_extra_values(conf):
+  cm_extras = {
+    'hadoop_hdfs_home': [('hadoop', 'hdfs_clusters', 'default')],
+    'hadoop_bin': [('hadoop', 'hdfs_clusters', 'default'), ('hadoop', 'yarn_clusters', 'default')],
+    'hadoop_mapred_home': [('hadoop', 'yarn_clusters', 'default')],
+    'hadoop_conf_dir': [('hadoop', 'yarn_clusters', 'default')],
+    'ssl_cacerts': [('beeswax', 'ssl'), ('impala', 'ssl')],
+    'remote_data_dir': [('liboozie', )],
+    'shell': [()]
+  }
+  whitelist_extras = ((sections, name) for sections, name in get_extra_values(conf) if not (name in desktop.conf.APP_BLACKLIST.get() or (name in cm_extras.keys() and sections in cm_extras[name])))
+
+  for sections, name in whitelist_extras:
     the_section = conf
     hierarchy_sections_string = ''
     try:
@@ -676,7 +696,7 @@ def collect_validation_messages(conf, error_list):
     message.append('Extra %s, %s in the section: %s' % (section_or_value, name, section_string))
   if message:
     error = {
-      'name': 'Desktop',
+      'name': 'ini configuration',
       'message': ', '.join(message),
     }
     error_list.append(error)