Repository: ambari Updated Branches: refs/heads/trunk d78c5b2f8 -> 704e11455
AMBARI-5577. Turn Off Maintenance Mode for HDFS does not work (problems with ambari-agent) (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/704e1145 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/704e1145 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/704e1145 Branch: refs/heads/trunk Commit: 704e114552e39417e3e3c9b974aa297d31320a7e Parents: d78c5b2 Author: Lisnichenko Dmitro <[email protected]> Authored: Mon Apr 28 22:30:19 2014 +0300 Committer: Lisnichenko Dmitro <[email protected]> Committed: Mon Apr 28 22:31:04 2014 +0300 ---------------------------------------------------------------------- .../python/ambari_agent/CommandStatusDict.py | 3 +- .../test/python/ambari_agent/TestActionQueue.py | 6 ++-- .../ambari_agent/TestCommandStatusDict.py | 38 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/704e1145/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py index 1da6e79..15e7e2e 100644 --- a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py +++ b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py @@ -102,8 +102,7 @@ class CommandStatusDict(): tmpout = '...' tmperr = '...' try: - with open(report['structuredOut'], 'r') as fp: - tmpstructuredout = json.load(fp) + tmpstructuredout = open(report['structuredOut'], 'r').read() except Exception: tmpstructuredout = '{}' grep = Grep() http://git-wip-us.apache.org/repos/asf/ambari/blob/704e1145/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py index 7dc80c7..b6b79b1 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py +++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py @@ -222,10 +222,9 @@ class TestActionQueue(TestCase): self.assertTrue(print_exc_mock.called) - @patch("json.load") @patch("__builtin__.open") @patch.object(ActionQueue, "status_update_callback") - def test_execute_command(self, status_update_callback_mock, open_mock, json_load_mock): + def test_execute_command(self, status_update_callback_mock, open_mock): # Make file read calls visible def open_side_effect(file, mode): if mode == 'r': @@ -235,7 +234,6 @@ class TestActionQueue(TestCase): else: return self.original_open(file, mode) open_mock.side_effect = open_side_effect - json_load_mock.return_value = '' config = AmbariConfig().getConfig() tempdir = tempfile.gettempdir() @@ -276,7 +274,7 @@ class TestActionQueue(TestCase): expected = {'status': 'IN_PROGRESS', 'stderr': 'Read from {0}/errors-3.txt'.format(tempdir), 'stdout': 'Read from {0}/output-3.txt'.format(tempdir), - 'structuredOut' : '', + 'structuredOut' : 'Read from {0}/structured-out-3.json'.format(tempdir), 'clusterName': u'cc', 'roleCommand': u'INSTALL', 'serviceName': u'HDFS', http://git-wip-us.apache.org/repos/asf/ambari/blob/704e1145/ambari-agent/src/test/python/ambari_agent/TestCommandStatusDict.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestCommandStatusDict.py b/ambari-agent/src/test/python/ambari_agent/TestCommandStatusDict.py index 77b8f1b..8751479 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestCommandStatusDict.py +++ b/ambari-agent/src/test/python/ambari_agent/TestCommandStatusDict.py @@ -125,3 +125,41 @@ class TestCommandStatusDict(TestCase): } self.assertEquals(report, expected) + @patch("__builtin__.open") + def test_structured_output(self, open_mock): + callback_mock = MagicMock() + commandStatuses = CommandStatusDict(callback_action = callback_mock) + file_mock = MagicMock(name = 'file_mock') + file_mock.__enter__.return_value = file_mock + file_mock.read.return_value = '{"var1":"test1", "var2":"test2"}' + open_mock.return_value = file_mock + command_in_progress1 = { + 'commandType': 'EXECUTION_COMMAND', + 'commandId': '1-1', + 'clusterName': u'cc', + 'exitCode': 777, + 'role': u'DATANODE', + 'roleCommand': u'INSTALL', + 'serviceName': u'HDFS', + 'stderr': '', + 'stdout': "notice: /Stage[1]/Hdp::Iptables/Service[iptables]/ensure: ensure changed 'running' to 'stopped'\nnotice: /Stage[1]/Hdp/File[/tmp/changeUid.sh]/ensure: defined content as '{md5}32b994a2e970f8acc3c91c198b484654'\nnotice: /Stage[1]/Hdp::Snappy::Package/Hdp::Package[snappy]/Hdp::Package::Process_pkg[snappy]/Package[snappy]/ensure: created\nnotice: /Stage[1]/Hdp/Hdp::Group[nagios_group]/Group[nagios_group]/ensure: created\nnotice: /Stage[1]/Hdp/Hdp::User[nagios_user]/User[nagios]/ensure: created\nnotice: /Stage[1]/Hdp::Snmp/Hdp::Package[snmp]/Hdp::Package::Process_pkg[snmp]/Package[net-snmp-utils]/ensure: created", + 'taskId': 5 + } + command_in_progress1_report = { + 'status': 'IN_PROGRESS', + 'taskId': 5, + 'structuredOut' : 'structured_out.tmp', + } + commandStatuses.put_command_status(command_in_progress1, command_in_progress1_report) + report = commandStatuses.generate_report() + expected = \ + {'componentStatus': [], + 'reports': [{'status': 'IN_PROGRESS', 'stderr': '...', + 'stdout': '...', 'clusterName': u'cc', + 'structuredOut': '{"var1":"test1", "var2":"test2"}', + 'roleCommand': u'INSTALL', + 'serviceName': u'HDFS', + 'role': u'DATANODE', + 'actionId': '1-1', 'taskId': 5, 'exitCode': 777}] + } + self.assertEquals(report, expected)
