瀏覽代碼

AMBARI-1899. ambari-reset does not respect -s. (swagle)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1467123 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Wagle 12 年之前
父節點
當前提交
4ab244b52e
共有 3 個文件被更改,包括 42 次插入11 次删除
  1. 2 0
      CHANGES.txt
  2. 5 7
      ambari-server/src/main/python/ambari-server.py
  3. 35 4
      ambari-server/src/test/python/TestAmbaryServer.py

+ 2 - 0
CHANGES.txt

@@ -692,6 +692,8 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1899. ambari-reset does not respect -s. (swagle)
+
  AMBARI-1898. Update stack definitions for 1.3.0. (smohanty)
 
  AMBARI-1886. Derived properties not being overridden for hosts. (srimanth)

+ 5 - 7
ambari-server/src/main/python/ambari-server.py

@@ -900,24 +900,22 @@ def setup(args):
 #
 def reset(args):
   okToRun = False
-  choice = raw_input("**** WARNING **** You are about to reset and clear the "
+  choice = get_YN_input("**** WARNING **** You are about to reset and clear the "
                      "Ambari Server database. This will remove all cluster "
                      "host and configuration information from the database. "
                      "You will be required to re-configure the Ambari server "
                      "and re-run the cluster wizard. \n"
                      "Are you SURE you want to perform the reset "
-                     "[yes/no]? ").lower()
-  if choice in set(['yes']):
-    okToRun = True
+                     "[yes/no]? ", True)
+  okToRun = choice
 
   if not okToRun:
     print "Ambari Server 'reset' cancelled"
     return -1
 
   okToRun = False
-  choice = raw_input("Confirm server reset [yes/no]? ").lower()
-  if choice in set(['yes']):
-    okToRun = True
+  choice = get_YN_input("Confirm server reset [yes/no]? ", True)
+  okToRun = choice
 
   if not okToRun:
     print "Ambari Server 'reset' cancelled"

+ 35 - 4
ambari-server/src/test/python/TestAmbaryServer.py

@@ -23,6 +23,7 @@ from mock.mock import patch
 from mock.mock import MagicMock
 from mock.mock import create_autospec
 import os, errno, tempfile
+import signal
 import stat
 # We have to use this import HACK because the filename contains a dash
 ambari_server = __import__('ambari-server')
@@ -932,24 +933,24 @@ class TestAmbariServer(TestCase):
 
 
 
-  @patch("__builtin__.raw_input")
+  @patch.object(ambari_server, "get_YN_input")
   @patch.object(ambari_server, "setup_db")
   @patch.object(ambari_server, "print_info_msg")
   @patch.object(ambari_server, "run_os_command")
   @patch.object(ambari_server, "configure_postgres_username_password")
   def test_reset(self, configure_postgres_username_password_mock,
                  run_os_command_mock, print_info_msg_mock,
-                 setup_db_mock, raw_inputMock):
+                 setup_db_mock, get_YN_inputMock):
 
     out = StringIO.StringIO()
     sys.stdout = out
 
     args = MagicMock()
-    raw_inputMock.return_value = "No"
+    get_YN_inputMock.return_value = False
     rcode = ambari_server.reset(args)
     self.assertEqual(-1, rcode)
 
-    raw_inputMock.return_value = "yes"
+    get_YN_inputMock.return_value = True
     run_os_command_mock.return_value = (1, None, None)
     rcode = ambari_server.reset(args)
     self.assertEqual(1, rcode)
@@ -963,6 +964,36 @@ class TestAmbariServer(TestCase):
 
 
 
+  @patch.object(ambari_server, "setup_db")
+  @patch.object(ambari_server, "print_info_msg")
+  @patch.object(ambari_server, "run_os_command")
+  @patch.object(ambari_server, "configure_postgres_username_password")
+  def test_silent_reset(self, configure_postgres_username_password_mock,
+                 run_os_command_mock, print_info_msg_mock,
+                 setup_db_mock):
+
+    out = StringIO.StringIO()
+    sys.stdout = out
+
+    args = MagicMock()
+    ambari_server.SILENT = True
+    self.assertTrue(ambari_server.SILENT)
+    run_os_command_mock.return_value = (0, None, None)
+
+    def signal_handler(signum, frame):
+       self.fail("Timed out!")
+
+    signal.signal(signal.SIGALRM, signal_handler)
+    signal.alarm(5)
+    rcode = ambari_server.reset(args)
+    
+    self.assertEqual(None, rcode)
+    self.assertTrue(setup_db_mock.called)
+    
+    sys.stdout = sys.__stdout__
+
+
+
   @patch("os.kill")
   @patch("os.path.exists")
   @patch("__builtin__.open")