You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/05/03 21:46:42 UTC
ambari git commit: AMBARI-20924 - Old Status Command Structured
Output is Returned on Every Status Command Causing Upgrades to Fail
(jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk da9185ce3 -> b0d7f0016
AMBARI-20924 - Old Status Command Structured Output is Returned on Every Status Command Causing Upgrades to Fail (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b0d7f001
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b0d7f001
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b0d7f001
Branch: refs/heads/trunk
Commit: b0d7f001646fb2fcc502e0d980e20f4a8c6612d9
Parents: da9185c
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed May 3 13:58:30 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed May 3 17:46:35 2017 -0400
----------------------------------------------------------------------
.../python/resource_management/TestScript.py | 56 ++++++++++++++------
.../libraries/script/script.py | 7 +++
ambari-server/src/test/python/unitTests.py | 2 +-
3 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0d7f001/ambari-agent/src/test/python/resource_management/TestScript.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestScript.py b/ambari-agent/src/test/python/resource_management/TestScript.py
index 65f8c2d..d531314 100644
--- a/ambari-agent/src/test/python/resource_management/TestScript.py
+++ b/ambari-agent/src/test/python/resource_management/TestScript.py
@@ -17,27 +17,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
-import ConfigParser
-import os
-
-import pprint
-
-from unittest import TestCase
-import threading
-import tempfile
-import time
-from threading import Thread
-
-
import StringIO
-import sys, logging, pprint
-from ambari_agent import AgentException
+import sys, pprint
from resource_management.libraries.script import Script
from resource_management.core.environment import Environment
-from mock.mock import MagicMock, patch
-
+from mock.mock import patch
+from stacks.utils.RMFTestCase import *
+import logging
-class TestScript(TestCase):
+class TestScript(RMFTestCase):
def setUp(self):
# disable stdout
@@ -116,6 +104,40 @@ class TestScript(TestCase):
self.assertEqual(open_mock.call_count, 3)
self.assertEqual(Script.structuredOut, {"1": "3", "2": "2"})
+ @patch("__builtin__.open")
+ def test_status_commands_clear_structured_out(self, open_mock):
+ """
+ Tests that status commands will clear and stored structured output from prior status commands.
+ :param open_mock:
+ :return:
+ """
+ class MagicFile(object):
+ def read(self):
+ return "{}"
+
+ def write(self, data):
+ pass
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ pass
+
+ def __enter__(self):
+ return self
+
+ sys.argv = ["", "status", "foo.py", "", "", "INFO", ""]
+ open_mock.side_effect = [MagicFile()]
+
+ try:
+ with Environment(".", test_mode=True) as env:
+ script = Script()
+ Script.structuredOut = { "version" : "old_version" }
+ script.execute()
+ except:
+ pass
+
+ self.assertTrue(open_mock.called)
+ self.assertEquals({}, Script.structuredOut)
+
def tearDown(self):
# enable stdout
sys.stdout = sys.__stdout__
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0d7f001/ambari-common/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/script/script.py b/ambari-common/src/main/python/resource_management/libraries/script/script.py
index dc657fb..0dd9c02 100644
--- a/ambari-common/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-common/src/main/python/resource_management/libraries/script/script.py
@@ -290,6 +290,13 @@ class Script(object):
if OSCheck.is_windows_family():
reload_windows_env()
+ # !!! status commands re-use structured output files; if the status command doesn't update the
+ # the file (because it doesn't have to) then we must ensure that the file is reset to prevent
+ # old, stale structured output from a prior status command from being used
+ if self.command_name == "status":
+ Script.structuredOut = {}
+ self.put_structured_out({})
+
try:
with open(self.command_data_file) as f:
pass
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0d7f001/ambari-server/src/test/python/unitTests.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/unitTests.py b/ambari-server/src/test/python/unitTests.py
index a8e72e9..bff8959 100644
--- a/ambari-server/src/test/python/unitTests.py
+++ b/ambari-server/src/test/python/unitTests.py
@@ -125,7 +125,7 @@ def resolve_paths_to_import_from_common_services(metainfo_file, base_stack_folde
@param base_stack_folder: Path to stacks folder that does not include the version number. This can potentially be None.
@param common_services_parent_dir: Path to the common-services directory for a specified service, not including the version.
@param service: Service name
- :return A list of paths to insert to sys.path by following the chain of inheritence.
+ :return A list of paths to insert to sys.path by follwing the chain of inheritence.
"""
paths_to_import = []