Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B7757188E9 for ; Wed, 4 Nov 2015 13:36:30 +0000 (UTC) Received: (qmail 45821 invoked by uid 500); 4 Nov 2015 13:36:30 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 45771 invoked by uid 500); 4 Nov 2015 13:36:30 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 44157 invoked by uid 99); 4 Nov 2015 13:36:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Nov 2015 13:36:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D5CD6E108C; Wed, 4 Nov 2015 13:36:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ncole@apache.org To: commits@ambari.apache.org Date: Wed, 04 Nov 2015 13:37:02 -0000 Message-Id: <9beb8dc55bc741efb7d719b191d96734@git.apache.org> In-Reply-To: <5f394c0c0c364192b617d0ac827b5427@git.apache.org> References: <5f394c0c0c364192b617d0ac827b5427@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [35/50] [abbrv] ambari git commit: AMBARI-13694 Code to read keysdir cannot handle space in the front (dsen) 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/b5406c59 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b5406c59 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b5406c59 Branch: refs/heads/branch-dev-patch-upgrade Commit: b5406c597f2b7bf83a070fd6f0c69a233a2e1064 Parents: f24058f Author: Dmytro Sen Authored: Tue Nov 3 11:43:59 2015 +0200 Committer: Dmytro Sen Committed: Tue Nov 3 16:54:23 2015 +0200 ---------------------------------------------------------------------- ambari-agent/conf/unix/ambari-agent | 3 ++ .../main/python/ambari_agent/AmbariConfig.py | 4 +- .../test/python/ambari_agent/TestActionQueue.py | 3 -- .../python/ambari_agent/TestAmbariConfig.py | 47 ++++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b5406c59/ambari-agent/conf/unix/ambari-agent ---------------------------------------------------------------------- diff --git a/ambari-agent/conf/unix/ambari-agent b/ambari-agent/conf/unix/ambari-agent index ea59216..c1e7fe7 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/b5406c59/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 03e14ad..2c82ca5 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/b5406c59/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py index a583131..10bfe1a 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py +++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py @@ -24,7 +24,6 @@ from ambari_agent.LiveStatus import LiveStatus from ambari_agent.ActionQueue import ActionQueue from ambari_agent.AmbariConfig import AmbariConfig import os, errno, time, pprint, tempfile, threading -import StringIO import sys from threading import Thread import copy @@ -33,10 +32,8 @@ from mock.mock import patch, MagicMock, call from ambari_agent.StackVersionsFileHandler import StackVersionsFileHandler from ambari_agent.CustomServiceOrchestrator import CustomServiceOrchestrator from ambari_agent.PythonExecutor import PythonExecutor -from ambari_agent.CommandStatusDict import CommandStatusDict from ambari_agent.ActualConfigHandler import ActualConfigHandler from ambari_agent.RecoveryManager import RecoveryManager -from ambari_agent.FileCache import FileCache from ambari_commons import OSCheck from only_for_platform import not_for_platform, os_distro_value, PLATFORM_WINDOWS, PLATFORM_LINUX http://git-wip-us.apache.org/repos/asf/ambari/blob/b5406c59/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") +