You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ha...@apache.org on 2018/05/02 06:38:58 UTC

[ambari] 02/03: Revert "AMBARI-23717 Stack installation command didn't fail properly when installed package didn't present in repository (dgrinenko)"

This is an automated email from the ASF dual-hosted git repository.

hapylestat pushed a commit to branch revert-1136-in-work/trunk/AMBARI-23717
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit b2c07ad1c7a1aef2a31b1283ee147cc511e80fbc
Author: Dmytro Grinenko <ha...@gmail.com>
AuthorDate: Wed May 2 09:38:54 2018 +0300

    Revert "AMBARI-23717 Stack installation command didn't fail properly when installed package didn't present in repository (dgrinenko)"
    
    This reverts commit 010e4a77ddd640201f01a3f5335acf2ca32e9367.
---
 .../ambari_commons/repo_manager/apt_manager.py     | 16 +++--------
 .../ambari_commons/repo_manager/generic_manager.py |  6 -----
 .../ambari_commons/repo_manager/yum_manager.py     | 14 +++-------
 .../ambari_commons/repo_manager/zypper_manager.py  | 14 ++--------
 .../resource_management/libraries/script/script.py | 31 +++++++---------------
 5 files changed, 18 insertions(+), 63 deletions(-)

diff --git a/ambari-common/src/main/python/ambari_commons/repo_manager/apt_manager.py b/ambari-common/src/main/python/ambari_commons/repo_manager/apt_manager.py
index fdee179..76d31f1 100644
--- a/ambari-common/src/main/python/ambari_commons/repo_manager/apt_manager.py
+++ b/ambari-common/src/main/python/ambari_commons/repo_manager/apt_manager.py
@@ -215,16 +215,12 @@ class AptManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     from resource_management.core import sudo
 
     apt_sources_list_tmp_dir = None
 
-    if not name:
-      raise ValueError("Installation command were executed with no package name passed")
-    elif context.is_upgrade or context.use_repos or not self._check_existence(name):
+    if context.is_upgrade or context.use_repos or not self._check_existence(name):
       cmd = self.properties.install_cmd[context.log_output]
       copied_sources_files = []
       is_tmp_dir_created = False
@@ -268,8 +264,6 @@ class AptManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     context.is_upgrade = True
     return self.install_package(name, context)
@@ -282,12 +276,8 @@ class AptManager(GenericManager):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
-
-    :raise ValueError if name is empty
     """
-    if not name:
-      raise ValueError("Installation command were executed with no package name passed")
-    elif self._check_existence(name):
+    if self._check_existence(name):
       cmd = self.properties.remove_cmd[context.log_output] + [name]
       Logger.info("Removing package {0} ('{1}')".format(name, shell.string_cmd_from_args_list(cmd)))
       shell.repository_manager_executor(cmd, self.properties, context)
@@ -314,6 +304,8 @@ class AptManager(GenericManager):
     apt-get in inconsistant state (locked, used, having invalid repo). Once packages are installed
     we should not rely on that.
     """
+    if not name:
+      raise ValueError("Package name can't be empty")
 
     r = shell.subprocess_executor(self.properties.check_cmd % name)
     return not bool(r.code)
diff --git a/ambari-common/src/main/python/ambari_commons/repo_manager/generic_manager.py b/ambari-common/src/main/python/ambari_commons/repo_manager/generic_manager.py
index 3b6056c..d4e1e08 100644
--- a/ambari-common/src/main/python/ambari_commons/repo_manager/generic_manager.py
+++ b/ambari-common/src/main/python/ambari_commons/repo_manager/generic_manager.py
@@ -69,8 +69,6 @@ class GenericManager(object):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     raise NotImplementedError()
 
@@ -81,8 +79,6 @@ class GenericManager(object):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
-
-    :raise ValueError if name is empty
     """
     raise NotImplementedError()
 
@@ -92,8 +88,6 @@ class GenericManager(object):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     raise NotImplementedError()
 
diff --git a/ambari-common/src/main/python/ambari_commons/repo_manager/yum_manager.py b/ambari-common/src/main/python/ambari_commons/repo_manager/yum_manager.py
index 0f056ba..6a2b629 100644
--- a/ambari-common/src/main/python/ambari_commons/repo_manager/yum_manager.py
+++ b/ambari-common/src/main/python/ambari_commons/repo_manager/yum_manager.py
@@ -202,13 +202,9 @@ class YumManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
 
-    if not name:
-      raise ValueError("Installation command were executed with no package name passed")
-    elif context.is_upgrade or context.use_repos or not self._check_existence(name):
+    if context.is_upgrade or context.use_repos or not self._check_existence(name):
       cmd = self.properties.install_cmd[context.log_output]
       if context.use_repos:
         enable_repo_option = '--enablerepo=' + ",".join(sorted(context.use_repos.keys()))
@@ -226,8 +222,6 @@ class YumManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     context.is_upgrade = True
     return self.install_package(name, context)
@@ -239,11 +233,7 @@ class YumManager(GenericManager):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
-
-    :raise ValueError if name is empty
     """
-    if not name:
-      raise ValueError("Remove command were executed with no package name passed")
     if self._check_existence(name):
       if ignore_dependencies:
         cmd = self.properties.remove_without_dependencies_cmd + [name]
@@ -273,6 +263,8 @@ class YumManager(GenericManager):
     yum in inconsistant state (locked, used, having invalid repo). Once packages are installed
     we should not rely on that.
     """
+    if not name:
+      raise ValueError("Package name can't be empty")
 
     if os.geteuid() == 0:
       return self.yum_check_package_available(name)
diff --git a/ambari-common/src/main/python/ambari_commons/repo_manager/zypper_manager.py b/ambari-common/src/main/python/ambari_commons/repo_manager/zypper_manager.py
index 592e7c8..9f6f09a 100644
--- a/ambari-common/src/main/python/ambari_commons/repo_manager/zypper_manager.py
+++ b/ambari-common/src/main/python/ambari_commons/repo_manager/zypper_manager.py
@@ -178,12 +178,8 @@ class ZypperManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
-    if not name:
-      raise ValueError("Installation command were executed with no package name passed")
-    elif context.is_upgrade or context.use_repos or not self._check_existence(name):
+    if context.is_upgrade or context.use_repos or not self._check_existence(name):
       cmd = self.properties.install_cmd[context.log_output]
 
       if context.use_repos:
@@ -210,8 +206,6 @@ class ZypperManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
-
-    :raise ValueError if name is empty
     """
     context.is_upgrade = True
     return self.install_package(name, context)
@@ -223,12 +217,8 @@ class ZypperManager(GenericManager):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
-
-    :raise ValueError if name is empty
     """
-    if not name:
-      raise ValueError("Installation command were executed with no package name passed")
-    elif self._check_existence(name):
+    if self._check_existence(name):
       cmd = self.properties.remove_cmd[context.log_output] + [name]
       Logger.info("Removing package {0} ('{1}')".format(name, shell.string_cmd_from_args_list(cmd)))
       shell.repository_manager_executor(cmd, self.properties, context)
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 60aac9c..626aa19 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
@@ -491,41 +491,24 @@ class Script(object):
 
     return Script.stack_version_from_distro_select
 
-  def get_package_from_available(self, name, available_packages_in_repos=None):
+
+  def get_package_from_available(self, name, available_packages_in_repos):
     """
     This function matches package names with ${stack_version} placeholder to actual package names from
     Ambari-managed repository.
     Package names without ${stack_version} placeholder are returned as is.
     """
-
     if STACK_VERSION_PLACEHOLDER not in name:
       return name
-
-    if not available_packages_in_repos:
-      available_packages_in_repos = self.load_available_packages()
-
-    from resource_management.libraries.functions.default import default
-
     package_delimiter = '-' if OSCheck.is_ubuntu_family() else '_'
     package_regex = name.replace(STACK_VERSION_PLACEHOLDER, '(\d|{0})+'.format(package_delimiter)) + "$"
-    repo = default('/repositoryFile', None)
-    name_with_version = None
-
-    if repo:
-      command_repo = CommandRepository(repo)
-      version_str = command_repo.version_string.replace('.', package_delimiter).replace("-", package_delimiter)
-      name_with_version = name.replace(STACK_VERSION_PLACEHOLDER, version_str)
-
     for package in available_packages_in_repos:
       if re.match(package_regex, package):
         return package
+    Logger.warning("No package found for {0}({1})".format(name, package_regex))
 
-    if name_with_version:
-      raise Fail("No package found for {0}(expected name: {1})".format(name, name_with_version))
-    else:
-      raise Fail("Cannot match package for regexp name {0}. Available packages: {1}".format(name, self.available_packages_in_repos))
 
-  def format_package_name(self, name):
+  def format_package_name(self, name, repo_version=None):
     from resource_management.libraries.functions.default import default
     """
     This function replaces ${stack_version} placeholder with actual version.  If the package
@@ -554,7 +537,11 @@ class Script(object):
       package_version = default("hostLevelParams/package_version", None)
 
     if (package_version is None or '-' not in package_version) and default('/repositoryFile', None):
-      return self.get_package_from_available(name)
+      self.load_available_packages()
+      package_name = self.get_package_from_available(name, self.available_packages_in_repos)
+      if package_name is None:
+        raise Fail("Cannot match package for regexp name {0}. Available packages: {1}".format(name, self.available_packages_in_repos))
+      return package_name
 
     if package_version is not None:
       package_version = package_version.replace('.', package_delimiter).replace('-', package_delimiter)

-- 
To stop receiving notification emails like this one, please contact
hapylestat@apache.org.