Updated Branches: refs/heads/trunk 964e5cf42 -> fb0527ffc
AMBARI-2745. All ambari-server operations that need ambari-server restart should say so. (Artem Baranchuk via smohanty) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/fb0527ff Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/fb0527ff Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/fb0527ff Branch: refs/heads/trunk Commit: fb0527ffcaea608bdb5df6e894c693d0a3cc8a66 Parents: 964e5cf Author: Sumit Mohanty <[email protected]> Authored: Wed Jul 31 12:47:00 2013 -0700 Committer: Sumit Mohanty <[email protected]> Committed: Wed Jul 31 12:47:07 2013 -0700 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 21 +++++++++++++------- .../src/test/python/TestAmbaryServer.py | 10 +++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fb0527ff/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 b3ddf40..b098a85 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -62,6 +62,8 @@ SETUP_GANGLIA_HTTPS_ACTION = "setup-ganglia-https" SETUP_NAGIOS_HTTPS_ACTION = "setup-nagios-https" ENCRYPT_PASSWORDS_ACTION = "encrypt-passwords" +ACTION_REQUIRE_RESTART = [RESET_ACTION, UPGRADE_ACTION, UPGRADE_STACK_ACTION, SETUP_HTTPS_ACTION, LDAP_SETUP_ACTION] + # selinux commands GET_SE_LINUX_ST_CMD = "/usr/sbin/sestatus" SE_SETENFORCE_CMD = "setenforce 0" @@ -3038,18 +3040,17 @@ def setup_https(args): conf_file = find_properties_file() f = open(conf_file, 'w') properties.store(f, "Changed by 'ambari-server setup-https' command") - if is_server_runing(): - print 'NOTE: Restart Ambari Server to apply changes'+\ - ' ("ambari-server restart|stop|start")' + + ambari_user = read_ambari_user() + if ambari_user: + adjust_directory_permissions(ambari_user) except (KeyError), e: err = 'Property ' + str(e) + ' is not defined at ' + conf_file raise FatalException(1, err) else: - print "setup-https is not enabled in silent mode." + warning = "setup-https is not enabled in silent mode." + raise NonFatalException(warning) - ambari_user = read_ambari_user() - if ambari_user: - adjust_directory_permissions(ambari_user) def is_server_runing(): if os.path.exists(PID_DIR + os.sep + PID_NAME): @@ -3603,6 +3604,12 @@ def main(): setup_component_https("Nagios", "setup-nagios-https", NAGIOS_HTTPS, "nagios_cert") else: parser.error("Invalid action") + + if action in ACTION_REQUIRE_RESTART: + if is_server_runing(): + print 'NOTE: Restart Ambari Server to apply changes'+ \ + ' ("ambari-server restart|stop|start")' + except FatalException as e: if e.reason is not None: print_error_msg("Exiting with exit code {0}. Reason: {1}".format(e.code, e.reason)) http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fb0527ff/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 a513e26..74c1166 100644 --- a/ambari-server/src/test/python/TestAmbaryServer.py +++ b/ambari-server/src/test/python/TestAmbaryServer.py @@ -1104,8 +1104,16 @@ class TestAmbariServer(TestCase): p.process_pair.reset_mock() p.get_property.reset_mock() p.store.reset_mock() - import_cert_and_key_action_mock.reset_mock() + import_cert_and_key_action_mock.reset_mock() + + #Case #5: if silent mode is enabled ambari_server.SILENT = True + try: + ambari_server.setup_https(args) + self.fail("Should throw exception") + except NonFatalException as fe: + self.assertTrue("setup-https is not enabled in silent mode" in fe.reason) + @patch.object(ambari_server, "import_cert_and_key") def test_import_cert_and_key_action(self, import_cert_and_key_mock):
