Repository: ambari Updated Branches: refs/heads/branch-2.6 5eab1a569 -> 6cf8be32e
AMBARI-22139 - CURRENT cluster Shows Upgrade If Component Didn't Report Version (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6cf8be32 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6cf8be32 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6cf8be32 Branch: refs/heads/branch-2.6 Commit: 6cf8be32e4f0e41346b59953b7069c4ac67140fb Parents: 5eab1a5 Author: Jonathan Hurley <[email protected]> Authored: Thu Oct 5 16:06:06 2017 -0400 Committer: Jonathan Hurley <[email protected]> Committed: Fri Oct 6 09:37:10 2017 -0400 ---------------------------------------------------------------------- .../python/resource_management/TestScript.py | 26 ++++++++++++++++++-- .../libraries/script/script.py | 22 ++++++++++++++--- .../src/test/python/stacks/utils/RMFTestCase.py | 9 ++++--- 3 files changed, 48 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/6cf8be32/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 75726d6..79d0598 100644 --- a/ambari-agent/src/test/python/resource_management/TestScript.py +++ b/ambari-agent/src/test/python/resource_management/TestScript.py @@ -21,9 +21,9 @@ import StringIO import sys, pprint from resource_management.libraries.script import Script from resource_management.core.environment import Environment +from resource_management.core.logger import Logger from mock.mock import patch, MagicMock from stacks.utils.RMFTestCase import * -import logging class TestScript(RMFTestCase): @@ -110,7 +110,7 @@ class TestScript(RMFTestCase): @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. + Tests that status commands will clear any stored structured output from prior status commands. :param open_mock: :return: """ @@ -141,6 +141,28 @@ class TestScript(RMFTestCase): self.assertTrue(open_mock.called) self.assertEquals({}, Script.structuredOut) + + @patch.object(Logger, "error", new = MagicMock()) + @patch.object(Script, "put_structured_out") + @patch("resource_management.libraries.functions.version_select_util.get_component_version_from_symlink", new = MagicMock(return_value=None)) + @patch("resource_management.libraries.functions.stack_select.get_package_name", new = MagicMock(return_value="foo-package")) + @patch("resource_management.libraries.functions.stack_select.unsafe_get_stack_versions", new = MagicMock(return_value=("",0,["2.6.0.0-1234"]))) + def test_save_version_structured_out_stack_select(self, pso_mock): + """ + Tests that when writing out the version of the component to the structure output, + if all else fails, we'll invoke the stack-select tool to see if there are any versions + reported. + :param pso_mock: + :return: + """ + script = Script() + script.stroutfile = '' + script.save_component_version_to_structured_out("start") + + self.assertEqual(pso_mock.call_count, 1) + self.assertEquals(pso_mock.call_args[0][0], {'version':'2.6.0.0-1234'}) + + def tearDown(self): # enable stdout sys.stdout = sys.__stdout__ http://git-wip-us.apache.org/repos/asf/ambari/blob/6cf8be32/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 8f9cf5c..a1fd1f3 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 @@ -46,7 +46,7 @@ from resource_management.core.environment import Environment from resource_management.core.logger import Logger from resource_management.core.exceptions import Fail, ClientComponentHasNoStatus, ComponentIsNotRunning from resource_management.core.resources.packaging import Package -from resource_management.libraries.functions.version_select_util import get_component_version_from_symlink +from resource_management.libraries.functions import version_select_util from resource_management.libraries.functions.version import compare_versions from resource_management.libraries.functions.version import format_stack_version from resource_management.libraries.functions import stack_tools @@ -212,6 +212,12 @@ class Script(object): Saves the version of the component for this command to the structured out file. If the command is an install command and the repository is trusted, then it will use the version of the repository. Otherwise, it will consult the stack-select tool to read the symlink version. + + Under rare circumstances, a component may have a bug which prevents it from reporting a + version back after being installed. This is most likely due to the stack-select tool not being + invoked by the package's installer. In these rare cases, we try to see if the component + should have reported a version and we try to fallback to the "<stack-select> versions" command. + :param command_name: command name :return: None """ @@ -240,7 +246,17 @@ class Script(object): if stack_select_package_name and stack_name: # only query for the component version from stack-select if we can't trust the repository yet if component_version is None: - component_version = get_component_version_from_symlink(stack_name, stack_select_package_name) + component_version = version_select_util.get_component_version_from_symlink(stack_name, stack_select_package_name) + + # last ditch effort - should cover the edge case where the package failed to setup its + # link and we have to try to see if <stack-select> can help + if component_version is None: + output, code, versions = stack_select.unsafe_get_stack_versions() + if len(versions) == 1: + component_version = versions[0] + Logger.error("The '{0}' component did not advertise a version. This may indicate a problem with the component packaging. " \ + "However, the stack-select tool was able to report a single version installed ({1}). " \ + "This is the version that will be reported.".format(stack_select_package_name, component_version)) if component_version: self.put_structured_out({"version": component_version}) @@ -252,7 +268,7 @@ class Script(object): self.put_structured_out({"repository_version_id": repo_version_id}) else: if not self.is_hook(): - Logger.error("Component '{0}' did not advertise a version. This may indicate a problem with the component packaging.".format(stack_select_package_name)) + Logger.error("The '{0}' component did not advertise a version. This may indicate a problem with the component packaging.".format(stack_select_package_name)) def should_expose_component_version(self, command_name): http://git-wip-us.apache.org/repos/asf/ambari/blob/6cf8be32/ambari-server/src/test/python/stacks/utils/RMFTestCase.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py index 665fc20..7091298 100644 --- a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py +++ b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py @@ -149,11 +149,12 @@ class RMFTestCase(TestCase): with patch('resource_management.libraries.functions.stack_select.is_package_supported', return_value=True): with patch('resource_management.libraries.functions.stack_select.get_supported_packages', return_value=MagicMock()): with patch.object(os, "environ", new=os_env) as mocks_dict['environ']: - if not try_install: - with patch.object(Script, 'install_packages') as install_mock_value: + with patch('resource_management.libraries.functions.stack_select.unsafe_get_stack_versions', return_value = (("",0,[]))): + if not try_install: + with patch.object(Script, 'install_packages') as install_mock_value: + method(RMFTestCase.env, *command_args) + else: method(RMFTestCase.env, *command_args) - else: - method(RMFTestCase.env, *command_args) sys.path.remove(scriptsdir)
