You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ja...@apache.org on 2014/12/04 21:42:44 UTC
ambari git commit: AMBARI-8436. Kerberos wizard: Test kerberos
command fails when no credentials specified for test user (Robert Levas via
Jaimin)
Repository: ambari
Updated Branches:
refs/heads/trunk 53013484a -> 772f7b48b
AMBARI-8436. Kerberos wizard: Test kerberos command fails when no credentials specified for test user (Robert Levas via Jaimin)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/772f7b48
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/772f7b48
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/772f7b48
Branch: refs/heads/trunk
Commit: 772f7b48b9bb5bff5159a5d87d140f5d28360ea0
Parents: 5301348
Author: Jaimin Jetly <ja...@hortonworks.com>
Authored: Thu Dec 4 12:42:18 2014 -0800
Committer: Jaimin Jetly <ja...@hortonworks.com>
Committed: Thu Dec 4 12:42:18 2014 -0800
----------------------------------------------------------------------
.../services/KERBEROS/package/scripts/params.py | 38 ++++++---------
.../KERBEROS/package/scripts/service_check.py | 2 +
.../services/KERBEROS/package/scripts/utils.py | 42 ++++++++++++++--
.../stacks/2.2/KERBEROS/test_kerberos_client.py | 50 ++++++++++++++++++++
4 files changed, 105 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/772f7b48/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/params.py
index cff6250..fdc1ba0 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/params.py
@@ -70,8 +70,8 @@ if config is not None:
cluster_env = get_property_value(configurations, 'cluster-env')
if cluster_env is not None:
- smoke_test_principal = get_property_value(cluster_env, 'smokeuser')
- smoke_test_keytab_file = get_property_value(cluster_env, 'smokeuser_keytab')
+ smoke_test_principal = get_property_value(cluster_env, 'smokeuser', None, True, None)
+ smoke_test_keytab_file = get_property_value(cluster_env, 'smokeuser_keytab', None, True, None)
default_group = get_property_value(cluster_env, 'user_group')
@@ -145,28 +145,18 @@ if config is not None:
kdc_host = get_property_value(krb5_conf_data, 'kdc_host', kdc_host)
admin_server_host = get_property_value(krb5_conf_data, 'admin_server_host', admin_server_host)
- admin_principal = get_property_value(krb5_conf_data, 'admin_principal', admin_principal)
- admin_password = get_property_value(krb5_conf_data, 'admin_password', admin_password)
- admin_keytab = get_property_value(krb5_conf_data, 'admin_keytab', admin_keytab)
-
- # If the admin keytab is just white space, set it to None
- if admin_keytab is not None:
- admin_keytab = admin_keytab.strip()
-
- if len(admin_keytab) == 0:
- admin_keytab = None
-
- test_principal = get_property_value(krb5_conf_data, 'test_principal', test_principal)
- test_password = get_property_value(krb5_conf_data, 'test_password', test_password)
- test_keytab = get_property_value(krb5_conf_data, 'test_keytab', test_keytab)
- test_keytab_file = get_property_value(krb5_conf_data, 'test_keytab_file', test_keytab_file)
-
- # If the test keytab is just white space, set it to None
- if test_keytab is not None:
- test_keytab = test_keytab.strip()
-
- if len(test_keytab) == 0:
- test_keytab = None
+ admin_principal = get_property_value(krb5_conf_data, 'admin_principal', admin_principal, True,
+ None)
+ admin_password = get_property_value(krb5_conf_data, 'admin_password', admin_password, True,
+ None)
+ admin_keytab = get_property_value(krb5_conf_data, 'admin_keytab', admin_keytab, True, None)
+
+ test_principal = get_property_value(krb5_conf_data, 'test_principal', test_principal, True,
+ None)
+ test_password = get_property_value(krb5_conf_data, 'test_password', test_password, True, None)
+ test_keytab = get_property_value(krb5_conf_data, 'test_keytab', test_keytab, True, None)
+ test_keytab_file = get_property_value(krb5_conf_data, 'test_keytab_file', test_keytab_file,
+ True, None)
krb5_conf_template = get_property_value(krb5_conf_data, 'content', krb5_conf_template)
krb5_conf_dir = get_property_value(krb5_conf_data, 'conf_dir', krb5_conf_dir)
http://git-wip-us.apache.org/repos/asf/ambari/blob/772f7b48/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/service_check.py b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/service_check.py
index 73b9c7a..13d4975 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/service_check.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/service_check.py
@@ -58,6 +58,8 @@ class KerberosServiceCheck(KerberosScript):
print "Test executed successfully."
else:
print "Test failed with error code %d: %s." % (code, out)
+ else:
+ print "Test not performed - no test principal was available"
if __name__ == "__main__":
KerberosServiceCheck().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/772f7b48/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/utils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/utils.py b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/utils.py
index 79e89e6..199e6d7 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/utils.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/services/KERBEROS/package/scripts/utils.py
@@ -17,8 +17,44 @@ limitations under the License.
"""
-def get_property_value(dictionary, property_name, null_value=None):
- return dictionary[property_name] if property_name in dictionary else null_value
+def get_property_value(dictionary, property_name, default_value=None, trim_string=False,
+ empty_value=""):
+ """
+ Get a property value from a dictionary, applying applying rules as necessary.
+
+ If dictionary does not contain a value for property_name or the value for property_name is None,
+ null_value is used as the value to return. Then, if trim_string is True and the value is None
+ or the value is an empty string, empty_value will be return else the (current) value is returned.
+
+ Note: the property value will most likely be a string or a unicode string, however in the event
+ it is not (for example a number), this method will behave properly and return the value as is.
+
+ :param dictionary: a dictionary of values
+ :param property_name: the name of a dictionary item to retrieve
+ :param default_value: the value to use if the item is not in the dictionary or the value of the item is None
+ :param trim_string: a Boolean value indicating whether to strip whitespace from the value (True) or not (False)
+ :param empty_value: the value to use if the (current) value is None or an empty string, if trim_string is True
+ :return: the requested property value with rules applied
+ """
+ # If property_name is not in the dictionary, set value to null_value
+ if property_name in dictionary:
+ value = dictionary[property_name]
+ if value is None:
+ value = default_value
+ else:
+ value = default_value
+
+ if trim_string:
+ # If the value is none, consider it empty...
+ if value is None:
+ value = empty_value
+ elif (type(value) == str) or (type(value) == unicode):
+ value = value.strip()
+
+ if len(value) == 0:
+ value = empty_value
+
+ return value
def get_unstructured_data(dictionary, property_name):
prefix = property_name + '/'
@@ -29,7 +65,7 @@ def split_host_and_port(host):
"""
Splits a string into its host and port components
- :param host: a string matching the following patern: <host name | ip address>[:port]
+ :param host: a string matching the following pattern: <host name | ip address>[:port]
:return: a Dictionary containing 'host' and 'port' entries for the input value
"""
http://git-wip-us.apache.org/repos/asf/ambari/blob/772f7b48/ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py b/ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py
index 95c357d..6bb29cb 100644
--- a/ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py
+++ b/ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py
@@ -19,6 +19,9 @@ limitations under the License.
import os
import use_cases
+from utils import get_property_value, get_unstructured_data
+
+
from stacks.utils.RMFTestCase import *
@@ -115,3 +118,50 @@ class TestKerberosClient(RMFTestCase):
group='root',
mode=0644)
+
+ def test_get_property(self):
+ d = {
+ 'non_empty' : "Nonempty value",
+ 'unicode_non_empty' : u"Nonempty value",
+ 'number' : 33,
+ 'number_string' : "33",
+ 'empty' : "",
+ 'unicode_empty' : u"",
+ 'whitespace' : " ",
+ 'unicode_whitespace' : u" ",
+ 'none' : None,
+ }
+
+ self.assertEqual('Nonempty value', get_property_value(d, 'non_empty'))
+ self.assertEqual('Nonempty value', get_property_value(d, 'non_empty', None, True, None))
+
+ self.assertEqual('Nonempty value', get_property_value(d, 'unicode_non_empty'))
+ self.assertEqual('Nonempty value', get_property_value(d, 'unicode_non_empty', None, True, None))
+
+ self.assertEqual('33', get_property_value(d, 'number_string'))
+ self.assertEqual('33', get_property_value(d, 'number_string', None, True, None))
+
+ self.assertEqual(33, get_property_value(d, 'number'))
+ self.assertEqual(33, get_property_value(d, 'number', None, True, None))
+
+ self.assertEqual('', get_property_value(d, 'empty'))
+ self.assertEqual("I'm empty", get_property_value(d, 'empty', None, True, "I'm empty"))
+ self.assertEqual('', get_property_value(d, 'empty', None, False, "I'm empty"))
+
+ self.assertEqual('', get_property_value(d, 'unicode_empty'))
+ self.assertEqual("I'm empty", get_property_value(d, 'unicode_empty', None, True, "I'm empty"))
+ self.assertEqual('', get_property_value(d, 'unicode_empty', None, False, "I'm empty"))
+
+ self.assertEqual(" ", get_property_value(d, 'whitespace'))
+ self.assertEqual("I'm empty", get_property_value(d, 'whitespace', None, True, "I'm empty"))
+ self.assertEqual(' ', get_property_value(d, 'whitespace', None, False, "I'm empty"))
+
+ self.assertEqual(" ", get_property_value(d, 'unicode_whitespace'))
+ self.assertEqual("I'm empty", get_property_value(d, 'unicode_whitespace', None, True, "I'm empty"))
+ self.assertEqual(' ', get_property_value(d, 'unicode_whitespace', None, False, "I'm empty"))
+
+ self.assertEqual(None, get_property_value(d, 'none'))
+ self.assertEqual("I'm empty", get_property_value(d, 'none', None, True, "I'm empty"))
+ self.assertEqual(None, get_property_value(d, 'none', None, False, "I'm empty"))
+ self.assertEqual("I'm empty", get_property_value(d, 'none', '', True, "I'm empty"))
+ self.assertEqual("", get_property_value(d, 'none', '', False, "I'm empty"))