Repository: ambari Updated Branches: refs/heads/branch-2.1 5f22554ee -> 12f9d0764
AMBARI-7591 - Ambari-server Should Return Correct System Level Run Code (stoader via jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/12f9d076 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/12f9d076 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/12f9d076 Branch: refs/heads/branch-2.1 Commit: 12f9d0764e43bd11bb06b48312bd226c628a6176 Parents: 5f22554 Author: Jonathan Hurley <jhur...@hortonworks.com> Authored: Thu Nov 19 14:38:13 2015 -0500 Committer: Jonathan Hurley <jhur...@hortonworks.com> Committed: Thu Nov 19 14:40:06 2015 -0500 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 15 ++++-- .../src/test/python/TestAmbariServer.py | 54 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/12f9d076/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 9f8f925..8be79a5 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -159,13 +159,16 @@ def stop(args): # @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY) def status(args): - from ambari_windows_service import AmbariServerService - args.exit_message = None + status, statusStr = is_server_runing() - statusStr = AmbariServerService.QueryStatus() print "Ambari Server is " + statusStr + if status: + args.exit_code = 0 + else: + args.exit_code = 3 + # # The Ambari Server status. # @@ -175,10 +178,12 @@ def status(args): status, pid = is_server_runing() pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME) if status: + args.exit_code = 0 print "Ambari Server running" print "Found Ambari Server PID: " + str(pid) + " at: " + pid_file_path else: print "Ambari Server not running. Stale PID File at: " + pid_file_path + args.exit_code = 3 def refresh_stack_hash_action(): @@ -571,6 +576,7 @@ def main(options, args, parser): parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args) options.exit_message = "Ambari Server '%s' completed successfully." % action + options.exit_code = None try: action_obj.execute() @@ -599,6 +605,9 @@ def main(options, args, parser): if options.exit_message is not None: print options.exit_message + if options.exit_code is not None: # not all actions may return a system exit code + sys.exit(options.exit_code) + def mainBody(): parser = optparse.OptionParser(usage="usage: %prog [options] action [stack_id os]",) init_parser_options(parser) http://git-wip-us.apache.org/repos/asf/ambari/blob/12f9d076/ambari-server/src/test/python/TestAmbariServer.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py index d38dc4e..bc23402 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -6821,4 +6821,58 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV 'org.apache.ambari.server.update.HostUpdateHelper /testFileWithChanges > ' '/var/log/ambari-server/ambari-server.out 2>&1') + pass + + @not_for_platform(PLATFORM_WINDOWS) + @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) + @patch.object(_ambari_server_, "is_server_runing") + @patch("optparse.OptionParser") + def test_main_test_status_running(self, optionParserMock, is_server_runing_method): + opm = optionParserMock.return_value + options = MagicMock() + del options.exit_message + + args = ["status"] + opm.parse_args.return_value = (options, args) + + is_server_runing_method.return_value = (True, 100) + + options.dbms = None + options.sid_or_sname = "sid" + + try: + _ambari_server_.mainBody() + except SystemExit as e: + self.assertTrue(e.code == 0) + + self.assertTrue(is_server_runing_method.called) + pass + + + @not_for_platform(PLATFORM_WINDOWS) + @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value)) + @patch.object(_ambari_server_, "is_server_runing") + @patch("optparse.OptionParser") + def test_main_test_status_not_running(self, optionParserMock, is_server_runing_method): + opm = optionParserMock.return_value + options = MagicMock() + del options.exit_message + + args = ["status"] + opm.parse_args.return_value = (options, args) + + is_server_runing_method.return_value = (False, None) + + options.dbms = None + options.sid_or_sname = "sid" + + try: + _ambari_server_.mainBody() + except SystemExit as e: + self.assertTrue(e.code == 3) + + self.assertTrue(is_server_runing_method.called) + pass + +