Browse Source

AMBARI-2200. ambari-server start script (ambari-server.py) will never use SERVER_START_CMD_DEBUG. (Chad Roberts via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1488110 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 12 years ago
parent
commit
a6281b4f9c

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

@@ -991,7 +991,8 @@ def start(args):
     print_error_msg ("Failed to stop iptables. Exiting")
     sys.exit(retcode)
 
-  command = SERVER_START_CMD.format(jdk_path, conf_dir, get_ambari_classpath())
+  command_base = SERVER_START_CMD_DEBUG if (SERVER_DEBUG_MODE or SERVER_START_DEBUG) else SERVER_START_CMD
+  command = command_base.format(jdk_path, conf_dir, get_ambari_classpath())
   print "Running server: " + command
   server_process = subprocess.Popen(["/bin/sh", "-c", command])
   f = open(PID_DIR + os.sep + PID_NAME, "w")
@@ -1265,6 +1266,8 @@ def main():
   parser.add_option("-b", "--remote-database",
       action="store_true", dest="remote_database", default=False,
       help="Set up remote database instead of local")
+  parser.add_option('-g', '--debug', action="store_true", dest='debug', default=False,
+                  help="Start ambari-server in debug mode")
 
   (options, args) = parser.parse_args()
 
@@ -1280,6 +1283,9 @@ def main():
   global REMOTE_DATABASE
   REMOTE_DATABASE = options.remote_database
 
+  # debug mode
+  global SERVER_DEBUG_MODE
+  SERVER_DEBUG_MODE = options.debug
 
 
 

+ 46 - 0
ambari-server/src/test/python/TestAmbaryServer.py

@@ -384,6 +384,52 @@ class TestAmbariServer(TestCase):
     self.assertFalse(False, ambari_server.SILENT)
 
 
+   
+  @patch.object(ambari_server, 'setup')
+  @patch.object(ambari_server, 'start')
+  @patch.object(ambari_server, 'stop')
+  @patch.object(ambari_server, 'reset')
+  @patch('optparse.OptionParser')
+  def test_main_test_start_debug_short(self, OptionParserMock, reset_method, stop_method,
+                           start_method, setup_method):
+    opm = OptionParserMock.return_value
+    options = MagicMock()
+    args = ["start", "-g"]
+    opm.parse_args.return_value = (options, args)
+
+    ambari_server.main()
+
+    self.assertFalse(setup_method.called)
+    self.assertTrue(start_method.called)
+    self.assertFalse(stop_method.called)
+    self.assertFalse(reset_method.called)
+
+    self.assertTrue(ambari_server.SERVER_DEBUG_MODE)  
+
+
+
+  @patch.object(ambari_server, 'setup')
+  @patch.object(ambari_server, 'start')
+  @patch.object(ambari_server, 'stop')
+  @patch.object(ambari_server, 'reset')
+  @patch('optparse.OptionParser')
+  def test_main_test_start_debug_long(self, OptionParserMock, reset_method, stop_method,
+                           start_method, setup_method):
+    opm = OptionParserMock.return_value
+    options = MagicMock()
+    args = ["start", "--debug"]
+    opm.parse_args.return_value = (options, args)
+
+    ambari_server.main()
+
+    self.assertFalse(setup_method.called)
+    self.assertTrue(start_method.called)
+    self.assertFalse(stop_method.called)
+    self.assertFalse(reset_method.called)
+
+    self.assertTrue(ambari_server.SERVER_DEBUG_MODE)        
+
+
 
   @patch.object(ambari_server, 'setup')
   @patch.object(ambari_server, 'start')