Browse Source

AMBARI-2737. Cleanup script --skip option does not allow to unskip users. (Andrew Onischuk via smohanty)

Sumit Mohanty 12 years ago
parent
commit
8666a165ef

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

@@ -365,7 +365,7 @@ class HostCleanup:
     return process.returncode, stdoutdata, stderrdata
 
 
-  def search_file(filename, search_path, pathsep=os.pathsep):
+  def search_file(self, filename, search_path, pathsep=os.pathsep):
     """ Given a search path, find file with requested name """
     for path in string.split(search_path, pathsep):
       candidate = os.path.join(path, filename)
@@ -419,7 +419,7 @@ def main():
   else:
     logging.basicConfig(level=logging.INFO)
 
-  if options.skip:
+  if options.skip is not None:
     global SKIP_LIST
     SKIP_LIST = options.skip.split(',')
 

+ 29 - 1
ambari-agent/src/test/python/TestHostCleanup.py

@@ -26,6 +26,8 @@ import StringIO
 import sys
 import tempfile
 import os.path
+import optparse
+import logging
 
 PACKAGE_SECTION = "packages"
 PACKAGE_KEY = "pkg_list"
@@ -94,7 +96,33 @@ created = 2013-07-02 20:39:22.162757"""
     self.assertTrue("hadoop-libhdfs.x86_64" in propMap["packages"])
     sys.stdout = sys.__stdout__
 
-
+  class HostCleanupOptions:
+    def __init__(self, outputfile, inputfile, skip, verbose):
+      self.outputfile = outputfile
+      self.inputfile = inputfile
+      self.skip = skip
+      self.verbose = False
+      
+  @patch.object(logging.FileHandler, 'setFormatter')
+  @patch.object(HostCleanup.HostCleanup,'read_host_check_file')
+  @patch.object(logging,'basicConfig')
+  @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):
+    parser_mock.return_value = (TestHostCleanup.HostCleanupOptions('/someoutputfile', '/someinputfile', '', False), [])
+    file_handler_mock.return_value = logging.FileHandler('') # disable creating real file
+    HostCleanup.main()
+    
+    # test --out
+    file_handler_mock.assert_called_with('/someoutputfile')
+    # test --skip
+    self.assertEquals([''],HostCleanup.SKIP_LIST)
+    #test --verbose
+    logging_mock.assert_called_with(level=logging.INFO)
+    # test --in
+    read_host_check_file_mock.assert_called_with('/someinputfile')
+    
+  
   @patch.object(HostCleanup.HostCleanup, 'do_erase_alternatives')
   @patch.object(HostCleanup.HostCleanup, 'find_repo_files_for_repos')
   @patch.object(HostCleanup.HostCleanup, 'get_os_type')