ソースを参照

[desktop] Change hadoop and oozie to use global ssl validate default

Erick Tryzelaar 10 年 前
コミット
7906224634

+ 3 - 2
desktop/libs/hadoop/src/hadoop/conf.py

@@ -17,6 +17,7 @@
 
 from django.utils.translation import ugettext_lazy as _t
 from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool
+from desktop.conf import default_ssl_validate
 import fnmatch
 import logging
 import os
@@ -71,7 +72,7 @@ HDFS_CLUSTERS = UnspecifiedConfigSection(
                               default=False, type=coerce_bool),
       SSL_CERT_CA_VERIFY=Config("ssl_cert_ca_verify",
                   help="In secure mode (HTTPS), if SSL certificates from YARN Rest APIs have to be verified against certificate authority",
-                  default=True,
+                  dynamic_default=default_ssl_validate,
                   type=coerce_bool),
       TEMP_DIR=Config("temp_dir", help="HDFS directory for temporary files",
                       default='/tmp', type=str),
@@ -146,7 +147,7 @@ YARN_CLUSTERS = UnspecifiedConfigSection(
                   help="URL of the HistoryServer API"),
       SSL_CERT_CA_VERIFY=Config("ssl_cert_ca_verify",
                   help="In secure mode (HTTPS), if SSL certificates from YARN Rest APIs have to be verified against certificate authority",
-                  default=True,
+                  dynamic_default=default_ssl_validate,
                   type=coerce_bool)
     )
   )

+ 55 - 0
desktop/libs/hadoop/src/hadoop/tests.py

@@ -22,6 +22,7 @@ from nose.tools import assert_true, assert_equal, assert_false
 from nose.plugins.attrib import attr
 from nose.plugins.skip import SkipTest
 
+import desktop.conf as desktop_conf
 from desktop.lib.django_test_util import make_logged_in_client
 from hadoop import cluster
 from hadoop import conf
@@ -175,3 +176,57 @@ def test_non_default_cluster():
     for old_conf in reset:
       old_conf()
     cluster.restore_caches(old)
+
+
+def test_hdfs_ssl_validate():
+  for desktop_kwargs, conf_kwargs, expected in [
+      ({'present': False}, {'present': False}, True),
+      ({'present': False}, {'data': False}, False),
+      ({'present': False}, {'data': True}, True),
+
+      ({'data': False}, {'present': False}, False),
+      ({'data': False}, {'data': False}, False),
+      ({'data': False}, {'data': True}, True),
+
+      ({'data': True}, {'present': False}, True),
+      ({'data': True}, {'data': False}, False),
+      ({'data': True}, {'data': True}, True),
+      ]:
+    resets = [
+      desktop_conf.SSL_VALIDATE.set_for_testing(**desktop_kwargs),
+      conf.HDFS_CLUSTERS['default'].SSL_CERT_CA_VERIFY.set_for_testing(**conf_kwargs),
+    ]
+
+    try:
+      assert_equal(conf.HDFS_CLUSTERS['default'].SSL_CERT_CA_VERIFY.get(), expected,
+          'desktop:%s conf:%s expected:%s got:%s' % (desktop_kwargs, conf_kwargs, expected, conf.HDFS_CLUSTERS['default'].SSL_CERT_CA_VERIFY.get()))
+    finally:
+      for reset in resets:
+        reset()
+
+
+def test_yarn_ssl_validate():
+  for desktop_kwargs, conf_kwargs, expected in [
+      ({'present': False}, {'present': False}, True),
+      ({'present': False}, {'data': False}, False),
+      ({'present': False}, {'data': True}, True),
+
+      ({'data': False}, {'present': False}, False),
+      ({'data': False}, {'data': False}, False),
+      ({'data': False}, {'data': True}, True),
+
+      ({'data': True}, {'present': False}, True),
+      ({'data': True}, {'data': False}, False),
+      ({'data': True}, {'data': True}, True),
+      ]:
+    resets = [
+      desktop_conf.SSL_VALIDATE.set_for_testing(**desktop_kwargs),
+      conf.YARN_CLUSTERS['default'].SSL_CERT_CA_VERIFY.set_for_testing(**conf_kwargs),
+    ]
+
+    try:
+      assert_equal(conf.YARN_CLUSTERS['default'].SSL_CERT_CA_VERIFY.get(), expected,
+          'desktop:%s conf:%s expected:%s got:%s' % (desktop_kwargs, conf_kwargs, expected, conf.YARN_CLUSTERS['default'].SSL_CERT_CA_VERIFY.get()))
+    finally:
+      for reset in resets:
+        reset()

+ 2 - 1
desktop/libs/liboozie/src/liboozie/conf.py

@@ -20,6 +20,7 @@ import sys
 
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
+from desktop.conf import default_ssl_validate
 from desktop.lib.conf import Config, coerce_bool, validate_path
 
 LOG = logging.getLogger(__name__)
@@ -46,7 +47,7 @@ REMOTE_DEPLOYMENT_DIR = Config(
 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",
-  default=True,
+  dynamic_default=default_ssl_validate,
   type=coerce_bool)
 
 

+ 30 - 0
desktop/libs/liboozie/src/liboozie/tests.py

@@ -20,8 +20,10 @@ import logging
 from django.contrib.auth.models import User
 from nose.tools import assert_equal
 
+import desktop.conf as desktop_conf
 from desktop.lib.test_utils import reformat_xml
 
+from liboozie import conf
 from liboozie.types import WorkflowAction, Coordinator
 from liboozie.utils import config_gen
 from oozie.tests import MockOozieApi
@@ -72,3 +74,31 @@ def test_config_gen():
   <value><![CDATA[hue]]></value>
 </property>
 </configuration>"""), reformat_xml(config_gen(properties)))
+
+
+
+def test_ssl_validate():
+  for desktop_kwargs, conf_kwargs, expected in [
+      ({'present': False}, {'present': False}, True),
+      ({'present': False}, {'data': False}, False),
+      ({'present': False}, {'data': True}, True),
+
+      ({'data': False}, {'present': False}, False),
+      ({'data': False}, {'data': False}, False),
+      ({'data': False}, {'data': True}, True),
+
+      ({'data': True}, {'present': False}, True),
+      ({'data': True}, {'data': False}, False),
+      ({'data': True}, {'data': True}, True),
+      ]:
+    resets = [
+      desktop_conf.SSL_VALIDATE.set_for_testing(**desktop_kwargs),
+      conf.SSL_CERT_CA_VERIFY.set_for_testing(**conf_kwargs),
+    ]
+
+    try:
+      assert_equal(conf.SSL_CERT_CA_VERIFY.get(), expected,
+          'desktop:%s conf:%s expected:%s got:%s' % (desktop_kwargs, conf_kwargs, expected, conf.SSL_CERT_CA_VERIFY.get()))
+    finally:
+      for reset in resets:
+        reset()