You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2017/01/27 18:17:14 UTC

[03/49] ambari git commit: AMBARI-19630: Ambari should accept stack version in format of x.x.x.x without the build level digits (dili)

AMBARI-19630: Ambari should accept stack version in format of x.x.x.x without the build level digits (dili)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/21c18a78
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/21c18a78
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/21c18a78

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 21c18a78beb397da324c80d6943d55038167d855
Parents: 6a2aca6
Author: Di Li <di...@apache.org>
Authored: Wed Jan 25 14:16:56 2017 -0500
Committer: Di Li <di...@apache.org>
Committed: Wed Jan 25 14:16:56 2017 -0500

----------------------------------------------------------------------
 .../libraries/functions/get_stack_version.py    |  2 +-
 .../libraries/functions/version_select_util.py  |  5 ++-
 .../src/test/python/TestVersionSelectUtil.py    | 40 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/21c18a78/ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py b/ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py
index 7274a59..463d61f 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/get_stack_version.py
@@ -85,7 +85,7 @@ def get_stack_version(package_name):
 
   stack_version = re.sub(package_name + ' - ', '', stack_output)
   stack_version = stack_version.rstrip()
-  match = re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+-[0-9]+', stack_version)
+  match = re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+(-[0-9]+)?', stack_version)
 
   if match is None:
     Logger.info('Failed to get extracted version with ' + stack_selector_path)

http://git-wip-us.apache.org/repos/asf/ambari/blob/21c18a78/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py b/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
index 615a0cd..ff00a1f 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py
@@ -67,8 +67,9 @@ def get_component_version(stack_name, component_name):
           raise Exception("Code is nonzero or output is empty")
 
         Logger.debug("Command: %s\nOutput: %s" % (get_stack_comp_version_cmd, str(out)))
-        matches = re.findall(r"([\d\.]+\-\d+)", out)
-        version = matches[0] if matches and len(matches) > 0 else None
+        matches = re.findall(r"( [\d\.]+(\-\d+)?)", out)
+        version = matches[0][0].strip() if matches and len(matches) > 0 and len(matches[0]) > 0 else None
+        Logger.debug("Version for component %s: %s" % (component_name, str(version)))
       except Exception, e:
         Logger.error("Could not determine stack version for component %s by calling '%s'. Return Code: %s, Output: %s." %
                      (component_name, get_stack_comp_version_cmd, str(code), str(out)))

http://git-wip-us.apache.org/repos/asf/ambari/blob/21c18a78/ambari-server/src/test/python/TestVersionSelectUtil.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestVersionSelectUtil.py b/ambari-server/src/test/python/TestVersionSelectUtil.py
index 38798e2..5facf31 100644
--- a/ambari-server/src/test/python/TestVersionSelectUtil.py
+++ b/ambari-server/src/test/python/TestVersionSelectUtil.py
@@ -97,3 +97,43 @@ class TestVersionSelectUtil(TestCase):
     self.assertEquals(version, stack_expected_version)
     version = self.module.get_component_version("HDP", "hadoop-hdfs-datanode")
     self.assertEquals(version, stack_expected_version)
+
+  @patch('__builtin__.open')
+  @patch("resource_management.core.shell.call")
+  @patch('os.path.exists')
+  @patch("resource_management.libraries.functions.stack_tools.get_stack_tool")
+  def test_get_component_version_no_build_ids(self, get_stack_tool_mock, os_path_exists_mock, call_mock, open_mock):
+    stack_expected_version = "2.2.1.0"
+
+    # Mock classes for reading from a file
+    class MagicFile(object):
+      allowed_names = set(["hive-server2",
+                           "zookeeper-server"])
+      def read(self, value):
+        return (value + " - " + stack_expected_version) if value in self.allowed_names else ("ERROR: Invalid package - " + value)
+
+      def __exit__(self, exc_type, exc_val, exc_tb):
+        pass
+
+      def __enter__(self):
+        return self
+    pass
+
+    class MagicFile1(MagicFile):
+      def read(self):
+        return super(MagicFile1, self).read("hive-server2")
+    class MagicFile2(MagicFile):
+      def read(self):
+        return super(MagicFile2, self).read("zookeeper-server")
+
+    get_stack_tool_mock.side_effect = [("hdp-select", "/usr/bin/hdp-select", "hdp-select"),
+                                       ("hdp-select", "/usr/bin/hdp-select", "hdp-select")]
+    os_path_exists_mock.side_effect = [False, True, True, True]
+    open_mock.side_effect = [MagicFile1(), MagicFile2()]
+    call_mock.side_effect = [(0, "value will come from MagicFile"), ] * 2
+
+    # Pass
+    version = self.module.get_component_version("HDP", "hive-server2")
+    self.assertEquals(version, stack_expected_version)
+    version = self.module.get_component_version("HDP", "zookeeper-server")
+    self.assertEquals(version, stack_expected_version)