Repository: incubator-impala
Updated Branches:
  refs/heads/master 541180105 -> 7db2d3064


IMPALA-5455: test infra: default --cm-port based on --use-tls

This patch sets the default --cm-port (for the CM ApiResource
initialization) based on a new flag, --use-tls, which enables test infra
to talk to CM clusters with TLS enabled. It is still possible to set a
port override, but in general it will not be needed.

Reference:

https://cloudera.github.io/cm_api/epydoc/5.4.0/cm_api.api_client.ApiResource-class.html#__init__

Testing:

Connected both to TLS-disabled and TLS-enabled CM instances. Before this
patch, we would fail hard when trying to talk to the TLS-enabled CM
instance.

Change-Id: Ie7dfa6c400687f3c5ccaf578fd4fb17dedd6eded
Reviewed-on: http://gerrit.cloudera.org:8080/7107
Reviewed-by: Matthew Jacobs <[email protected]>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/48829102
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/48829102
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/48829102

Branch: refs/heads/master
Commit: 488291022688e750342a3d8a775d2184e98b5822
Parents: 5411801
Author: Michael Brown <[email protected]>
Authored: Mon Jun 5 12:40:20 2017 -0700
Committer: Impala Public Jenkins <[email protected]>
Committed: Thu Jun 8 05:49:37 2017 +0000

----------------------------------------------------------------------
 tests/comparison/cli_options.py | 19 +++++++++++++++----
 tests/comparison/cluster.py     | 19 ++++++++++++++++---
 2 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48829102/tests/comparison/cli_options.py
----------------------------------------------------------------------
diff --git a/tests/comparison/cli_options.py b/tests/comparison/cli_options.py
index ca2efc6..91dd0ce 100644
--- a/tests/comparison/cli_options.py
+++ b/tests/comparison/cli_options.py
@@ -30,6 +30,8 @@ from tests.comparison.cluster import (
     DEFAULT_HIVE_PASSWORD,
     DEFAULT_HIVE_PORT,
     DEFAULT_HIVE_USER,
+    CM_CLEAR_PORT,
+    CM_TLS_PORT,
     MiniCluster,
     MiniHiveCluster,
 )
@@ -142,9 +144,14 @@ def add_cm_options(parser):
   parser.add_argument(
       '--cm-host', metavar='host name',
       help='The host name of the CM server.')
+  # IMPALA-5455: --cm-port defaults to None so that --use-tls can later 
influence the
+  # default value of --cm-port: it needs to default to 7180, or 7183 if 
--use-tls is
+  # included.
   parser.add_argument(
-      '--cm-port', default=7180, type=int, metavar='port number',
-      help='The port of the CM server.')
+      '--cm-port', default=None, type=int, metavar='port number',
+      help='Override the CM port. Defaults to {clear}, or {tls} with 
--use-tls'.format(
+          clear=CM_CLEAR_PORT,
+          tls=CM_TLS_PORT))
   parser.add_argument(
       '--cm-user', default="admin", metavar='user name',
       help='The name of the CM user.')
@@ -154,6 +161,10 @@ def add_cm_options(parser):
   parser.add_argument(
       '--cm-cluster-name', metavar='name',
       help='If CM manages multiple clusters, use this to specify which cluster 
to use.')
+  parser.add_argument(
+      '--use-tls', action='store_true', default=False,
+      help='Whether to communicate with CM using TLS. This alters the default 
CM port '
+           'from {clear} to {tls}'.format(clear=CM_CLEAR_PORT, 
tls=CM_TLS_PORT))
 
 
 def add_ssl_options(parser):
@@ -166,9 +177,9 @@ def add_ssl_options(parser):
 def create_cluster(args):
   if args.cm_host:
     cluster = CmCluster(
-        args.cm_host, user=args.cm_user, password=args.cm_password,
+        args.cm_host, port=args.cm_port, user=args.cm_user, 
password=args.cm_password,
         cluster_name=args.cm_cluster_name, ssh_user=args.ssh_user, 
ssh_port=args.ssh_port,
-        ssh_key_file=args.ssh_key_file)
+        ssh_key_file=args.ssh_key_file, use_tls=args.use_tls)
   elif args.use_hive:
     cluster = MiniHiveCluster(args.hive_host, args.hive_port)
   else:

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48829102/tests/comparison/cluster.py
----------------------------------------------------------------------
diff --git a/tests/comparison/cluster.py b/tests/comparison/cluster.py
index 87a4009..e0328b0 100644
--- a/tests/comparison/cluster.py
+++ b/tests/comparison/cluster.py
@@ -60,6 +60,10 @@ DEFAULT_HIVE_PASSWORD = 'hive'
 
 DEFAULT_TIMEOUT = 300
 
+CM_CLEAR_PORT = 7180
+CM_TLS_PORT = 7183
+
+
 class Cluster(object):
   """This is a base class for clusters. Cluster classes provide various 
methods for
      interacting with a cluster. Ideally the various cluster implementations 
provide
@@ -231,16 +235,25 @@ class MiniHiveCluster(MiniCluster):
   def _get_other_conf_dir(self):
     return os.environ["HIVE_CONF_DIR"]
 
+
 class CmCluster(Cluster):
 
-  def __init__(self, host_name, port=7180, user="admin", password="admin",
-      cluster_name=None, ssh_user=None, ssh_port=None, ssh_key_file=None):
+  def __init__(self, host_name, port=None, user="admin", password="admin",
+               cluster_name=None, ssh_user=None, ssh_port=None, 
ssh_key_file=None,
+               use_tls=False):
     # Initialize strptime() to workaround https://bugs.python.org/issue7980. 
Apparently
     # something in the CM API uses strptime().
     strptime("2015", "%Y")
 
     Cluster.__init__(self)
-    self.cm = CmApiResource(host_name, server_port=port, username=user, 
password=password)
+    # IMPALA-5455: If the caller doesn't specify port, default it based on 
use_tls
+    if port is None:
+      if use_tls:
+        port = CM_TLS_PORT
+      else:
+        port = CM_CLEAR_PORT
+    self.cm = CmApiResource(host_name, server_port=port, username=user, 
password=password,
+                            use_tls=use_tls)
     clusters = self.cm.get_all_clusters()
     if not clusters:
       raise Exception("No clusters found in CM at %s" % host_name)

Reply via email to