Преглед на файлове

AMBARI-5302. Ambari Unit Test Failures (aonishuk)

Andrew Onischuk преди 11 години
родител
ревизия
71e099d292

+ 2 - 2
ambari-agent/src/main/python/ambari_agent/ActualConfigHandler.py

@@ -21,7 +21,6 @@ limitations under the License.
 import json
 import logging
 import os
-import LiveStatus
 
 logger = logging.getLogger()
 
@@ -49,7 +48,8 @@ class ActualConfigHandler:
     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 \

+ 2 - 1
ambari-agent/src/main/python/ambari_agent/FileCache.py

@@ -229,7 +229,8 @@ class FileCache():
         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(

+ 13 - 4
ambari-agent/src/main/python/resource_management/core/shell.py

@@ -20,9 +20,9 @@ Ambari Agent
 
 """
 
-__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 @@ def _call(command, logoutput=False, throw_on_failure=True,
   """
   # 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 @@ def on_timeout(proc, q):
     try:
       proc.terminate()
     except:
-      pass
+      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

+ 4 - 4
ambari-agent/src/main/python/resource_management/libraries/functions/format.py

@@ -22,12 +22,12 @@ Ambari Agent
 
 __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 @@ class ConfigurationFormatter(Formatter):
   
   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
   

+ 1 - 2
ambari-agent/src/main/python/resource_management/libraries/providers/execute_hadoop.py

@@ -20,7 +20,6 @@ Ambari Agent
 
 """
 
-import pipes
 from resource_management import *
 
 class ExecuteHadoopProvider(Provider):
@@ -32,7 +31,7 @@ class ExecuteHadoopProvider(Provider):
     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: