Updated Branches: refs/heads/trunk 9886890e3 -> d8d308e6a
AMBARI-4279. Status commands are not executed for new services (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d8d308e6 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d8d308e6 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d8d308e6 Branch: refs/heads/trunk Commit: d8d308e6aa9e7c2d5957d48d6a84860156d16283 Parents: 9886890 Author: Lisnichenko Dmitro <[email protected]> Authored: Tue Jan 14 23:15:55 2014 +0200 Committer: Lisnichenko Dmitro <[email protected]> Committed: Tue Jan 14 23:16:53 2014 +0200 ---------------------------------------------------------------------- .../src/main/python/ambari_agent/LiveStatus.py | 49 ++++++++++---------- .../test/python/ambari_agent/TestLiveStatus.py | 29 ++++++++++++ 2 files changed, 53 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d8d308e6/ambari-agent/src/main/python/ambari_agent/LiveStatus.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/LiveStatus.py b/ambari-agent/src/main/python/ambari_agent/LiveStatus.py index cfb11f7..c95b96d 100644 --- a/ambari-agent/src/main/python/ambari_agent/LiveStatus.py +++ b/ambari-agent/src/main/python/ambari_agent/LiveStatus.py @@ -150,31 +150,30 @@ class LiveStatus: livestatus = None component = {"serviceName" : self.service, "componentName" : self.component} - if component in self.COMPONENTS + self.CLIENT_COMPONENTS : - if forsed_component_status: # If already determined - status = forsed_component_status # Nothing to do - elif component in self.CLIENT_COMPONENTS: - status = self.DEAD_STATUS # CLIENT components can't have status STARTED - else: - statusCheck = StatusCheck(AmbariConfig.servicesToPidNames, - AmbariConfig.pidPathesVars, self.globalConfig, - AmbariConfig.servicesToLinuxUser) - serviceStatus = statusCheck.getStatus(self.component) - if serviceStatus is None: - logger.warn("There is no service to pid mapping for " + self.component) - status = self.LIVE_STATUS if serviceStatus else self.DEAD_STATUS - - livestatus ={"componentName" : self.component, - "msg" : "", - "status" : status, - "clusterName" : self.cluster, - "serviceName" : self.service, - "stackVersion": self.versionsHandler. - read_stack_version(self.component) - } - active_config = self.actualConfigHandler.read_actual_component(self.component) - if not active_config is None: - livestatus['configurationTags'] = active_config + if forsed_component_status: # If already determined + status = forsed_component_status # Nothing to do + elif component in self.CLIENT_COMPONENTS: + status = self.DEAD_STATUS # CLIENT components can't have status STARTED + elif component in self.COMPONENTS: + statusCheck = StatusCheck(AmbariConfig.servicesToPidNames, + AmbariConfig.pidPathesVars, self.globalConfig, + AmbariConfig.servicesToLinuxUser) + serviceStatus = statusCheck.getStatus(self.component) + if serviceStatus is None: + logger.warn("There is no service to pid mapping for " + self.component) + status = self.LIVE_STATUS if serviceStatus else self.DEAD_STATUS + + livestatus ={"componentName" : self.component, + "msg" : "", + "status" : status, + "clusterName" : self.cluster, + "serviceName" : self.service, + "stackVersion": self.versionsHandler. + read_stack_version(self.component) + } + active_config = self.actualConfigHandler.read_actual_component(self.component) + if not active_config is None: + livestatus['configurationTags'] = active_config logger.debug("The live status for component " + str(self.component) +\ " of service " + str(self.service) + " is " + str(livestatus)) http://git-wip-us.apache.org/repos/asf/ambari/blob/d8d308e6/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py index a025f6e..4266236 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py +++ b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py @@ -25,6 +25,9 @@ import socket import os, sys, StringIO from ambari_agent import ActualConfigHandler from mock.mock import patch, MagicMock, call +import pprint +from ambari_agent import StatusCheck + class TestLiveStatus(TestCase): @@ -70,3 +73,29 @@ class TestLiveStatus(TestCase): self.assertTrue(len(result) > 0, 'Livestatus should not be empty') self.assertTrue(result['status'], LiveStatus.DEAD_STATUS) + + @patch.object(ActualConfigHandler.ActualConfigHandler, "read_actual_component") + @patch.object(StatusCheck.StatusCheck, "getStatus") + def test_build_predefined(self, getStatus_mock, read_actual_component_mock): + read_actual_component_mock.return_value = "actual_component" + """ + Tests that if live status us defined (using default parameter), + then no StatusCheck is executed + """ + config = AmbariConfig().getConfig() + config.set('agent', 'prefix', "ambari_agent" + os.sep + "dummy_files") + livestatus = LiveStatus('', 'SOME_UNKNOWN_SERVICE', + 'SOME_UNKNOWN_COMPONENT', {}, config) + livestatus.versionsHandler.versionsFilePath = "ambari_agent" + \ + os.sep + "dummy_files" + os.sep + "dummy_current_stack" + result = livestatus.build(forsed_component_status = "STARTED") + result_str = pprint.pformat(result) + self.assertEqual(result_str, + "{'clusterName': '',\n " + "'componentName': 'SOME_UNKNOWN_COMPONENT',\n " + "'configurationTags': 'actual_component',\n " + "'msg': '',\n 'serviceName': 'SOME_UNKNOWN_SERVICE',\n " + "'stackVersion': '',\n 'status': 'STARTED'}") + self.assertFalse(getStatus_mock.called) + +
