AMBARI-5302. Ambari Unit Test Failures (aonishuk)
diff --git a/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py b/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
index 483b940..d8349ef 100644
--- a/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
+++ b/ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py
@@ -21,7 +21,6 @@
import json
import logging
import os
-import LiveStatus
logger = logging.getLogger()
@@ -49,7 +48,8 @@
self.write_file(filename, tags)
def write_client_components(self, serviceName, tags):
- for comp in LiveStatus.LiveStatus.CLIENT_COMPONENTS:
+ from LiveStatus import LiveStatus
+ for comp in LiveStatus.CLIENT_COMPONENTS:
if comp['serviceName'] == serviceName:
componentName = comp['componentName']
if componentName in self.configTags and \
diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py b/ambari-agent/src/main/python/ambari_agent/FileCache.py
index 6b307f1..740e820 100644
--- a/ambari-agent/src/main/python/ambari_agent/FileCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py
@@ -229,7 +229,8 @@
if not os.path.isdir(concrete_dir):
os.makedirs(concrete_dir)
logger.debug("Unpacking file {0} to {1}".format(name, concrete_dir))
- zfile.extract(name, target_directory)
+ if filename!='':
+ zfile.extract(name, target_directory)
except Exception, err:
raise CachingException("Can not unpack zip file to "
"directory {0} : {1}".format(
diff --git a/ambari-agent/src/main/python/resource_management/core/shell.py b/ambari-agent/src/main/python/resource_management/core/shell.py
index 63547e6..e6644f4 100644
--- a/ambari-agent/src/main/python/resource_management/core/shell.py
+++ b/ambari-agent/src/main/python/resource_management/core/shell.py
@@ -20,9 +20,9 @@
"""
-__all__ = ["checked_call", "call"]
+__all__ = ["checked_call", "call", "quote_bash_args"]
-import pipes
+import string
import subprocess
import threading
from multiprocessing import Queue
@@ -52,7 +52,7 @@
"""
# convert to string and escape
if isinstance(command, (list, tuple)):
- command = ' '.join(pipes.quote(x) for x in command)
+ command = ' '.join(quote_bash_args(x) for x in command)
if user:
command = ["su", "-", user, "-c", command]
@@ -97,4 +97,13 @@
try:
proc.terminate()
except:
- pass
\ No newline at end of file
+ pass
+
+def quote_bash_args(command):
+ if not command:
+ return "''"
+ valid = set(string.ascii_letters + string.digits + '@%_-+=:,./')
+ for char in command:
+ if char not in valid:
+ return "'" + command.replace("'", "'\"'\"'") + "'"
+ return command
\ No newline at end of file
diff --git a/ambari-agent/src/main/python/resource_management/libraries/functions/format.py b/ambari-agent/src/main/python/resource_management/libraries/functions/format.py
index 85a638e..efbacd7 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/functions/format.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/functions/format.py
@@ -22,12 +22,12 @@
__all__ = ["format"]
import sys
-import pipes
from string import Formatter
from resource_management.core.exceptions import Fail
from resource_management.core.utils import checked_unite
from resource_management.core.environment import Environment
from resource_management.core.logger import Logger
+from resource_management.core.shell import quote_bash_args
class ConfigurationFormatter(Formatter):
@@ -66,15 +66,15 @@
def _convert_field(self, value, conversion, is_protected):
if conversion == 'e':
- return pipes.quote(str(value))
+ return quote_bash_args(str(value))
elif conversion == 'h':
return "[PROTECTED]" if is_protected else value
elif conversion == 'p':
return "[PROTECTED]" if is_protected else self._convert_field(value, 'e', is_protected)
return super(ConfigurationFormatter, self).convert_field(value, conversion)
-
-
+
+
def format(format_string, *args, **kwargs):
variables = sys._getframe(1).f_locals
diff --git a/ambari-agent/src/main/python/resource_management/libraries/providers/execute_hadoop.py b/ambari-agent/src/main/python/resource_management/libraries/providers/execute_hadoop.py
index 5a159da..8ab71ff 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/providers/execute_hadoop.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/providers/execute_hadoop.py
@@ -20,7 +20,6 @@
"""
-import pipes
from resource_management import *
class ExecuteHadoopProvider(Provider):
@@ -32,7 +31,7 @@
principal = self.resource.principal
if isinstance(command, (list, tuple)):
- command = ' '.join(pipes.quote(x) for x in command)
+ command = ' '.join(quote_bash_args(x) for x in command)
with Environment.get_instance_copy() as env:
if self.resource.security_enabled and not self.resource.kinit_override: