ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject [41/51] [partial] AMBARI-7718. Rebase branch-windows-dev against trunk. (Jayush Luniya and Florian Barca via yusaku)
Date Thu, 16 Oct 2014 20:12:05 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
index 23b9bed..721cbe9 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
@@ -18,9 +18,11 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 import ConfigParser
+from multiprocessing.pool import ThreadPool
 import os
 
 import pprint
+import shell
 
 from unittest import TestCase
 import threading
@@ -37,6 +39,8 @@ import sys
 from AgentException import AgentException
 from FileCache import FileCache
 from LiveStatus import LiveStatus
+from BackgroundCommandExecutionHandle import BackgroundCommandExecutionHandle
+from ambari_agent.ActionQueue import ActionQueue
 
 
 class TestCustomServiceOrchestrator(TestCase):
@@ -47,9 +51,11 @@ class TestCustomServiceOrchestrator(TestCase):
     sys.stdout = out
     # generate sample config
     tmpdir = tempfile.gettempdir()
+    exec_tmp_dir = os.path.join(tmpdir, 'tmp')
     self.config = ConfigParser.RawConfigParser()
     self.config.add_section('agent')
     self.config.set('agent', 'prefix', tmpdir)
+    self.config.set('agent', 'tmp_dir', exec_tmp_dir)
     self.config.set('agent', 'cache_dir', "/cachedir")
     self.config.add_section('python')
     self.config.set('python', 'custom_actions_dir', tmpdir)
@@ -183,6 +189,8 @@ class TestCustomServiceOrchestrator(TestCase):
        '/hooks_dir/prefix-command')
     dummy_controller = MagicMock()
     orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
+    unix_process_id = 111
+    orchestrator.commands_in_progress = {command['taskId']: unix_process_id}
     get_hook_base_dir_mock.return_value = "/hooks/"
     # normal run case
     run_file_mock.return_value = {
@@ -206,9 +214,9 @@ class TestCustomServiceOrchestrator(TestCase):
     ret = orchestrator.runCommand(command, "out.txt", "err.txt",
               forced_command_name=CustomServiceOrchestrator.COMMAND_NAME_STATUS)
     ## Check that override_output_files was true only during first call
-    self.assertEquals(run_file_mock.call_args_list[0][0][7], True)
-    self.assertEquals(run_file_mock.call_args_list[1][0][7], False)
-    self.assertEquals(run_file_mock.call_args_list[2][0][7], False)
+    self.assertEquals(run_file_mock.call_args_list[0][0][10], True)
+    self.assertEquals(run_file_mock.call_args_list[1][0][10], False)
+    self.assertEquals(run_file_mock.call_args_list[2][0][10], False)
     ## Check that forced_command_name was taken into account
     self.assertEqual(run_file_mock.call_args_list[0][0][1][0],
                                   CustomServiceOrchestrator.COMMAND_NAME_STATUS)
@@ -227,6 +235,146 @@ class TestCustomServiceOrchestrator(TestCase):
 
     pass
 
+  @patch("shell.kill_process_with_children")
+  @patch.object(CustomServiceOrchestrator, "resolve_script_path")
+  @patch.object(CustomServiceOrchestrator, "resolve_hook_script_path")
+  @patch.object(FileCache, "get_service_base_dir")
+  @patch.object(FileCache, "get_hook_base_dir")
+  @patch.object(CustomServiceOrchestrator, "dump_command_to_json")
+  @patch.object(PythonExecutor, "run_file")
+  @patch.object(FileCache, "__init__")
+  def test_cancel_command(self, FileCache_mock,
+                      run_file_mock, dump_command_to_json_mock,
+                      get_hook_base_dir_mock, get_service_base_dir_mock,
+                      resolve_hook_script_path_mock, resolve_script_path_mock,
+                      kill_process_with_children_mock):
+    FileCache_mock.return_value = None
+    command = {
+      'role' : 'REGION_SERVER',
+      'hostLevelParams' : {
+        'stack_name' : 'HDP',
+        'stack_version' : '2.0.7',
+        'jdk_location' : 'some_location'
+      },
+      'commandParams': {
+        'script_type': 'PYTHON',
+        'script': 'scripts/hbase_regionserver.py',
+        'command_timeout': '600',
+        'service_package_folder' : 'HBASE'
+      },
+      'taskId' : '3',
+      'roleCommand': 'INSTALL'
+    }
+    get_service_base_dir_mock.return_value = "/basedir/"
+    resolve_script_path_mock.return_value = "/basedir/scriptpath"
+    resolve_hook_script_path_mock.return_value = \
+      ('/hooks_dir/prefix-command/scripts/hook.py',
+       '/hooks_dir/prefix-command')
+    dummy_controller = MagicMock()
+    orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
+    unix_process_id = 111
+    orchestrator.commands_in_progress = {command['taskId']: unix_process_id}
+    get_hook_base_dir_mock.return_value = "/hooks/"
+    run_file_mock_return_value = {
+      'stdout' : 'killed',
+      'stderr' : 'killed',
+      'exitcode': 1,
+      }
+    def side_effect(*args, **kwargs):
+      time.sleep(0.2)
+      return run_file_mock_return_value
+    run_file_mock.side_effect = side_effect
+
+    _, out = tempfile.mkstemp()
+    _, err = tempfile.mkstemp()
+    pool = ThreadPool(processes=1)
+    async_result = pool.apply_async(orchestrator.runCommand, (command, out, err))
+
+    time.sleep(0.1)
+    orchestrator.cancel_command(command['taskId'], 'reason')
+
+    ret = async_result.get()
+
+    self.assertEqual(ret['exitcode'], 1)
+    self.assertEquals(ret['stdout'], 'killed\nCommand aborted. reason')
+    self.assertEquals(ret['stderr'], 'killed\nCommand aborted. reason')
+
+    self.assertTrue(kill_process_with_children_mock.called)
+    self.assertFalse(command['taskId'] in orchestrator.commands_in_progress.keys())
+    self.assertTrue(os.path.exists(out))
+    self.assertTrue(os.path.exists(err))
+    os.remove(out)
+    os.remove(err)
+
+  from ambari_agent.StackVersionsFileHandler import StackVersionsFileHandler
+
+  @patch("shell.kill_process_with_children")
+  @patch.object(FileCache, "__init__")
+  @patch.object(CustomServiceOrchestrator, "resolve_script_path")
+  @patch.object(CustomServiceOrchestrator, "resolve_hook_script_path")
+  @patch.object(StackVersionsFileHandler, "read_stack_version")
+  def test_cancel_backgound_command(self, read_stack_version_mock, resolve_hook_script_path_mock, resolve_script_path_mock, FileCache_mock,
+                                      kill_process_with_children_mock):
+    FileCache_mock.return_value = None
+    FileCache_mock.cache_dir = MagicMock()
+    resolve_hook_script_path_mock.return_value = None
+#     shell.kill_process_with_children = MagicMock()
+    dummy_controller = MagicMock()
+    cfg = AmbariConfig().getConfig()
+    cfg.set('agent', 'tolerate_download_failures', 'true')
+    cfg.set('agent', 'prefix', '.')
+    cfg.set('agent', 'cache_dir', 'background_tasks')
+
+    actionQueue = ActionQueue(cfg, dummy_controller)
+
+    dummy_controller.actionQueue = actionQueue
+    orchestrator = CustomServiceOrchestrator(cfg, dummy_controller)
+    orchestrator.file_cache = MagicMock()
+    def f (a, b):
+      return ""
+    orchestrator.file_cache.get_service_base_dir = f
+    actionQueue.customServiceOrchestrator = orchestrator
+
+    import TestActionQueue
+    import copy
+
+    TestActionQueue.patch_output_file(orchestrator.python_executor)
+    orchestrator.python_executor.prepare_process_result = MagicMock()
+    orchestrator.dump_command_to_json = MagicMock()
+
+    lock = threading.RLock()
+    complete_done = threading.Condition(lock)
+
+    complete_was_called = {}
+    def command_complete_w(process_condenced_result, handle):
+      with lock:
+        complete_was_called['visited']= ''
+        complete_done.wait(3)
+
+    actionQueue.on_background_command_complete_callback = TestActionQueue.wraped(actionQueue.on_background_command_complete_callback, command_complete_w, None)
+    execute_command = copy.deepcopy(TestActionQueue.TestActionQueue.background_command)
+    actionQueue.put([execute_command])
+    actionQueue.processBackgroundQueueSafeEmpty()
+
+    time.sleep(.1)
+
+    orchestrator.cancel_command(19,'')
+    self.assertTrue(kill_process_with_children_mock.called)
+    kill_process_with_children_mock.assert_called_with(33)
+
+    with lock:
+      complete_done.notifyAll()
+
+    with lock:
+      self.assertTrue(complete_was_called.has_key('visited'))
+
+    time.sleep(.1)
+
+    runningCommand = actionQueue.commandStatuses.get_command_status(19)
+    self.assertTrue(runningCommand is not None)
+    self.assertEqual(runningCommand['status'], ActionQueue.FAILED_STATUS)
+
+
   @patch.object(CustomServiceOrchestrator, "dump_command_to_json")
   @patch.object(PythonExecutor, "run_file")
   @patch.object(FileCache, "__init__")
@@ -250,6 +398,8 @@ class TestCustomServiceOrchestrator(TestCase):
     }
     dummy_controller = MagicMock()
     orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
+    unix_process_id = 111
+    orchestrator.commands_in_progress = {command['taskId']: unix_process_id}
     # normal run case
     run_file_mock.return_value = {
       'stdout' : 'sss',
@@ -316,6 +466,40 @@ class TestCustomServiceOrchestrator(TestCase):
     self.assertEqual(runCommand_mock.return_value, status)
 
 
+  @patch.object(CustomServiceOrchestrator, "dump_command_to_json")
+  @patch.object(FileCache, "__init__")
+  @patch.object(FileCache, "get_custom_actions_base_dir")
+  def test_runCommand_background_action(self, get_custom_actions_base_dir_mock,
+                                    FileCache_mock,
+                                    dump_command_to_json_mock):
+    FileCache_mock.return_value = None
+    get_custom_actions_base_dir_mock.return_value = "some path"
+    _, script = tempfile.mkstemp()
+    command = {
+      'role' : 'any',
+      'commandParams': {
+        'script_type': 'PYTHON',
+        'script': 'some_custom_action.py',
+        'command_timeout': '600',
+        'jdk_location' : 'some_location'
+      },
+      'taskId' : '13',
+      'roleCommand': 'ACTIONEXECUTE',
+      'commandType': 'BACKGROUND_EXECUTION_COMMAND',
+      '__handle': BackgroundCommandExecutionHandle({'taskId': '13'}, 13,
+                                                   MagicMock(), MagicMock())
+    }
+    dummy_controller = MagicMock()
+    orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
+
+    import TestActionQueue
+    TestActionQueue.patch_output_file(orchestrator.python_executor)
+    orchestrator.python_executor.condenseOutput = MagicMock()
+    orchestrator.dump_command_to_json = MagicMock()
+
+    ret = orchestrator.runCommand(command, "out.txt", "err.txt")
+    self.assertEqual(ret['exitcode'], 777)
+
   def tearDown(self):
     # enable stdout
     sys.stdout = sys.__stdout__

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
index d385697..fc79d27 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
@@ -22,66 +22,90 @@ limitations under the License.
 import unittest
 from mock.mock import patch, MagicMock, call, Mock
 from ambari_agent import DataCleaner
+import AmbariConfig
 
 
 class TestDataCleaner(unittest.TestCase):
 
   def setUp(self):
     self.test_dir = [('/test_path', [],
-                      ['errors-12.txt','output-12.txt','site-12.pp','site-13.pp','site-15.pp','version'])]
+                      ['errors-12.txt', 'output-12.txt', 'site-12.pp', 'site-13.pp', 'site-15.pp',
+                       'structured-out-13.json', 'command-13.json', 'version'])]
     self.config = MagicMock()
-    self.config.get.side_effect = [2592000,3600 + 1,"/test_path"]
+    self.config.get.side_effect = [2592000, (3600 + 1), 10000, "/test_path"]
     DataCleaner.logger = MagicMock()
 
   def test_init_success(self):
     config = MagicMock()
-    config.get.return_value = 2592000
+    config.get.side_effect = [2592000, (3600 + 1), 10000, "/test_path"]
     DataCleaner.logger.reset_mock()
     cleaner = DataCleaner.DataCleaner(config)
     self.assertFalse(DataCleaner.logger.warn.called)
 
+  def test_config(self):
+    """
+    Verify that if the config does not have a property, default values are used.
+    """
+    DataCleaner.logger.reset_mock()
+    config = AmbariConfig.AmbariConfig()
+    config.remove_option('agent', 'data_cleanup_max_age')
+    config.remove_option('agent', 'data_cleanup_interval')
+    config.remove_option('agent', 'data_cleanup_max_size_MB')
+    cleaner = DataCleaner.DataCleaner(config)
+
+    self.assertEqual(cleaner.file_max_age, 86400)
+    self.assertEqual(cleaner.cleanup_interval, 3600)
+    self.assertEqual(cleaner.cleanup_max_size_MB, 10000)
 
   def test_init_warn(self):
     config = MagicMock()
-    config.get.return_value = 10
+    config.get.side_effect = [1, (3600 - 1), (10000 + 1), "/test_path"]
     DataCleaner.logger.reset_mock()
     cleaner = DataCleaner.DataCleaner(config)
     self.assertTrue(DataCleaner.logger.warn.called)
-    self.assertTrue(cleaner.file_max_age == 3600)
+    self.assertTrue(cleaner.file_max_age == 86400)
+    self.assertTrue(cleaner.cleanup_interval == 3600)
+    self.assertTrue(cleaner.cleanup_max_size_MB == 10000)
 
   @patch('os.walk')
   @patch('time.time')
   @patch('os.path.getmtime')
   @patch('os.remove')
-  def test_cleanup_success(self,remMock,mtimeMock,timeMock,walkMock):
+  @patch('os.path.getsize')
+  def test_cleanup_success(self, sizeMock, remMock, mtimeMock, timeMock, walkMock):
     self.config.reset_mock()
     DataCleaner.logger.reset_mock()
 
     walkMock.return_value = iter(self.test_dir)
     timeMock.return_value = 2592000 + 2
-    mtimeMock.side_effect = [1,1,1,2,1,1]
+    mtimeMock.side_effect = [1, 1, 1, 2, 1, 1, 1, 1]
+    sizeMock.return_value = 100
 
     cleaner = DataCleaner.DataCleaner(self.config)
     cleaner.cleanup()
 
-    self.assertTrue(len(remMock.call_args_list) == 4)
-    remMock.assert_any_call('/test_path/errors-12.txt');
-    remMock.assert_any_call('/test_path/output-12.txt');
-    remMock.assert_any_call('/test_path/site-12.pp');
-    remMock.assert_any_call('/test_path/site-15.pp');
+    self.assertTrue(len(remMock.call_args_list) == 6)
+    remMock.assert_any_call('/test_path/errors-12.txt')
+    remMock.assert_any_call('/test_path/output-12.txt')
+    remMock.assert_any_call('/test_path/site-12.pp')
+    remMock.assert_any_call('/test_path/site-15.pp')
+    remMock.assert_any_call('/test_path/structured-out-13.json')
+    remMock.assert_any_call('/test_path/command-13.json')
     pass
 
   @patch('os.walk')
   @patch('time.time')
   @patch('os.path.getmtime')
   @patch('os.remove')
-  def test_cleanup_remove_error(self,remMock,mtimeMock,timeMock,walkMock):
+  @patch('os.path.getsize')
+  def test_cleanup_remove_error(self, sizeMock, remMock, mtimeMock, timeMock, walkMock):
     self.config.reset_mock()
     DataCleaner.logger.reset_mock()
 
     walkMock.return_value = iter(self.test_dir)
     timeMock.return_value = 2592000 + 2
-    mtimeMock.side_effect = [1,1,1,2,1,1]
+    mtimeMock.side_effect = [1, 1, 1, 2, 1, 1, 1, 1]
+    sizeMock.return_value = 100
 
     def side_effect(arg):
       if arg == '/test_path/site-15.pp':
@@ -92,7 +116,7 @@ class TestDataCleaner(unittest.TestCase):
     cleaner = DataCleaner.DataCleaner(self.config)
     cleaner.cleanup()
 
-    self.assertTrue(len(remMock.call_args_list) == 4)
+    self.assertTrue(len(remMock.call_args_list) == 6)
     self.assertTrue(DataCleaner.logger.error.call_count == 1)
     pass
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestHardware.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHardware.py b/ambari-agent/src/test/python/ambari_agent/TestHardware.py
index 96d1a65..410f9d8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHardware.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHardware.py
@@ -196,10 +196,10 @@ lo        Link encap:Local Loopback
     self.assertEquals(result['operatingsystem'], 'some_type_of_os')
     self.assertEquals(result['osfamily'], 'redhat')
 
-    get_os_family_mock.return_value = "debian"
+    get_os_family_mock.return_value = "ubuntu"
     result = Facter().facterInfo()
     self.assertEquals(result['operatingsystem'], 'some_type_of_os')
-    self.assertEquals(result['osfamily'], 'debian')
+    self.assertEquals(result['osfamily'], 'ubuntu')
 
     get_os_family_mock.return_value = "suse"
     result = Facter().facterInfo()

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestHeartbeat.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHeartbeat.py b/ambari-agent/src/test/python/ambari_agent/TestHeartbeat.py
index 4703af4..bdc6c6b 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHeartbeat.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHeartbeat.py
@@ -27,6 +27,7 @@ from mock.mock import patch, MagicMock, call
 import StringIO
 import sys
 
+
 with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
   from ambari_agent.Heartbeat import Heartbeat
   from ambari_agent.ActionQueue import ActionQueue
@@ -64,7 +65,7 @@ class TestHeartbeat(TestCase):
     self.assertEquals(result['componentStatus'] is not None, True, "Heartbeat should contain componentStatus")
     self.assertEquals(result['reports'] is not None, True, "Heartbeat should contain reports")
     self.assertEquals(result['timestamp'] >= 1353679373880L, True)
-    self.assertEquals(len(result['nodeStatus']), 2)
+    self.assertEquals(len(result['nodeStatus']), 3)
     self.assertEquals(result['nodeStatus']['cause'], "NONE")
     self.assertEquals(result['nodeStatus']['status'], "HEALTHY")
     # result may or may NOT have an agentEnv structure in it
@@ -102,9 +103,10 @@ class TestHeartbeat(TestCase):
     hb = heartbeat.build(id = 0, state_interval=1, componentsMapped=True)
     self.assertEqual(register_mock.call_args_list[0][0][1], False)
 
-
+  @patch.object(HostInfo, "createAlerts")
   @patch.object(ActionQueue, "result")
-  def test_build_long_result(self, result_mock):
+  def test_build_long_result(self, result_mock, createAlerts_mock):
+    createAlerts_mock.return_value = []
     config = AmbariConfig.AmbariConfig().getConfig()
     config.set('agent', 'prefix', 'tmp')
     config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
@@ -169,6 +171,7 @@ class TestHeartbeat(TestCase):
     hb['timestamp'] = 'timestamp'
     expected = {'nodeStatus':
                   {'status': 'HEALTHY',
+                   'alerts': [],
                    'cause': 'NONE'},
                 'timestamp': 'timestamp', 'hostname': 'hostname',
                 'responseId': 10, 'reports': [

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py b/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
index cdd5c36..c958412 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
@@ -117,6 +117,7 @@ class TestHostCleanup(TestCase):
       self.silent = silent
       self.java_home = java_home
 
+  @patch.object(HostCleanup.HostCleanup, 'do_clear_cache')
   @patch.object(HostCleanup, 'get_YN_input')
   @patch.object(HostCleanup.HostCleanup, 'do_cleanup')
   @patch.object(HostCleanup.HostCleanup, 'is_current_user_root')
@@ -126,7 +127,7 @@ class TestHostCleanup(TestCase):
   @patch.object(logging, 'FileHandler')
   @patch.object(optparse.OptionParser, 'parse_args')
   def test_options(self, parser_mock, file_handler_mock, logging_mock, read_host_check_file_mock,
-                   set_formatter_mock, user_root_mock, do_cleanup_mock, get_yn_input_mock):
+                   set_formatter_mock, user_root_mock, do_cleanup_mock, get_yn_input_mock, clear_cache_mock):
     parser_mock.return_value = (TestHostCleanup.HostCleanupOptions('/someoutputfile', '/someinputfile', '', False,
                                                                    False, 'java_home'), [])
     file_handler_mock.return_value = logging.FileHandler('') # disable creating real file
@@ -144,7 +145,27 @@ class TestHostCleanup(TestCase):
     read_host_check_file_mock.assert_called_with('/someinputfile')
     self.assertTrue(get_yn_input_mock.called)
 
+  @patch.object(HostCleanup.HostCleanup, 'get_files_in_dir')
+  @patch.object(HostCleanup.HostCleanup, 'do_erase_files_silent')
+  def test_clear_cache(self, erase_files_mock, get_files_mock):
+    old_data = HostCleanup.CACHE_FILES_PATTERN
+
+    HostCleanup.CACHE_FILES_PATTERN = {
+      'somedir': ['*.txt']
+    }
+
+    files_list = ['/tmp/somedir/test.txt']
+    get_files_mock.return_value = files_list
+
+    self.hostcleanup.do_clear_cache('/tmp')
 
+
+    get_files_mock.assert_called_with('/tmp/somedir', '*.txt')
+    erase_files_mock.assert_called_with(files_list)
+
+    HostCleanup.CACHE_FILES_PATTERN = old_data
+
+  @patch.object(HostCleanup.HostCleanup, 'do_clear_cache')
   @patch.object(HostCleanup, 'get_YN_input')
   @patch.object(HostCleanup.HostCleanup, 'do_cleanup')
   @patch.object(HostCleanup.HostCleanup, 'is_current_user_root')
@@ -154,7 +175,7 @@ class TestHostCleanup(TestCase):
   @patch.object(logging, 'FileHandler')
   @patch.object(optparse.OptionParser, 'parse_args')
   def test_options_silent(self, parser_mock, file_handler_mock, logging_mock, read_host_check_file_mock,
-                   set_formatter_mock, user_root_mock, do_cleanup_mock, get_yn_input_mock):
+                   set_formatter_mock, user_root_mock, do_cleanup_mock, get_yn_input_mock, clear_cache_mock):
     parser_mock.return_value = (TestHostCleanup.HostCleanupOptions('/someoutputfile', '/someinputfile', '', False,
                                                                    True, 'java_home'), [])
     file_handler_mock.return_value = logging.FileHandler('') # disable creating real file
@@ -172,6 +193,7 @@ class TestHostCleanup(TestCase):
     read_host_check_file_mock.assert_called_with('/someinputfile')
     self.assertFalse(get_yn_input_mock.called)
 
+  @patch.object(HostCleanup.HostCleanup, 'do_clear_cache')
   @patch.object(HostCleanup.HostCleanup, 'get_additional_dirs')
   @patch.object(HostCleanup.HostCleanup, 'do_erase_alternatives')
   @patch.object(HostCleanup.HostCleanup, 'find_repo_files_for_repos')
@@ -185,7 +207,7 @@ class TestHostCleanup(TestCase):
                       do_erase_dir_silent_method,
                       do_erase_files_silent_method, do_kill_processes_method,
                       get_os_type_method, find_repo_files_for_repos_method,
-                      do_erase_alternatives_method, get_additional_dirs_method):
+                      do_erase_alternatives_method, get_additional_dirs_method, clear_cache_mock):
     out = StringIO.StringIO()
     sys.stdout = out
     get_additional_dirs_method.return_value = ['/tmp/hadoop-nagios','/tmp/hsperfdata_007']
@@ -216,7 +238,7 @@ class TestHostCleanup(TestCase):
 
     sys.stdout = sys.__stdout__
 
-
+  @patch.object(HostCleanup.HostCleanup, 'do_clear_cache')
   @patch.object(HostCleanup.HostCleanup, 'do_delete_by_owner')
   @patch.object(HostCleanup.HostCleanup, 'get_user_ids')
   @patch.object(HostCleanup.HostCleanup, 'do_erase_alternatives')
@@ -232,7 +254,7 @@ class TestHostCleanup(TestCase):
                       do_erase_files_silent_method, do_kill_processes_method,
                       get_os_type_method, find_repo_files_for_repos_method,
                       do_erase_alternatives_method, get_user_ids_method,
-                      do_delete_by_owner_method):
+                      do_delete_by_owner_method, clear_cache_mock):
 
     global SKIP_LIST
     oldSkipList = HostCleanup.SKIP_LIST
@@ -260,6 +282,7 @@ class TestHostCleanup(TestCase):
     HostCleanup.SKIP_LIST = oldSkipList
     sys.stdout = sys.__stdout__
 
+  @patch.object(HostCleanup.HostCleanup, 'do_clear_cache')
   @patch.object(HostCleanup.HostCleanup, 'find_repo_files_for_repos')
   @patch.object(OSCheck, "get_os_type")
   @patch.object(HostCleanup.HostCleanup, 'do_kill_processes')
@@ -271,7 +294,7 @@ class TestHostCleanup(TestCase):
                       do_delete_users_method,
                       do_erase_dir_silent_method,
                       do_erase_files_silent_method, do_kill_processes_method,
-                      get_os_type_method, find_repo_files_for_repos_method):
+                      get_os_type_method, find_repo_files_for_repos_method, clear_cache_mock):
 
     out = StringIO.StringIO()
     sys.stdout = out

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
index ba827ae..71129c7 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
@@ -32,20 +32,18 @@ with patch("platform.linux_distribution", return_value = ('redhat','11','Final')
   from ambari_agent.HostCheckReportFileHandler import HostCheckReportFileHandler
   from ambari_agent.PackagesAnalyzer import PackagesAnalyzer
   from ambari_agent.HostInfo import HostInfo
-  from ambari_agent.HostInfo import FirewallChecks
   from ambari_agent.Hardware import Hardware
   from ambari_agent.AmbariConfig import AmbariConfig
   from resource_management.core.system import System
-  from ambari_commons import OSCheck
+  from ambari_commons import OSCheck, Firewall, FirewallChecks ,OSConst
 
 @patch.object(System, "os_family", new = 'redhat')
 class TestHostInfo(TestCase):
 
-  logger = logging.getLogger()
-
-  @patch.object(PackagesAnalyzer, 'hasZypper')
+  @patch.object(OSCheck, 'get_os_family')
   @patch.object(PackagesAnalyzer, 'subprocessWithTimeout')
-  def test_analyze_zypper_out(self, spwt_mock, hasZy_mock):
+  def test_analyze_zypper_out(self, spwt_mock, get_os_family_mock):
+    get_os_family_mock.return_value = 'suse'
     packageAnalyzer = PackagesAnalyzer()
     stringToRead = """Refreshing service 'susecloud'.
            Loading repository data...
@@ -66,7 +64,6 @@ class TestHostInfo(TestCase):
     result['retCode'] = 0
 
     spwt_mock.return_value = result
-    hasZy_mock.return_value = True
     installedPackages = []
     packageAnalyzer.allInstalledPackages(installedPackages)
     self.assertEqual(7, len(installedPackages))
@@ -134,9 +131,10 @@ class TestHostInfo(TestCase):
     for package in expected:
       self.assertTrue(package in allPackages)
 
-  @patch.object(PackagesAnalyzer, 'hasZypper')
+  @patch.object(OSCheck, 'get_os_family')
   @patch.object(PackagesAnalyzer, 'subprocessWithTimeout')
-  def test_analyze_yum_output(self, subprocessWithTimeout_mock, hasZy_mock):
+  def test_analyze_yum_output(self, subprocessWithTimeout_mock, get_os_family_mock):
+    get_os_family_mock.return_value = 'redhat'
     packageAnalyzer = PackagesAnalyzer()
     stringToRead = """Loaded plugins: amazon-id, product-id, rhui-lb, security, subscription-manager
                       Updating certificate-based repositories.
@@ -160,7 +158,6 @@ class TestHostInfo(TestCase):
     result['retCode'] = 0
 
     subprocessWithTimeout_mock.return_value = result
-    hasZy_mock.return_value = False
     installedPackages = []
     packageAnalyzer.allInstalledPackages(installedPackages)
     self.assertEqual(9, len(installedPackages))
@@ -269,6 +266,7 @@ class TestHostInfo(TestCase):
     hostInfo = HostInfo()
     dict = {}
     hostInfo.register(dict, False, False)
+    self.assertTrue(cit_mock.called)
     self.assertTrue(gir_mock.called)
     self.assertTrue(gpd_mock.called)
     self.assertTrue(aip_mock.called)
@@ -321,6 +319,7 @@ class TestHostInfo(TestCase):
     self.verifyReturnedValues(dict)
     self.assertTrue(os_umask_mock.call_count == 2)
 
+    cit_mock.reset_mock()
     hostInfo = HostInfo()
     dict = {}
     hostInfo.register(dict, False, False)
@@ -328,6 +327,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(gpd_mock.called)
     self.assertTrue(aip_mock.called)
     self.assertTrue(cit_mock.called)
+    self.assertEqual(1, cit_mock.call_count)
 
     for existingPkg in ["pkg1", "pkg2"]:
       self.assertTrue(existingPkg in dict['installedPackages'])
@@ -515,36 +515,31 @@ class TestHostInfo(TestCase):
     self.assertEquals(result[0]['name'], 'config1')
     self.assertEquals(result[0]['target'], 'real_path_to_conf')
 
+  @patch.object(OSCheck, "get_os_family")
+  @patch.object(OSCheck, "get_os_type")
+  @patch.object(OSCheck, "get_os_major_version")
   @patch.object(FirewallChecks, "run_os_command")
-  def test_IpTablesRunning(self, run_os_command_mock):
-    hostInfo = HostInfo()
-    for firewallType in hostInfo.getFirewallObjectTypes():
-      firewall = firewallType()
-      run_os_command_mock.return_value = firewall.get_running_result()
-      self.assertTrue(firewall.check_iptables())
-
-  @patch("subprocess.Popen")
-  def test_run_os_command_exception(self, popen_mock):
-    def base_test():
-       return "base test"
+  def test_IpTablesRunning(self, run_os_command_mock, get_os_major_version_mock, get_os_type_mock, get_os_family_mock):
+    get_os_type_mock.return_value = ""
+    get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
+    run_os_command_mock.return_value = 0, "Table: filter", ""
+    self.assertTrue(Firewall().getFirewallObject().check_iptables())
 
-    def sub_test():
-      return "output 1", "error 1"
-
-    base_test.communicate = sub_test
-    base_test.returncode = 0
 
+  @patch.object(HostInfo, "osdiskAvailableSpace")
+  def test_createAlerts(self, osdiskAvailableSpace_mock):
     hostInfo = HostInfo()
-    for firewallType in hostInfo.getFirewallObjectTypes():
-      firewall = firewallType()
-
-      popen_mock.side_effect = None
-      popen_mock.return_value = base_test
-      self.assertTrue(firewall.check_iptables())
+    osdiskAvailableSpace_mock.return_value = {
+      'size': '100',
+      'used': '50',
+      'available': '50',
+      'percent': '50%',
+      'mountpoint': '/testmount',
+      'type': 'ext4',
+      'device': 'device'}
+    result = hostInfo.createAlerts([])
+    self.assertEquals(1, len(result))
 
-      popen_mock.side_effect = OSError('File not found')
-      popen_mock.return_value = None
-      self.assertFalse(firewall.check_iptables())
 
   @patch.object(socket, "getfqdn")
   @patch.object(socket, "gethostbyname")
@@ -570,13 +565,16 @@ class TestHostInfo(TestCase):
 
     self.assertFalse(hostInfo.checkReverseLookup())
 
+
+  @patch.object(OSCheck, "get_os_family")
+  @patch.object(OSCheck, "get_os_type")
+  @patch.object(OSCheck, "get_os_major_version")
   @patch.object(FirewallChecks, "run_os_command")
-  def test_IpTablesStopped(self, run_os_command_mock):
-    hostInfo = HostInfo()
-    for firewallType in hostInfo.getFirewallObjectTypes():
-      firewall = firewallType()
-      run_os_command_mock.return_value = firewall.get_stopped_result()
-      self.assertFalse(firewall.check_iptables())
+  def test_IpTablesStopped(self, run_os_command_mock, get_os_major_version_mock, get_os_type_mock, get_os_family_mock):
+    get_os_type_mock.return_value = ""
+    get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
+    run_os_command_mock.return_value = 3, "", ""
+    self.assertFalse(Firewall().getFirewallObject().check_iptables())
 
   @patch("os.path.isfile")
   @patch('__builtin__.open')

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestHostname.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostname.py b/ambari-agent/src/test/python/ambari_agent/TestHostname.py
index 039ffd4..993a9d1 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostname.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostname.py
@@ -21,7 +21,7 @@ limitations under the License.
 from unittest import TestCase
 import unittest
 import ambari_agent.hostname as hostname
-import ambari_agent.AmbariConfig as AmbariConfig
+from ambari_agent.AmbariConfig import AmbariConfig
 import socket
 import tempfile
 import shutil
@@ -33,7 +33,8 @@ class TestHostname(TestCase):
   def test_hostname(self):
     hostname.cached_hostname = None
     hostname.cached_public_hostname = None
-    self.assertEquals(hostname.hostname(), socket.getfqdn().lower(),
+    config = AmbariConfig()
+    self.assertEquals(hostname.hostname(config), socket.getfqdn().lower(),
                       "hostname should equal the socket-based hostname")
     pass
 
@@ -46,14 +47,14 @@ class TestHostname(TestCase):
     os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)
 
     tmpfile = file(tmpname, "w+")
-    config = AmbariConfig.config
+    config = AmbariConfig()
     try:
       tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
       tmpfile.close()
 
       config.set('agent', 'hostname_script', tmpname)
 
-      self.assertEquals(hostname.hostname(), 'test.example.com', "expected hostname 'test.example.com'")
+      self.assertEquals(hostname.hostname(config), 'test.example.com', "expected hostname 'test.example.com'")
     finally:
       os.remove(tmpname)
       config.remove_option('agent', 'hostname_script')
@@ -66,17 +67,17 @@ class TestHostname(TestCase):
     tmpname = fd[1]
     os.close(fd[0])
     os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)
-   
+
     tmpfile = file(tmpname, "w+")
 
-    config = AmbariConfig.config
+    config = AmbariConfig()
     try:
       tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
       tmpfile.close()
 
       config.set('agent', 'public_hostname_script', tmpname)
 
-      self.assertEquals(hostname.public_hostname(), 'test.example.com', 
+      self.assertEquals(hostname.public_hostname(config), 'test.example.com',
                         "expected hostname 'test.example.com'")
     finally:
       os.remove(tmpname)
@@ -87,9 +88,10 @@ class TestHostname(TestCase):
   def test_caching(self, getfqdn_mock):
     hostname.cached_hostname = None
     hostname.cached_public_hostname = None
+    config = AmbariConfig()
     getfqdn_mock.side_effect = ["test.example.com", "test2.example.com'"]
-    self.assertEquals(hostname.hostname(), "test.example.com")
-    self.assertEquals(hostname.hostname(), "test.example.com")
+    self.assertEquals(hostname.hostname(config), "test.example.com")
+    self.assertEquals(hostname.hostname(config), "test.example.com")
     self.assertEqual(getfqdn_mock.call_count, 1)
     pass
 
@@ -97,5 +99,3 @@ if __name__ == "__main__":
   unittest.main(verbosity=2)
 
 
-
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
index 6937da2..9dfb47a 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
@@ -36,8 +36,8 @@ class TestLiveStatus(TestCase):
     sys.stdout = out
     LiveStatus.SERVICES = [
       "HDFS", "MAPREDUCE", "GANGLIA", "HBASE",
-      "NAGIOS", "ZOOKEEPER", "OOZIE", "HCATALOG",
-      "KERBEROS", "TEMPLETON", "HIVE", "WEBHCAT",
+      "NAGIOS", "ZOOKEEPER", "OOZIE",
+      "KERBEROS", "TEMPLETON", "HIVE",
       "YARN", "MAPREDUCE2", "FLUME", "TEZ",
       "FALCON", "STORM"
     ]

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestMain.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestMain.py b/ambari-agent/src/test/python/ambari_agent/TestMain.py
index 7cf14b6..7b1a8c8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -242,11 +242,11 @@ class TestMain(unittest.TestCase):
   @patch.object(DataCleaner,"start")
   @patch.object(DataCleaner,"__init__")
   @patch.object(PingPortListener,"start")
-  @patch.object(PingPortListener,"__init__")  
+  @patch.object(PingPortListener,"__init__")
   def test_main(self, ping_port_init_mock, ping_port_start_mock, data_clean_init_mock,data_clean_start_mock,
                 parse_args_mock, join_mock, start_mock, Controller_init_mock, try_to_connect_mock,
                 update_log_level_mock, daemonize_mock, perform_prestart_checks_mock,
-                resolve_ambari_config_mock, stop_mock, bind_signal_handlers_mock, 
+                resolve_ambari_config_mock, stop_mock, bind_signal_handlers_mock,
                 setup_logging_mock, socket_mock):
     data_clean_init_mock.return_value = None
     Controller_init_mock.return_value = None

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py b/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
index 10ddca3..474548f 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
@@ -38,16 +38,16 @@ class TestNetUtil(unittest.TestCase):
 
     # test 200
     netutil = NetUtil.NetUtil()
-    self.assertTrue(netutil.checkURL("url"))
+    self.assertTrue(netutil.checkURL("url")[0])
 
     # test fail
     response.status = 404
-    self.assertFalse(netutil.checkURL("url"))
+    self.assertFalse(netutil.checkURL("url")[0])
 
     # test Exception
     response.status = 200
     httpsConMock.side_effect = Exception("test")
-    self.assertFalse(netutil.checkURL("url"))
+    self.assertFalse(netutil.checkURL("url")[0])
 
 
   @patch("time.sleep")
@@ -55,15 +55,15 @@ class TestNetUtil(unittest.TestCase):
 
     netutil = NetUtil.NetUtil()
     checkURL = MagicMock(name="checkURL")
-    checkURL.return_value = True
+    checkURL.return_value = True, "test"
     netutil.checkURL = checkURL
-    l = MagicMock()
 
     # one successful get
     self.assertEqual(0, netutil.try_to_connect("url", 10))
 
     # got successful after N retries
-    gets = [True, False, False]
+    gets = [[True, ""], [False, ""], [False, ""]]
+
     def side_effect(*args):
       return gets.pop()
     checkURL.side_effect = side_effect
@@ -71,7 +71,5 @@ class TestNetUtil(unittest.TestCase):
 
     # max retries
     checkURL.side_effect = None
-    checkURL.return_value = False
+    checkURL.return_value = False, "test"
     self.assertEqual(5, netutil.try_to_connect("url", 5))
-
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
index 9e52eae..d1bec5d 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
@@ -55,12 +55,15 @@ class TestPythonExecutor(TestCase):
     runShellKillPgrp_method.side_effect = lambda python : python.terminate()
     executor.runShellKillPgrp = runShellKillPgrp_method
     subproc_mock.returncode = None
+    callback_method = MagicMock()
     thread = Thread(target =  executor.run_file, args = ("fake_puppetFile",
-      ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstrucout,"INFO"))
+      ["arg1", "arg2"], "/fake_tmp_dir", tmpoutfile, tmperrfile,
+      PYTHON_TIMEOUT_SECONDS, tmpstrucout, "INFO", callback_method, '1'))
     thread.start()
     time.sleep(0.1)
     subproc_mock.finished_event.wait()
     self.assertEquals(subproc_mock.was_terminated, True, "Subprocess should be terminated due to timeout")
+    self.assertTrue(callback_method.called)
 
 
   def test_watchdog_2(self):
@@ -83,16 +86,18 @@ class TestPythonExecutor(TestCase):
     runShellKillPgrp_method.side_effect = lambda python : python.terminate()
     executor.runShellKillPgrp = runShellKillPgrp_method
     subproc_mock.returncode = 0
+    callback_method = MagicMock()
     thread = Thread(target =  executor.run_file, args = ("fake_puppetFile", ["arg1", "arg2"],
-                                                      tmpoutfile, tmperrfile,
-                                                      PYTHON_TIMEOUT_SECONDS, tmpstrucout, "INFO"))
+                                                      "/fake_tmp_dir", tmpoutfile, tmperrfile,
+                                                      PYTHON_TIMEOUT_SECONDS, tmpstrucout,
+                                                      "INFO", callback_method, "1-1"))
     thread.start()
     time.sleep(0.1)
     subproc_mock.should_finish_event.set()
     subproc_mock.finished_event.wait()
     self.assertEquals(subproc_mock.was_terminated, False, "Subprocess should not be terminated before timeout")
     self.assertEquals(subproc_mock.returncode, 0, "Subprocess should not be terminated before timeout")
-
+    self.assertTrue(callback_method.called)
 
   def test_execution_results(self):
     subproc_mock = self.Subprocess_mockup()
@@ -112,10 +117,13 @@ class TestPythonExecutor(TestCase):
     executor.runShellKillPgrp = runShellKillPgrp_method
     subproc_mock.returncode = 0
     subproc_mock.should_finish_event.set()
-    result = executor.run_file("file", ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstroutfile, "INFO")
+    callback_method = MagicMock()
+    result = executor.run_file("file", ["arg1", "arg2"], "/fake_tmp_dir",
+                               tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS,
+                               tmpstroutfile, "INFO", callback_method, "1-1")
     self.assertEquals(result, {'exitcode': 0, 'stderr': 'Dummy err', 'stdout': 'Dummy output',
                                'structuredOut': {}})
-
+    self.assertTrue(callback_method.called)
 
   def test_is_successfull(self):
     executor = PythonExecutor("/tmp", AmbariConfig().getConfig())

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
index b70ebbe..2a9f716 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestRegistration.py
@@ -28,8 +28,7 @@ with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
   from ambari_agent.Register import Register
   from ambari_agent.AmbariConfig import AmbariConfig
   from ambari_agent.HostInfo import HostInfo
-  from ambari_agent.HostInfo import FirewallChecks
-  from ambari_commons import OSCheck
+  from ambari_commons import OSCheck, Firewall, FirewallChecks
 
 class TestRegistration(TestCase):
   @patch.object(FirewallChecks, "run_os_command")
@@ -60,6 +59,7 @@ class TestRegistration(TestCase):
     print data['agentEnv']['umask']
     self.assertEquals(not data['agentEnv']['umask']== "", True, "agents umask should not be empty")
     self.assertEquals(data['currentPingPort'] == 33777, True, "current ping port should be 33777")
-    self.assertEquals(len(data), 8)
+    self.assertEquals(data['prefix'], config.get('agent', 'prefix'), 'The prefix path does not match')
+    self.assertEquals(len(data), 9)
 
     os.remove(ver_file)

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
index 8b11063..37a61c8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
@@ -45,7 +45,7 @@ class TestSecurity(unittest.TestCase):
     out = StringIO.StringIO()
     sys.stdout = out
     # Create config
-    self.config = AmbariConfig().getConfig()
+    self.config = AmbariConfig()
     # Instantiate CachedHTTPSConnection (skip connect() call)
     with patch.object(security.VerifiedHTTPSConnection, "connect"):
       self.cachedHTTPSConnection = security.CachedHTTPSConnection(self.config)

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json b/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
new file mode 100644
index 0000000..6e80dea
--- /dev/null
+++ b/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
@@ -0,0 +1,37 @@
+[
+  {
+    "clusterName": "c1",
+    "hostName": "c6401.ambari.apache.org",
+    "hash": "12341234134412341243124",
+    "configurations": {
+      "hdfs-site": {
+        "dfs.namenode.http-address": "c6401.ambari.apache.org:50070"
+      }
+    },
+    "alertDefinitions": [
+      {
+        "name": "namenode_process",
+        "service": "HDFS",
+        "component": "NAMENODE",
+        "label": "NameNode process",
+        "interval": 6,
+        "scope": "HOST",
+        "uuid": "3f82ae27-fa6a-465b-b77d-67963ac55d2f",
+        "enabled": true,
+        "source": {
+          "type": "PORT",
+          "uri": "{{hdfs-site/dfs.namenode.http-address}}",
+          "default_port": 50070,
+          "reporting": {
+            "ok": {
+              "text": "TCP OK - {0:.4f} response time on port {1}"
+            },
+            "critical": {
+              "text": "Could not load process info: {0} on host {1}:{2}"
+            }
+          }
+        }
+      }
+    ]
+  }
+]

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/ambari_agent/dummy_files/test_script.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/dummy_files/test_script.py b/ambari-agent/src/test/python/ambari_agent/dummy_files/test_script.py
new file mode 100644
index 0000000..211087c
--- /dev/null
+++ b/ambari-agent/src/test/python/ambari_agent/dummy_files/test_script.py
@@ -0,0 +1,3 @@
+
+def execute(params=None):
+  return (('WARNING', ['all is not well', str(params)]))

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestContentSources.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestContentSources.py b/ambari-agent/src/test/python/resource_management/TestContentSources.py
index 2527f30..1c5e8a8 100644
--- a/ambari-agent/src/test/python/resource_management/TestContentSources.py
+++ b/ambari-agent/src/test/python/resource_management/TestContentSources.py
@@ -27,7 +27,7 @@ from resource_management.core.source import DownloadSource
 from resource_management.core.source import Template
 from resource_management.core.source import InlineTemplate
 
-from jinja2 import UndefinedError, TemplateNotFound
+from ambari_jinja2 import UndefinedError, TemplateNotFound
 import urllib2
 import os
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestCopyFromLocal.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestCopyFromLocal.py b/ambari-agent/src/test/python/resource_management/TestCopyFromLocal.py
index 90397ae..32a7963 100644
--- a/ambari-agent/src/test/python/resource_management/TestCopyFromLocal.py
+++ b/ambari-agent/src/test/python/resource_management/TestCopyFromLocal.py
@@ -36,10 +36,10 @@ class TestCopyFromLocal(TestCase):
       call_arg_list = execute_hadoop_mock.call_args_list
       self.assertEqual('fs -copyFromLocal /user/testdir/*.files /apps/test/',
                        call_arg_list[0][0][0].command)
-      self.assertEquals({'not_if': "su - user1 -c ' hadoop fs -ls /apps/test/*.files' >/dev/null 2>&1", 'user': 'user1', 'conf_dir': '/etc/hadoop/conf'},
+      self.assertEquals({'not_if': "su - user1 -c ' export PATH=$PATH:/usr/bin ; hadoop fs -ls /apps/test//*.files' >/dev/null 2>&1", 'user': 'user1', 'bin_dir': '/usr/bin', 'conf_dir': '/etc/hadoop/conf'},
                         call_arg_list[0][0][0].arguments)
-      self.assertEquals('fs -chown user1 /apps/test/*.files', call_arg_list[1][0][0].command)
-      self.assertEquals({'user': 'hdfs', 'conf_dir': '/etc/hadoop/conf'}, call_arg_list[1][0][0].arguments)
+      self.assertEquals('fs -chown user1 /apps/test//*.files', call_arg_list[1][0][0].command)
+      self.assertEquals({'user': 'hdfs', 'bin_dir': '/usr/bin', 'conf_dir': '/etc/hadoop/conf'}, call_arg_list[1][0][0].arguments)
 
 
   @patch("resource_management.libraries.providers.execute_hadoop.ExecuteHadoopProvider")
@@ -57,9 +57,9 @@ class TestCopyFromLocal(TestCase):
       call_arg_list = execute_hadoop_mock.call_args_list
       self.assertEqual('fs -copyFromLocal /user/testdir/*.files /apps/test/',
                        call_arg_list[0][0][0].command)
-      self.assertEquals({'not_if': "su - user1 -c ' hadoop fs -ls /apps/test/*.files' >/dev/null 2>&1", 'user': 'user1', 'conf_dir': '/etc/hadoop/conf'},
+      self.assertEquals({'not_if': "su - user1 -c ' export PATH=$PATH:/usr/bin ; hadoop fs -ls /apps/test//*.files' >/dev/null 2>&1", 'user': 'user1', 'bin_dir': '/usr/bin', 'conf_dir': '/etc/hadoop/conf'},
                         call_arg_list[0][0][0].arguments)
-      self.assertEquals('fs -chown user1:hdfs /apps/test/*.files', call_arg_list[1][0][0].command)
-      self.assertEquals({'user': 'hdfs', 'conf_dir': '/etc/hadoop/conf'}, call_arg_list[1][0][0].arguments)
+      self.assertEquals('fs -chown user1:hdfs /apps/test//*.files', call_arg_list[1][0][0].command)
+      self.assertEquals({'user': 'hdfs', 'bin_dir': '/usr/bin', 'conf_dir': '/etc/hadoop/conf'}, call_arg_list[1][0][0].arguments)
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
index e357390..d2ef71c 100644
--- a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py
@@ -15,6 +15,7 @@ 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.
 '''
+import os
 
 from unittest import TestCase
 from mock.mock import patch
@@ -38,7 +39,11 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_count, 1)
       self.assertEqual(execute_mock.call_args[0][0].command,'hadoop --config conf_dir command')
       self.assertEqual(execute_mock.call_args[0][0].arguments,
-                       {'logoutput': True, 'tries': 1, 'user': 'user', 'try_sleep': 0})
+                       {'logoutput': True,
+                        'tries': 1,
+                        'user': 'user',
+                        'try_sleep': 0,
+                        'path': []})
 
 
   @patch("resource_management.core.providers.system.ExecuteProvider")
@@ -58,7 +63,11 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_count, 1)
       self.assertEqual(execute_mock.call_args[0][0].command,'hadoop --config conf_dir command')
       self.assertEqual(execute_mock.call_args[0][0].arguments,
-                       {'logoutput': False, 'tries': 1, 'user': 'user', 'try_sleep': 0})
+                       {'logoutput': False,
+                        'tries': 1,
+                        'user': 'user',
+                        'try_sleep': 0,
+                        'path': []})
 
 
   @patch("resource_management.core.providers.system.ExecuteProvider")
@@ -83,7 +92,11 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_count, 1)
       self.assertEqual(execute_mock.call_args[0][0].command,'hadoop --config conf_dir command')
       self.assertEqual(execute_mock.call_args[0][0].arguments,
-                       {'logoutput': True, 'tries': 2, 'user': 'user', 'try_sleep': 2})
+                       {'logoutput': True,
+                        'tries': 2,
+                        'user': 'user',
+                        'try_sleep': 2,
+                        'path': []})
 
 
   @patch("resource_management.core.providers.system.ExecuteProvider")
@@ -105,9 +118,17 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_args_list[1][0][0].command,
                        'hadoop --config conf_dir command2')
       self.assertEqual(execute_mock.call_args_list[0][0][0].arguments,
-                       {'logoutput': False, 'tries': 1, 'user': 'user', 'try_sleep': 0})
+                       {'logoutput': False,
+                        'tries': 1,
+                        'user': 'user',
+                        'try_sleep': 0,
+                        'path': []})
       self.assertEqual(execute_mock.call_args_list[1][0][0].arguments,
-                       {'logoutput': False, 'tries': 1, 'user': 'user', 'try_sleep': 0})
+                       {'logoutput': False,
+                        'tries': 1,
+                        'user': 'user',
+                        'try_sleep': 0,
+                        'path': []})
 
 
   @patch("resource_management.core.providers.system.ExecuteProvider")
@@ -156,7 +177,11 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_args_list[1][0][0].command,
                        'hadoop --config conf_dir command')
       self.assertEqual(execute_mock.call_args_list[1][0][0].arguments,
-                       {'logoutput': True, 'tries': 1, 'user': 'user', 'try_sleep': 0})
+                       {'logoutput': True,
+                        'tries': 1,
+                        'user': 'user',
+                        'try_sleep': 0,
+                        'path': []})
 
 
   @patch("resource_management.core.providers.system.ExecuteProvider")
@@ -204,4 +229,4 @@ class TestExecuteHadoopResource(TestCase):
       self.assertEqual(execute_mock.call_args_list[0][0][0].command,
                        'path -kt keytab principal')
       self.assertEqual(execute_mock.call_args_list[1][0][0].command,
-                       'hadoop --config conf_dir command')
\ No newline at end of file
+                       'hadoop --config conf_dir command')

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
index f0a4539..93d7064 100644
--- a/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestExecuteResource.py
@@ -90,7 +90,8 @@ class TestExecuteResource(TestCase):
       execute_resource = Execute('echo "1"',
                                  path=["/test/one", "test/two"]
       )
-    self.assertEqual(execute_resource.environment["PATH"], '/test/one:test/two')
+    expected_command = 'export PATH=$PATH:/test/one:test/two ; echo "1"'
+    self.assertEqual(popen_mock.call_args_list[0][0][0][3], expected_command)
 
   @patch('time.sleep')
   @patch.object(subprocess, "Popen")

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestFileResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestFileResource.py b/ambari-agent/src/test/python/resource_management/TestFileResource.py
index 7da0dbd..8fba4c0 100644
--- a/ambari-agent/src/test/python/resource_management/TestFileResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestFileResource.py
@@ -330,3 +330,33 @@ class TestFileResource(TestCase):
 
     self.assertEqual(chmod_mock.call_count, 1)
     self.assertEqual(chown_mock.call_count, 0)
+
+  @patch("resource_management.core.providers.system._ensure_metadata")
+  @patch("resource_management.core.providers.system.FileProvider._get_content")
+  @patch("__builtin__.open")
+  @patch.object(os.path, "exists")
+  @patch.object(os.path, "isdir")
+  def test_action_create_encoding(self, isdir_mock, exists_mock, open_mock, get_content_mock ,ensure_mock):
+
+    isdir_mock.side_effect = [False, True]
+    exists_mock.return_value = True
+    content_mock = MagicMock()
+    old_content_mock = MagicMock()
+    get_content_mock.return_value = content_mock
+    new_file = MagicMock()
+    open_mock.return_value = new_file
+    enter_file_mock = MagicMock()
+    enter_file_mock.read = MagicMock(return_value=old_content_mock)
+    new_file.__enter__ = MagicMock(return_value=enter_file_mock)
+    with Environment('/') as env:
+      File('/directory/file',
+           action='create',
+           mode=0777,
+           content='file-content',
+           encoding = "UTF-8"
+      )
+
+
+    open_mock.assert_called_with('/directory/file', 'wb')
+    content_mock.encode.assert_called_with('UTF-8')
+    old_content_mock.decode.assert_called_with('UTF-8')

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestFileSystem.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestFileSystem.py b/ambari-agent/src/test/python/resource_management/TestFileSystem.py
new file mode 100644
index 0000000..91fd71d
--- /dev/null
+++ b/ambari-agent/src/test/python/resource_management/TestFileSystem.py
@@ -0,0 +1,117 @@
+'''
+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.
+'''
+
+import os
+from unittest import TestCase
+from mock.mock import patch
+
+from resource_management.libraries.functions import file_system
+import resource_management.core.providers.mount
+
+
+class TestFileSystem(TestCase):
+  """
+  Test the functionality of the file_system.py file that checks for the mount point of a path.
+  """
+
+  class MOUNT_TYPE:
+    SINGLE_ROOT = 1
+    MULT_DRIVE_CONFLICT = 2
+    MULT_DRIVE_DISTINCT = 3
+
+  def _get_mount(self, type):
+    """
+    /hadoop/hdfs/data will always be on the root
+
+    If the type is MULT_DRIVE_CONFLICT:
+    /hadoop/hdfs/data/1 is on /dev/sda1
+    /hadoop/hdfs/data/2 is on /dev/sda1
+
+    If the type is MULT_DRIVE_DISTINCT:
+    /hadoop/hdfs/data/1 is on /dev/sda1
+    /hadoop/hdfs/data/2 is on /dev/sda2
+    """
+    out = "/dev/mapper/VolGroup-lv_root on / type ext4 (rw)" + os.linesep + \
+          "proc on /proc type proc (rw)" + os.linesep + \
+          "sysfs on /sys type sysfs (rw)" + os.linesep + \
+          "devpts on /dev/pts type devpts (rw,gid=5,mode=620)" + os.linesep + \
+          "tmpfs on /dev/shm type tmpfs (rw)" + os.linesep + \
+          "/dev/sda1 on /boot type ext4 (rw)" + os.linesep + \
+          "none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)" + os.linesep + \
+          "sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)" + os.linesep + \
+          "/vagrant on /vagrant type vboxsf (uid=501,gid=501,rw)"
+
+    if type == self.MOUNT_TYPE.MULT_DRIVE_CONFLICT:
+      out += os.linesep + \
+             "/dev/sda1 on /hadoop/hdfs type ext4 (rw)"
+    elif type == self.MOUNT_TYPE.MULT_DRIVE_DISTINCT:
+      out += os.linesep + \
+             "/dev/sda1 on /hadoop/hdfs/data/1 type ext4 (rw)" + os.linesep + \
+             "/dev/sda2 on /hadoop/hdfs/data/2 type ext4 (rw)"
+
+    out_array = [x.split(' ') for x in out.strip().split('\n')]
+    mount_val = []
+    for m in out_array:
+      if len(m) >= 6 and m[1] == "on" and m[3] == "type":
+        x = dict(
+          device=m[0],
+          mount_point=m[2],
+          fstype=m[4],
+          options=m[5][1:-1].split(',') if len(m[5]) >= 2 else []
+        )
+        mount_val.append(x)
+
+    return mount_val
+
+  def test_invalid(self):
+    """
+    Testing when parameters are invalid or missing.
+    """
+    mount_point = file_system.get_mount_point_for_dir(None)
+    self.assertEqual(mount_point, None)
+
+    mount_point = file_system.get_mount_point_for_dir("")
+    self.assertEqual(mount_point, None)
+
+    mount_point = file_system.get_mount_point_for_dir("  ")
+    self.assertEqual(mount_point, None)
+
+
+  @patch('resource_management.core.providers.mount.get_mounted')
+  def test_at_root(self, mounted_mock):
+    """
+    Testing when the path is mounted on the root.
+    """
+    mounted_mock.return_value = self._get_mount(self.MOUNT_TYPE.SINGLE_ROOT)
+
+    mount_point = file_system.get_mount_point_for_dir("/hadoop/hdfs/data")
+    self.assertEqual(mount_point, "/")
+
+
+  @patch('resource_management.core.providers.mount.get_mounted')
+  def test_at_drive(self, mounted_mock):
+    """
+    Testing when the path is mounted on a virtual file system not at the root.
+    """
+    mounted_mock.return_value = self._get_mount(self.MOUNT_TYPE.MULT_DRIVE_DISTINCT)
+
+    mount_point = file_system.get_mount_point_for_dir("/hadoop/hdfs/data/1")
+    self.assertEqual(mount_point, "/hadoop/hdfs/data/1")
+
+    mount_point = file_system.get_mount_point_for_dir("/hadoop/hdfs/data/2")
+    self.assertEqual(mount_point, "/hadoop/hdfs/data/2")
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestPackageResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestPackageResource.py b/ambari-agent/src/test/python/resource_management/TestPackageResource.py
index 08c7ac3..66bfa83 100644
--- a/ambari-agent/src/test/python/resource_management/TestPackageResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestPackageResource.py
@@ -17,26 +17,48 @@ limitations under the License.
 '''
 
 from unittest import TestCase
-from mock.mock import patch, MagicMock
+from mock.mock import patch, MagicMock, call
 
 from resource_management.core import Environment, Fail
 from resource_management.core.system import System
 from resource_management.core.resources import Package
 
 from resource_management.core import shell
+from resource_management.core.providers.package.apt import replace_underscores
 
 class TestPackageResource(TestCase):
-
   @patch.object(shell, "call")
   @patch.object(shell, "checked_call")
-  @patch.object(System, "os_family", new = 'debian')
-  def test_action_install_debian(self, shell_mock, call_mock):
+  @patch.object(System, "os_family", new = 'ubuntu')
+  def test_action_install_ubuntu_update(self, shell_mock, call_mock):
     call_mock.return_value= (1, None)
     with Environment('/') as env:
       Package("some_package",
       )
-    call_mock.assert_called_with('dpkg --get-selections some_package | grep -v deinstall')
-    shell_mock.assert_called_with("env DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get -q -o Dpkg::Options::='--force-confdef' --allow-unauthenticated --assume-yes install some_package")
+    call_mock.assert_has_calls([call("dpkg --get-selections some-package | grep -v deinstall"),
+                                call("DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get -q -o Dpkg::Options::='--force-confdef'"
+                                      " --allow-unauthenticated --assume-yes install some-package"),
+                                call("apt-get update -qq")
+                              ])
+
+    shell_mock.assert_has_calls([call("DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get -q -o Dpkg::Options::='--force-confdef' --allow-unauthenticated --assume-yes install some-package")
+                              ])
+
+  @patch.object(shell, "call")
+  @patch.object(shell, "checked_call")
+  @patch.object(System, "os_family", new = 'ubuntu')
+  def test_action_install_ubuntu(self, shell_mock, call_mock):
+    call_mock.side_effect = [(1, None), (0, None)]
+    with Environment('/') as env:
+      Package("some_package",
+      )
+    call_mock.assert_has_calls([call("dpkg --get-selections some-package | grep -v deinstall"),
+                                call("DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get -q -o Dpkg::Options::='--force-confdef'"
+                                      " --allow-unauthenticated --assume-yes install some-package")
+                              ])
+
+    self.assertEqual(shell_mock.call_count, 0, "shell.checked_call shouldn't be called")
+
 
 
   @patch.object(shell, "call")
@@ -108,3 +130,12 @@ class TestPackageResource(TestCase):
               version = "3.5.0"
       )
     shell_mock.assert_called_with("/usr/bin/yum -d 0 -e 0 -y install some_package-3.5.0")
+
+  @replace_underscores
+  def func_to_test(self, name):
+    return name
+
+  def testReplaceUnderscore(self):
+    self.assertEqual("-", self.func_to_test("_"))
+    self.assertEqual("hadoop-x-x-x-*", self.func_to_test("hadoop_x_x_x-*"))
+    self.assertEqual("hadoop", self.func_to_test("hadoop"))

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
index e381e9a..4e4871a 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -123,8 +123,8 @@ class TestRepositoryResource(TestCase):
     @patch("os.path.isfile", new=MagicMock(return_value=True))
     @patch("filecmp.cmp", new=MagicMock(return_value=False))
     @patch.object(System, "os_release_name", new='precise')        
-    @patch.object(System, "os_family", new='debian')
-    def test_create_repo_debian_repo_exists(self, file_mock, execute_mock, 
+    @patch.object(System, "os_family", new='ubuntu')
+    def test_create_repo_ubuntu_repo_exists(self, file_mock, execute_mock,
                                             tempfile_mock, checked_call_mock):
       tempfile_mock.return_value = MagicMock(spec=file)
       tempfile_mock.return_value.__enter__.return_value.name = "/tmp/1.txt"
@@ -160,8 +160,8 @@ class TestRepositoryResource(TestCase):
     @patch("os.path.isfile", new=MagicMock(return_value=True))
     @patch("filecmp.cmp", new=MagicMock(return_value=True))
     @patch.object(System, "os_release_name", new='precise')        
-    @patch.object(System, "os_family", new='debian')
-    def test_create_repo_debian_doesnt_repo_exist(self, file_mock, execute_mock, tempfile_mock):
+    @patch.object(System, "os_family", new='ubuntu')
+    def test_create_repo_ubuntu_doesnt_repo_exist(self, file_mock, execute_mock, tempfile_mock):
       tempfile_mock.return_value = MagicMock(spec=file)
       tempfile_mock.return_value.__enter__.return_value.name = "/tmp/1.txt"
       
@@ -186,10 +186,10 @@ class TestRepositoryResource(TestCase):
       
     
     @patch("os.path.isfile", new=MagicMock(return_value=True))
-    @patch.object(System, "os_family", new='debian')
+    @patch.object(System, "os_family", new='ubuntu')
     @patch("resource_management.libraries.providers.repository.Execute")
     @patch("resource_management.libraries.providers.repository.File")
-    def test_remove_repo_debian_repo_exist(self, file_mock, execute_mock):
+    def test_remove_repo_ubuntu_repo_exist(self, file_mock, execute_mock):
       with Environment('/') as env:
           Repository('HDP',
                      action = "remove",
@@ -200,10 +200,10 @@ class TestRepositoryResource(TestCase):
       self.assertEqual(execute_mock.call_args[0][0], 'apt-get update -qq -o Dir::Etc::sourcelist="sources.list.d/HDP.list" -o APT::Get::List-Cleanup="0"')
 
     @patch("os.path.isfile", new=MagicMock(return_value=False))
-    @patch.object(System, "os_family", new='debian')
+    @patch.object(System, "os_family", new='ubuntu')
     @patch("resource_management.libraries.providers.repository.Execute")
     @patch("resource_management.libraries.providers.repository.File")
-    def test_remove_repo_debian_repo_doenst_exist(self, file_mock, execute_mock):
+    def test_remove_repo_ubuntu_repo_doenst_exist(self, file_mock, execute_mock):
       with Environment('/') as env:
           Repository('HDP',
                      action = "remove",

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestUserResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestUserResource.py b/ambari-agent/src/test/python/resource_management/TestUserResource.py
index 859b111..63aa40d 100644
--- a/ambari-agent/src/test/python/resource_management/TestUserResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestUserResource.py
@@ -36,8 +36,7 @@ class TestUserResource(TestCase):
     popen_mock.return_value = subproc_mock
     getpwnam_mock.return_value = None
     with Environment('/') as env:
-      user = User("mapred", action = "create")
-    
+      user = User("mapred", action = "create", shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'useradd -m -s /bin/bash mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -51,8 +50,7 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred", action = "create")
-    
+      user = User("mapred", action = "create", shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/bash mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -66,8 +64,7 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred", action = "remove")
-    
+      user = User("mapred", action = "remove", shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'userdel mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -81,10 +78,8 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  comment = "testComment")
-    
+      user = User("mapred", action = "create", comment = "testComment",
+          shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -c testComment -s /bin/bash mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -98,10 +93,8 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  home = "/test/home")
-    
+      user = User("mapred", action = "create", home = "/test/home",
+          shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/bash -d /test/home mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -115,10 +108,8 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  password = "secure")
-    
+      user = User("mapred", action = "create", password = "secure",
+          shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/bash -p secure mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -132,10 +123,7 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  shell = "/bin/sh")
-    
+      user = User("mapred", action = "create", shell = "/bin/sh")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/sh mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -149,10 +137,7 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  uid = "1")
-    
+      user = User("mapred", action = "create", uid = "1", shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/bash -u 1 mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -166,10 +151,7 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  gid = "1")
-    
+      user = User("mapred", action = "create", gid = "1", shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -s /bin/bash -g 1 mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
@@ -183,10 +165,21 @@ class TestUserResource(TestCase):
     getpwnam_mock.return_value = 1
 
     with Environment('/') as env:
-      user = User("mapred",
-                  action = "create",
-                  groups = ['1','2','3'])
-    
+      user = User("mapred", action = "create", groups = ['1','2','3'],
+          shell = "/bin/bash")
 
     popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'usermod -G 1,2,3 -s /bin/bash mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
     self.assertEqual(popen_mock.call_count, 1)
+
+  @patch.object(subprocess, "Popen")
+  @patch.object(pwd, "getpwnam")
+  def test_missing_shell_argument(self, getpwnam_mock, popen_mock):
+    subproc_mock = MagicMock()
+    subproc_mock.returncode = 0
+    popen_mock.return_value = subproc_mock
+    getpwnam_mock.return_value = None
+    with Environment('/') as env:
+      user = User("mapred", action = "create")
+
+    popen_mock.assert_called_with(['/bin/bash', '--login', '-c', 'useradd -m mapred'], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env=None, cwd=None)
+    self.assertEqual(popen_mock.call_count, 1)

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
index db9bb6c..e7a61e4 100644
--- a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
@@ -61,8 +61,9 @@ class TestXmlConfigResource(TestCase):
     with Environment('/') as env:
       XmlConfig('file.xml',
                 conf_dir='/dir/conf',
-                configurations={}
-      )
+                configurations={},
+                configuration_attributes={}
+                )
 
     open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
     result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n  </configuration>\n')
@@ -93,11 +94,12 @@ class TestXmlConfigResource(TestCase):
     with Environment('/') as env:
       XmlConfig('file.xml',
                 conf_dir='/dir/conf',
-                configurations={'property1': 'value1'}
-      )
+                configurations={'property1': 'value1'},
+                configuration_attributes={'attr': {'property1': 'attr_value'}}
+                )
 
     open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
-    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n    <property>\n      <name>property1</name>\n      <value>value1</value>\n    </property>\n    \n  </configuration>\n')
+    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n    <property>\n      <name>property1</name>\n      <value>value1</value>\n      <attr>attr_value</attr>\n    </property>\n    \n  </configuration>\n')
 
 
   @patch("resource_management.core.providers.system._ensure_metadata")
@@ -131,8 +133,88 @@ class TestXmlConfigResource(TestCase):
                                 "prop.2": "INFO, openjpa",
                                 "prop.4": "${oozie.log.dir}/oozie.log",
                                 "prop.empty": "",
-                },
-      )
+                                },
+                configuration_attributes={
+                    "": {
+                        "prop.1": "should_not_be_printed",
+                        "prop.2": "should_not_be_printed",
+                    },
+                    "attr1": {
+                        "prop.1": "x",
+                        "prop.8": "not_existed",
+                    },
+                    "attr2": {
+                        "prop.4": "value4",
+                        "prop.3": "value3"
+                    },
+                    "attr_empty": {
+                    },
+                    "attr_value_empty": {
+                        "prop.4": "",
+                        "prop.empty": ""
+                    }
+                })
+
+    open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
+    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n    <property>\n      <name></name>\n      <value></value>\n    </property>\n    \n    <property>\n      <name>prop.1</name>\n      <value>&#39;.&#39;yyyy-MM-dd-HH</value>\n      <attr1>x</attr1>\n    </property>\n    \n    <property>\n      <name>prop.2</name>\n      <value>INFO, openjpa</value>\n    </property>\n    \n    <property>\n      <name>prop.3</name>\n      <value>%d{ISO8601} %5p %c{1}:%L - %m%n</value>\n      <attr2>value3</attr2>\n    </property>\n    \n    <property>\n      <name>prop.4</name>\n      <value>${oozie.log.dir}/oozie.log</value>\n      <attr_value_empty></attr_value_empty>\n      <attr2>value4</attr2>\n    </property>\n    \n    <property>\n      <name>prop.empty</name>\n      <value></value>\n      <attr_value_empty></attr_value_empty>\n    </property>\n    \n  </configuration>\n')
+
+  @patch("resource_management.core.providers.system._ensure_metadata")
+  @patch("__builtin__.open")
+  @patch.object(os.path, "exists")
+  @patch.object(os.path, "isdir")
+  @patch.object(time, "asctime")
+  def test_action_create_xml_config_sorted_by_key(self,
+                                                  time_asctime_mock,
+                                                  os_path_isdir_mock,
+                                                  os_path_exists_mock,
+                                                  open_mock,
+                                                  ensure_mock):
+    """
+    Tests if 'create' action - creates new non existent xml file and writes proper data
+    where configurations={"Key":"Value"} are stored in sorted by key order
+    """
+    os_path_isdir_mock.side_effect = [False, True]
+    os_path_exists_mock.return_value = False
+    time_asctime_mock.return_value = 'Wed 2014-02'
+
+    result_file = MagicMock()
+    open_mock.return_value = result_file
+
+    with Environment('/') as env:
+      XmlConfig('file.xml',
+                conf_dir='/dir/conf',
+                configurations={"": "",
+                                "third": "should be third",
+                                "first": "should be first",
+                                "z_last": "should be last",
+                                "second": "should be second",
+                                },
+                configuration_attributes={}
+                )
 
     open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
-    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n    <property>\n      <name></name>\n      <value></value>\n    </property>\n    \n    <property>\n      <name>prop.empty</name>\n      <value></value>\n    </property>\n    \n    <property>\n      <name>prop.3</name>\n      <value>%d{ISO8601} %5p %c{1}:%L - %m%n</value>\n    </property>\n    \n    <property>\n      <name>prop.2</name>\n      <value>INFO, openjpa</value>\n    </property>\n    \n    <property>\n      <name>prop.1</name>\n      <value>&#39;.&#39;yyyy-MM-dd-HH</value>\n    </property>\n    \n    <property>\n      <name>prop.4</name>\n      <value>${oozie.log.dir}/oozie.log</value>\n    </property>\n    \n  </configuration>\n')
+    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n    \n    <property>\n      <name></name>\n      <value></value>\n    </property>\n    \n    <property>\n      <name>first</name>\n      <value>should be first</value>\n    </property>\n    \n    <property>\n      <name>second</name>\n      <value>should be second</value>\n    </property>\n    \n    <property>\n      <name>third</name>\n      <value>should be third</value>\n    </property>\n    \n    <property>\n      <name>z_last</name>\n      <value>should be last</value>\n    </property>\n    \n  </configuration>\n')
+
+  @patch("resource_management.libraries.providers.xml_config.File")
+  @patch.object(os.path, "exists")
+  @patch.object(os.path, "isdir")
+  def test_action_create_arguments(self, os_path_isdir_mock ,os_path_exists_mock, file_mock):
+
+    os_path_isdir_mock.side_effect = [False, True]
+    os_path_exists_mock.return_value = False
+
+    with Environment() as env:
+      XmlConfig('xmlFile.xml',
+                conf_dir='/dir/conf',
+                configurations={'property1': 'value1'},
+                configuration_attributes={'attr': {'property1': 'attr_value'}},
+                mode = 0755,
+                owner = "hdfs",
+                group = "hadoop",
+                encoding = "Code"
+      )
+
+    self.assertEqual(file_mock.call_args[0][0],'/dir/conf/xmlFile.xml')
+    call_args = file_mock.call_args[1].copy()
+    del call_args['content']
+    self.assertEqual(call_args,{'owner': 'hdfs', 'group': 'hadoop', 'mode': 0755, 'encoding' : 'Code'})

http://git-wip-us.apache.org/repos/asf/ambari/blob/9213dcca/ambari-client/groovy-client/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/pom.xml b/ambari-client/groovy-client/pom.xml
index b05ed24..cc823de 100644
--- a/ambari-client/groovy-client/pom.xml
+++ b/ambari-client/groovy-client/pom.xml
@@ -53,6 +53,10 @@
       <artifactId>spock-core</artifactId>
       <version>0.7-groovy-2.0</version>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
   </dependencies>
   <build>
     <plugins>


Mime
View raw message