You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2014/01/27 12:20:43 UTC
git commit: AMBARI-4354. HostCleanup should also clean /tmp/hadoop-*
(Dmytro Shkvyra via dlysnichenko)
Updated Branches:
refs/heads/trunk 930c8d909 -> 78559508e
AMBARI-4354. HostCleanup should also clean /tmp/hadoop-* (Dmytro Shkvyra via dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/78559508
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/78559508
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/78559508
Branch: refs/heads/trunk
Commit: 78559508e6738380e1e71c71d7f42aa725cc53e5
Parents: 930c8d9
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Jan 27 13:15:21 2014 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Jan 27 13:15:21 2014 +0200
----------------------------------------------------------------------
.../src/main/python/ambari_agent/HostCleanup.py | 25 +++++++++++++++++++-
.../test/python/ambari_agent/TestHostCleanup.py | 6 +++--
2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/78559508/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
index 593ad16..83429de 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
@@ -58,6 +58,7 @@ USER_HOMEDIR_SECTION = "usr_homedir"
REPO_SECTION = "repositories"
REPOS_KEY = "repo_list"
DIR_SECTION = "directories"
+ADDITIONAL_DIRS = "additional_directories"
DIR_KEY = "dir_list"
PROCESS_SECTION = "processes"
PROCESS_KEY = "proc_list"
@@ -65,6 +66,10 @@ ALT_SECTION = "alternatives"
ALT_KEYS = ["symlink_list", "target_list"]
HADOOP_GROUP = "hadoop"
FOLDER_LIST = ["/tmp"]
+# Additional path patterns to find existing directory
+DIRNAME_PATTERNS = [
+ "/tmp/hadoop-", "/tmp/hsperfdata_"
+]
# resources that should not be cleaned
REPOSITORY_BLACK_LIST = ["ambari.repo"]
@@ -85,6 +90,20 @@ class HostCleanup:
logger.warn(err)
return config
+ def get_additional_dirs(self):
+ resultList = []
+ dirList = set()
+ for patern in DIRNAME_PATTERNS:
+ dirList.add(os.path.dirname(patern))
+
+ for folder in dirList:
+ for dirs in os.walk(folder):
+ for dir in dirs:
+ for patern in DIRNAME_PATTERNS:
+ if patern in dir:
+ resultList.append(dir)
+ return resultList
+
def do_cleanup(self, argMap=None):
if argMap:
packageList = argMap.get(PACKAGE_SECTION)
@@ -94,6 +113,7 @@ class HostCleanup:
repoList = argMap.get(REPO_SECTION)
procList = argMap.get(PROCESS_SECTION)
alt_map = argMap.get(ALT_SECTION)
+ additionalDirList = self.get_additional_dirs()
if userList and not USER_SECTION in SKIP_LIST:
userIds = self.get_user_ids(userList)
@@ -111,6 +131,9 @@ class HostCleanup:
if dirList and not DIR_SECTION in SKIP_LIST:
logger.info("\n" + "Deleting directories: " + str(dirList))
self.do_erase_dir_silent(dirList)
+ if additionalDirList and not ADDITIONAL_DIRS in SKIP_LIST:
+ logger.info("\n" + "Deleting additional directories: " + str(dirList))
+ self.do_erase_dir_silent(additionalDirList)
if repoList and not REPO_SECTION in SKIP_LIST:
repoFiles = self.find_repo_files_for_repos(repoList)
logger.info("\n" + "Deleting repo files: " + str(repoFiles))
@@ -530,4 +553,4 @@ def main():
if __name__ == '__main__':
- main()
\ No newline at end of file
+ main()
http://git-wip-us.apache.org/repos/asf/ambari/blob/78559508/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 94d1715..568711b 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
@@ -170,6 +170,7 @@ created = 2013-07-02 20:39:22.162757"""
read_host_check_file_mock.assert_called_with('/someinputfile')
self.assertFalse(get_yn_input_mock.called)
+ @patch.object(HostCleanup.HostCleanup, 'get_additional_dirs')
@patch.object(HostCleanup.HostCleanup, 'do_erase_alternatives')
@patch.object(HostCleanup.HostCleanup, 'find_repo_files_for_repos')
@patch.object(HostCleanup.HostCleanup, 'get_os_type')
@@ -182,9 +183,10 @@ created = 2013-07-02 20:39:22.162757"""
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):
+ do_erase_alternatives_method, get_additional_dirs_method):
out = StringIO.StringIO()
sys.stdout = out
+ get_additional_dirs_method.return_value = ['/tmp/hadoop-nagios','/tmp/hsperfdata_007']
propertyMap = {PACKAGE_SECTION:['abcd', 'pqrst'], USER_SECTION:['abcd', 'pqrst'],
REPO_SECTION:['abcd', 'pqrst'], DIR_SECTION:['abcd', 'pqrst'],
PROCESS_SECTION:['abcd', 'pqrst'],
@@ -201,7 +203,7 @@ created = 2013-07-02 20:39:22.162757"""
self.assertTrue(do_erase_packages_method.called)
self.assertTrue(do_kill_processes_method.called)
self.assertTrue(do_erase_alternatives_method.called)
- calls = [call(['decf']), call(['abcd', 'pqrst'])]
+ calls = [call(['decf']), call(['abcd', 'pqrst']), call(['/tmp/hadoop-nagios','/tmp/hsperfdata_007'])]
do_erase_dir_silent_method.assert_has_calls(calls)
do_erase_packages_method.assert_called_once_with(['abcd', 'pqrst'])
do_erase_files_silent_method.assert_called_once_with(['abcd', 'pqrst'])