Browse Source

HUE-9125 [liboozie] Avoid Error in config validation by liboozie

When No oozie app but Oozie URL specified.
Romain 5 years ago
parent
commit
0439fdba9a

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

@@ -19,8 +19,7 @@
 from __future__ import absolute_import
 from future import standard_library
 standard_library.install_aliases()
-from builtins import range
-from builtins import object
+from builtins import range, object
 import json
 import logging
 import os

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

@@ -253,7 +253,9 @@ def bootstrap(request):
   """Concatenates bootstrap.js files from all installed Hue apps."""
 
   # Has some None's for apps that don't have bootsraps.
-  all_bootstraps = [(app, app.get_bootstrap_file()) for app in appmanager.DESKTOP_APPS if request.user.has_hue_permission(action="access", app=app.name)]
+  all_bootstraps = [
+    (app, app.get_bootstrap_file()) for app in appmanager.DESKTOP_APPS if request.user.has_hue_permission(action="access", app=app.name)
+  ]
 
   # Iterator over the streams.
   concatenated = ["\n/* %s */\n%s" % (app.name, b.read()) for app, b in all_bootstraps if b is not None]
@@ -455,9 +457,11 @@ def log_frontend_event(request):
   _LOG_FRONTEND_LOGGER.log(level, msg)
   return HttpResponse("")
 
+
 def commonheader_m(title, section, user, request=None, padding="90px", skip_topbar=False, skip_idle_timeout=False):
   return commonheader(title, section, user, request, padding, skip_topbar, skip_idle_timeout, True)
 
+
 def commonheader(title, section, user, request=None, padding="90px", skip_topbar=False, skip_idle_timeout=False, is_mobile=False):
   """
   Returns the rendered common header

+ 38 - 17
desktop/libs/liboozie/src/liboozie/conf.py

@@ -15,16 +15,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from builtins import oct
-from builtins import object
+from builtins import oct, object
 import logging
 import sys
 
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
+from desktop import appmanager
 from desktop.conf import default_ssl_validate
 from desktop.lib.conf import Config, coerce_bool, validate_path
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -32,32 +33,41 @@ OOZIE_URL = Config(
   key='oozie_url',
   help=_t('URL of Oozie server. This is required for job submission. Empty value disables the config check.'),
   default='http://localhost:11000/oozie',
-  type=str)
+  type=str
+)
 
 SECURITY_ENABLED = Config(
   key="security_enabled",
   help=_t("Whether Oozie requires client to perform Kerberos authentication."),
   default=False,
-  type=coerce_bool)
+  type=coerce_bool
+)
 
 REMOTE_DEPLOYMENT_DIR = Config(
   key="remote_deployement_dir",
   default="/user/hue/oozie/deployments/_$USER_-oozie-$JOBID-$TIME",
-  help=_t("Location on HDFS where the workflows/coordinators are deployed when submitted by a non-owner."
-          " Parameters are $TIME, $USER and $JOBID, e.g. /user/$USER/hue/deployments/$JOBID-$TIME"))
+  help=_t(
+    "Location on HDFS where the workflows/coordinators are deployed when submitted by a non-owner."
+    " Parameters are $TIME, $USER and $JOBID, e.g. /user/$USER/hue/deployments/$JOBID-$TIME"
+  )
+)
 
 SSL_CERT_CA_VERIFY=Config(
   key="ssl_cert_ca_verify",
   help="In secure mode (HTTPS), if SSL certificates from Oozie Rest APIs have to be verified against certificate authority",
   dynamic_default=default_ssl_validate,
-  type=coerce_bool)
+  type=coerce_bool
+)
 
 USE_LIBPATH_FOR_JARS = Config(
   key="use_libpath_for_jars",
-  help=_t("Whether Hue append jar paths to the oozie.libpath instead of copying them into the workspace."
-          " This makes submissions faster and less prone to HDFS permission errors"),
+  help=_t(
+    "Whether Hue append jar paths to the oozie.libpath instead of copying them into the workspace."
+    " This makes submissions faster and less prone to HDFS permission errors"
+  ),
   default=False,
-  type=coerce_bool)
+  type=coerce_bool
+)
 
 
 def get_oozie_status(user):
@@ -66,7 +76,7 @@ def get_oozie_status(user):
   status = 'down'
 
   try:
-    if not 'test' in sys.argv: # Avoid tests hanging
+    if not 'test' in sys.argv:  # Avoid tests hanging
       status = str(get_oozie(user).get_oozie_status())
   except:
     LOG.exception('failed to get oozie status')
@@ -93,13 +103,19 @@ def config_validator(user):
     LOG.warn('Config check failed because Oozie app not installed: %s' % e)
     return res
 
+  apps = appmanager.get_apps_dict(user)
+
+  if 'oozie' not in apps:
+    return res
+
   if OOZIE_URL.get():
     status = get_oozie_status(user)
     if 'NORMAL' not in status:
       res.append((status, _('The Oozie server is not available')))
+
     fs = get_filesystem()
-    NICE_NAME = 'Oozie'
-    if fs.do_as_superuser(fs.exists, REMOTE_SAMPLE_DIR.get()):
+
+    if fs and fs.do_as_superuser(fs.exists, REMOTE_SAMPLE_DIR.get()):
       stats = fs.do_as_superuser(fs.stats, REMOTE_SAMPLE_DIR.get())
       mode = oct(stats.mode)
       # if neither group nor others have write permission
@@ -107,7 +123,7 @@ def config_validator(user):
       others_has_write = int(mode[-1]) & 2
 
       if not group_has_write and not others_has_write:
-        res.append((NICE_NAME, "The permissions of workspace '%s' are too restrictive" % REMOTE_SAMPLE_DIR.get()))
+        res.append(('Oozie', "The permissions of workspace '%s' are too restrictive" % REMOTE_SAMPLE_DIR.get()))
 
     api = get_oozie(user, api_version="v2")
 
@@ -117,7 +133,9 @@ def config_validator(user):
       sharelib_url = 'gauges' in metrics and 'libs.sharelib.system.libpath' in metrics['gauges'] and [metrics['gauges']['libs.sharelib.system.libpath']['value']] or []
     else:
       intrumentation = api.get_instrumentation()
-      sharelib_url = [param['value'] for group in intrumentation['variables'] for param in group['data'] if param['name'] == 'sharelib.system.libpath']
+      sharelib_url = [
+        param['value'] for group in intrumentation['variables'] for param in group['data'] if param['name'] == 'sharelib.system.libpath'
+      ]
 
     if sharelib_url:
       sharelib_url = Hdfs.urlsplit(sharelib_url[0])[2]
@@ -131,7 +149,10 @@ def config_validator(user):
       def get_fully_qualifying_key(self): return self.value
 
     for cluster in list(get_all_hdfs().values()):
-      res.extend(validate_path(ConfigMock(sharelib_url), is_dir=True, fs=cluster,
-                               message=_('Oozie Share Lib not installed in default location.')))
+      res.extend(
+        validate_path(
+          ConfigMock(sharelib_url), is_dir=True, fs=cluster, message=_('Oozie Share Lib not installed in default location.')
+        )
+      )
 
   return res

+ 49 - 0
desktop/libs/liboozie/src/liboozie/conf_tests.py

@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 sys
+
+from nose.tools import assert_true, assert_false, assert_equal
+
+from useradmin.models import User
+from desktop.lib.django_test_util import make_logged_in_client
+
+from liboozie.conf import config_validator
+
+
+if sys.version_info[0] > 2:
+  from unittest.mock import patch, Mock
+else:
+  from mock import patch, Mock
+
+
+class TestGetConfigErrors():
+
+  def setUp(self):
+    self.client = make_logged_in_client(username="test", groupname="empty", recreate=True, is_superuser=False)
+    self.user = User.objects.get(username="test")
+
+  def test_check_config_oozie_disabled(self):
+    with patch('liboozie.conf.appmanager') as appmanager:
+      with patch('liboozie.conf.OOZIE_URL.get') as OOZIE_URL_get:
+        appmanager.get_apps_dict.return_value = []  # No oozie app but Oozie URL specified.
+        OOZIE_URL_get.return_value = 'http://localhost:11000/oozie'
+
+        assert_equal(
+          [],
+          config_validator(self.user)
+        )