ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [23/49] ambari git commit: AMBARI-19630: Ambari should accept stack version in format of x.x.x.x without the build level digits - new unit tests (dili)
Date Fri, 27 Jan 2017 18:17:34 GMT
AMBARI-19630: Ambari should accept stack version in format of x.x.x.x without the build level
digits - new unit tests (dili)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: b92b5f576300d0ab36005f35d7e9d0547be7c2e8
Parents: 9bc765a
Author: Di Li <dili@apache.org>
Authored: Thu Jan 26 11:05:55 2017 -0500
Committer: Di Li <dili@apache.org>
Committed: Thu Jan 26 11:05:55 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/b92b5f57/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/b92b5f57/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/b92b5f57/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..5097fac 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 = [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)


Mime
View raw message