Updated Branches: refs/heads/trunk cfa2f7f30 -> 758bbc1ac
AMBARI-2988. It's misleading to say "NOTE: Restart Ambari Server to apply changes" when ambari-server setup-https fails (Dmytro Shkvyra via dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/8d46a38b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/8d46a38b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/8d46a38b Branch: refs/heads/trunk Commit: 8d46a38b57f57970e8c8a62e91058d8171850167 Parents: cfa2f7f Author: Lisnichenko Dmitro <[email protected]> Authored: Thu Aug 22 17:58:33 2013 +0300 Committer: Lisnichenko Dmitro <[email protected]> Committed: Thu Aug 22 17:58:33 2013 +0300 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 10 ++++--- .../src/test/python/TestAmbaryServer.py | 29 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/8d46a38b/ambari-server/src/main/python/ambari-server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py index 99a341b..afbe501 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/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")' http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/8d46a38b/ambari-server/src/test/python/TestAmbaryServer.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestAmbaryServer.py b/ambari-server/src/test/python/TestAmbaryServer.py index 4786ca0..a671123 100644 --- a/ambari-server/src/test/python/TestAmbaryServer.py +++ b/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')
