ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-13694 Code to read keysdir cannot handle space in the front (dsen)
Date Tue, 03 Nov 2015 15:10:20 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 e2593c3d4 -> a67b1e12d


AMBARI-13694 Code to read keysdir cannot handle space in the front (dsen)


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

Branch: refs/heads/branch-2.1
Commit: a67b1e12d077ba0e3b6d9b190d6c24a9b5e2a271
Parents: e2593c3
Author: Dmytro Sen <dsen@apache.org>
Authored: Tue Nov 3 17:09:11 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Tue Nov 3 17:09:27 2015 +0200

----------------------------------------------------------------------
 ambari-agent/conf/unix/ambari-agent             |  3 ++
 .../main/python/ambari_agent/AmbariConfig.py    |  4 +-
 .../python/ambari_agent/TestAmbariConfig.py     | 47 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a67b1e12/ambari-agent/conf/unix/ambari-agent
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/ambari-agent b/ambari-agent/conf/unix/ambari-agent
index a08ead2..5a78e5f 100755
--- a/ambari-agent/conf/unix/ambari-agent
+++ b/ambari-agent/conf/unix/ambari-agent
@@ -59,6 +59,9 @@ if [ "$EUID" -ne 0 ] ; then
 fi
 
 keysdir=$(awk -F "=" '/keysdir/ {print $2}' /etc/ambari-agent/conf/ambari-agent.ini)
+# trim spaces
+keysdir=${keysdir// }
+keysdir=${keysdir%% }
 
 change_files_permissions() {
     if [ ! -z "$keysdir" ]; then

http://git-wip-us.apache.org/repos/asf/ambari/blob/a67b1e12/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
index f8f220b..8b4a749 100644
--- a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
+++ b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
@@ -140,8 +140,6 @@ pidPathVars = [
 ]
 
 
-
-
 class AmbariConfig:
   TWO_WAY_SSL_PROPERTY = "security.server.two_way_ssl"
   AMBARI_PROPERTIES_CATEGORY = 'agentConfig'
@@ -159,7 +157,7 @@ class AmbariConfig:
 
   def get(self, section, value, default=None):
     try:
-      return self.config.get(section, value)
+      return str(self.config.get(section, value)).strip()
     except ConfigParser.Error, err:
       if default != None:
         return default

http://git-wip-us.apache.org/repos/asf/ambari/blob/a67b1e12/ambari-agent/src/test/python/ambari_agent/TestAmbariConfig.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestAmbariConfig.py b/ambari-agent/src/test/python/ambari_agent/TestAmbariConfig.py
new file mode 100644
index 0000000..78f29fe
--- /dev/null
+++ b/ambari-agent/src/test/python/ambari_agent/TestAmbariConfig.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF 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.
+'''
+
+from unittest import TestCase
+from ambari_agent.AmbariConfig import AmbariConfig
+import sys
+
+import logging
+
+class TestAmbariConfig(TestCase):
+  def setUp(self):
+    # save original open() method for later use
+    self.original_open = open
+
+  def tearDown(self):
+    sys.stdout = sys.__stdout__
+
+  logger = logging.getLogger()
+
+  def test_ambari_config_get(self):
+    config = AmbariConfig()
+    #default
+    self.assertEqual(config.get("security", "keysdir"), "/tmp/ambari-agent")
+    #non-default
+    config.set("security", "keysdir", "/tmp/non-default-path")
+    self.assertEqual(config.get("security", "keysdir"), "/tmp/non-default-path")
+    #whitespace handling
+    config.set("security", "keysdir", " /tmp/non-stripped")
+    self.assertEqual(config.get("security", "keysdir"), "/tmp/non-stripped")
+


Mime
View raw message