ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hapyles...@apache.org
Subject [2/2] ambari git commit: AMBARI-21755 Unexpected Package Names in CentOS Cause Installation Failures (dgrinenko)
Date Tue, 22 Aug 2017 03:17:48 GMT
AMBARI-21755 Unexpected Package Names in CentOS Cause Installation Failures (dgrinenko)


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

Branch: refs/heads/branch-2.6
Commit: d2ca468cc1f09d69ca4af504076a20602e48fd27
Parents: d84cda8
Author: Dmytro Grinenko <hapylestat@apache.org>
Authored: Tue Aug 22 06:15:53 2017 +0300
Committer: Dmytro Grinenko <hapylestat@apache.org>
Committed: Tue Aug 22 06:15:53 2017 +0300

----------------------------------------------------------------------
 .../core/providers/package/__init__.py             | 17 ++++++++++-------
 .../python/custom_actions/TestInstallPackages.py   | 10 ++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d2ca468c/ambari-common/src/main/python/resource_management/core/providers/package/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/providers/package/__init__.py
b/ambari-common/src/main/python/resource_management/core/providers/package/__init__.py
index 256cf8f..84ff9cc 100644
--- a/ambari-common/src/main/python/resource_management/core/providers/package/__init__.py
+++ b/ambari-common/src/main/python/resource_management/core/providers/package/__init__.py
@@ -23,9 +23,6 @@ Ambari Agent
 import time
 import re
 import logging
-import sys
-
-import subprocess
 
 from resource_management.core.exceptions import ExecutionFailed
 from resource_management.core.providers import Provider
@@ -344,6 +341,7 @@ class RPMBasedPackageProvider(PackageProvider):
   """
    RPM Based abstract package provider
   """
+  INSTALLED_PACKAGE_VERSION_COMMAND = "rpm -q --queryformat '%{{version}}-%{{release}}' \"{0}\""
 
   def rpm_check_package_available(self, name):
     import rpm # this is faster then calling 'rpm'-binary externally.
@@ -359,8 +357,13 @@ class RPMBasedPackageProvider(PackageProvider):
     return False
 
   def get_installed_package_version(self, package_name):
-    result = self.checked_call("rpm -q --queryformat '%{{version}}-%{{release}}' {0} | sed
-e 's/\.el[0-9]//g'".format(package_name), stderr=subprocess.PIPE)
-    if len(result) >= 2:
-      return result[1]
+    version = None
 
-    return None
+    result = self.checked_call(self.INSTALLED_PACKAGE_VERSION_COMMAND.format(package_name))
+    try:
+      if result[0] == 0:
+        version = result[1].strip().partition(".el")[0]
+    except IndexError:
+      pass
+
+    return version

http://git-wip-us.apache.org/repos/asf/ambari/blob/d2ca468c/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
index b31e2f5..de2cced 100644
--- a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
+++ b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
@@ -75,6 +75,16 @@ class TestInstallPackages(RMFTestCase):
   def _add_packages_lookUpYum(*args):
     return TestInstallPackages._add_packages_available(*args)
 
+  def test_get_installed_package_version(self):
+    from resource_management.core.providers.package.yumrpm import YumProvider
+
+    provider = YumProvider(None)
+    with patch.object(provider, "checked_call") as checked_call_mock:
+      checked_call_mock.return_value = 0, "3.1.0.0-54.el7.centos"
+      expected_version = provider.get_installed_package_version("test")
+      self.assertEquals("3.1.0.0-54", expected_version)
+
+
   @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
   @patch("resource_management.core.providers.get_provider")
   @patch("resource_management.libraries.script.Script.put_structured_out")


Mime
View raw message