Sfoglia il codice sorgente

AMBARI-2988. It's misleading to say "NOTE: Restart Ambari Server to apply changes" when ambari-server setup-https fails (Dmytro Shkvyra via dlysnichenko)

Lisnichenko Dmitro 11 anni fa
parent
commit
8d46a38b57

+ 6 - 4
ambari-server/src/main/python/ambari-server.py

@@ -3029,11 +3029,11 @@ def setup_https(args):
         str(client_api_ssl_port), "^[0-9]{1,5}$", "Invalid port.", False, validatorFunction = is_valid_https_port))
         cert_was_imported = import_cert_and_key_action(security_server_keys_dir, properties)
        else:
-        return
+        return False
       
       if cert_must_import and not cert_was_imported:
         print 'Setup of HTTPS failed. Exiting.'
-        return
+        return False
 
       conf_file = find_properties_file()
       f = open(conf_file, 'w')
@@ -3042,6 +3042,7 @@ def setup_https(args):
       ambari_user = read_ambari_user()
       if ambari_user:
         adjust_directory_permissions(ambari_user)
+      return True
     except (KeyError), e:
       err = 'Property ' + str(e) + ' is not defined at ' + conf_file
       raise FatalException(1, err)
@@ -3573,6 +3574,7 @@ def main():
     parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + str(args_number_required))
 
   options.exit_message = "Ambari Server '%s' completed successfully." % action
+  need_restart = True
   try:
     if action == SETUP_ACTION:
       setup(options)
@@ -3596,7 +3598,7 @@ def main():
     elif action == UPDATE_METAINFO_ACTION:
       update_metainfo(options)
     elif action == SETUP_HTTPS_ACTION:
-      setup_https(options)
+      need_restart = setup_https(options)
     elif action == SETUP_GANGLIA_HTTPS_ACTION:
       setup_component_https("Ganglia", "setup-ganglia-https", GANGLIA_HTTPS, "ganglia_cert")
     elif action == SETUP_NAGIOS_HTTPS_ACTION:
@@ -3604,7 +3606,7 @@ def main():
     else:
       parser.error("Invalid action")
 
-    if action in ACTION_REQUIRE_RESTART:
+    if action in ACTION_REQUIRE_RESTART and need_restart:
       if is_server_runing():
         print 'NOTE: Restart Ambari Server to apply changes'+ \
               ' ("ambari-server restart|stop|start")'

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

@@ -204,6 +204,35 @@ class TestAmbariServer(TestCase):
     pass
 
 
+  @patch.object(ambari_server, 'is_server_runing')
+  @patch.object(ambari_server, 'setup_https')
+  @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_setup_https(self, OptionParserMock, reset_method, stop_method,
+                           start_method, setup_method, setup_https_method, is_server_runing_method):
+      opm = OptionParserMock.return_value
+      options = MagicMock()
+      args = ["setup-https"]
+      opm.parse_args.return_value = (options, args)
+      setup_https_method.return_value = False
+
+      options.database=None
+      options.sid_or_sname = "sid"
+      ambari_server.main()
+
+      self.assertTrue(setup_https_method.called)
+      self.assertEqual(is_server_runing_method.call_count, 0)
+      is_server_runing_method.reset()
+      setup_https_method.return_value = True
+      ambari_server.main()
+      self.assertTrue(setup_https_method.called)
+      self.assertEqual(is_server_runing_method.call_count, 1)
+      self.assertFalse(False, ambari_server.VERBOSE)
+      self.assertFalse(False, ambari_server.SILENT)
+
   @patch.object(ambari_server, 'setup')
   @patch.object(ambari_server, 'start')
   @patch.object(ambari_server, 'stop')