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:36:34 UTC

[ambari] branch trunk updated (b99f665 -> a9ed081)

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

hapylestat pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git.


    from b99f665  Updating Ambari docs for Ambari 2.6.2
     new fb178d2  initial
     new 010e4a7  AMBARI-23717 Stack installation command didn't fail properly when installed package didn't present in repository (dgrinenko)
     new a9ed081  fix UT and issues from review

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ambari_commons/repo_manager/apt_manager.py     | 15 +++++++--
 .../ambari_commons/repo_manager/generic_manager.py |  6 ++++
 .../ambari_commons/repo_manager/yum_manager.py     | 13 +++++++-
 .../ambari_commons/repo_manager/zypper_manager.py  | 17 ++++++++--
 .../resource_management/libraries/script/script.py | 33 +++++++++++++------
 .../python/custom_actions/TestInstallPackages.py   | 37 +++++++++++-----------
 6 files changed, 88 insertions(+), 33 deletions(-)

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

[ambari] 01/03: initial

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hapylestat pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit fb178d2fa3cdf6f2586648264a1888357dd95a3f
Author: Dmitry Grinenko <ha...@gmail.com>
AuthorDate: Fri Apr 27 20:46:29 2018 +0300

    initial
---
 .../src/main/python/ambari_commons/repo_manager/apt_manager.py         | 3 +++
 .../src/main/python/ambari_commons/repo_manager/yum_manager.py         | 3 +++
 .../src/main/python/ambari_commons/repo_manager/zypper_manager.py      | 3 +++
 3 files changed, 9 insertions(+)

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 38cf602..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
@@ -304,5 +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/yum_manager.py b/ambari-common/src/main/python/ambari_commons/repo_manager/yum_manager.py
index 5e404b1..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
@@ -263,6 +263,9 @@ 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)
     else:
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 8617ef9..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
@@ -282,4 +282,7 @@ class ZypperManager(GenericManager):
     zypper 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")
+
     return self.rpm_check_package_available(name)

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

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

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hapylestat pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 010e4a77ddd640201f01a3f5335acf2ca32e9367
Author: Reishin <ha...@gmail.com>
AuthorDate: Mon Apr 30 17:31:20 2018 +0300

    AMBARI-23717 Stack installation command didn't fail properly when installed package didn't present in repository (dgrinenko)
---
 .../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, 63 insertions(+), 18 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 76d31f1..fdee179 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,12 +215,16 @@ 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 context.is_upgrade or context.use_repos or not self._check_existence(name):
+    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):
       cmd = self.properties.install_cmd[context.log_output]
       copied_sources_files = []
       is_tmp_dir_created = False
@@ -264,6 +268,8 @@ 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)
@@ -276,8 +282,12 @@ class AptManager(GenericManager):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
+
+    :raise ValueError if name is empty
     """
-    if self._check_existence(name):
+    if not name:
+      raise ValueError("Installation command were executed with no package name passed")
+    elif 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)
@@ -304,8 +314,6 @@ 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 d4e1e08..3b6056c 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,6 +69,8 @@ class GenericManager(object):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
+
+    :raise ValueError if name is empty
     """
     raise NotImplementedError()
 
@@ -79,6 +81,8 @@ class GenericManager(object):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
+
+    :raise ValueError if name is empty
     """
     raise NotImplementedError()
 
@@ -88,6 +92,8 @@ 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 6a2b629..0f056ba 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,9 +202,13 @@ class YumManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
+
+    :raise ValueError if name is empty
     """
 
-    if context.is_upgrade or context.use_repos or not self._check_existence(name):
+    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):
       cmd = self.properties.install_cmd[context.log_output]
       if context.use_repos:
         enable_repo_option = '--enablerepo=' + ",".join(sorted(context.use_repos.keys()))
@@ -222,6 +226,8 @@ 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)
@@ -233,7 +239,11 @@ 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]
@@ -263,8 +273,6 @@ 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 9f6f09a..592e7c8 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,8 +178,12 @@ class ZypperManager(GenericManager):
 
     :type name str
     :type context ambari_commons.shell.RepoCallContext
+
+    :raise ValueError if name is empty
     """
-    if context.is_upgrade or context.use_repos or not self._check_existence(name):
+    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):
       cmd = self.properties.install_cmd[context.log_output]
 
       if context.use_repos:
@@ -206,6 +210,8 @@ 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)
@@ -217,8 +223,12 @@ class ZypperManager(GenericManager):
     :type name str
     :type context ambari_commons.shell.RepoCallContext
     :type ignore_dependencies bool
+
+    :raise ValueError if name is empty
     """
-    if self._check_existence(name):
+    if not name:
+      raise ValueError("Installation command were executed with no package name passed")
+    elif 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 626aa19..60aac9c 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,24 +491,41 @@ class Script(object):
 
     return Script.stack_version_from_distro_select
 
-
-  def get_package_from_available(self, name, available_packages_in_repos):
+  def get_package_from_available(self, name, available_packages_in_repos=None):
     """
     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, repo_version=None):
+  def format_package_name(self, name):
     from resource_management.libraries.functions.default import default
     """
     This function replaces ${stack_version} placeholder with actual version.  If the package
@@ -537,11 +554,7 @@ class Script(object):
       package_version = default("hostLevelParams/package_version", None)
 
     if (package_version is None or '-' not in package_version) and default('/repositoryFile', None):
-      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
+      return self.get_package_from_available(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.

[ambari] 03/03: fix UT and issues from review

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hapylestat pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit a9ed08134716a41a4feee07f50c8954c306f3117
Author: Dmitry Grinenko <ha...@gmail.com>
AuthorDate: Wed May 2 08:30:36 2018 +0300

    fix UT and issues from review
---
 .../ambari_commons/repo_manager/apt_manager.py     |  2 +-
 .../ambari_commons/repo_manager/yum_manager.py     |  2 +-
 .../ambari_commons/repo_manager/zypper_manager.py  |  2 +-
 .../resource_management/libraries/script/script.py |  2 ++
 .../python/custom_actions/TestInstallPackages.py   | 37 +++++++++++-----------
 5 files changed, 23 insertions(+), 22 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..9f4330a 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
@@ -223,7 +223,7 @@ class AptManager(GenericManager):
     apt_sources_list_tmp_dir = None
 
     if not name:
-      raise ValueError("Installation command were executed with no package name passed")
+      raise ValueError("Installation command was executed with no package name")
     elif context.is_upgrade or context.use_repos or not self._check_existence(name):
       cmd = self.properties.install_cmd[context.log_output]
       copied_sources_files = []
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..7df4632 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
@@ -207,7 +207,7 @@ class YumManager(GenericManager):
     """
 
     if not name:
-      raise ValueError("Installation command were executed with no package name passed")
+      raise ValueError("Installation command was executed with no package name")
     elif 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:
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..8d901c2 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
@@ -182,7 +182,7 @@ class ZypperManager(GenericManager):
     :raise ValueError if name is empty
     """
     if not name:
-      raise ValueError("Installation command were executed with no package name passed")
+      raise ValueError("Installation command was executed with no package name")
     elif context.is_upgrade or context.use_repos or not self._check_existence(name):
       cmd = self.properties.install_cmd[context.log_output]
 
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..1ddc49a 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
@@ -783,6 +783,8 @@ class Script(object):
       Logger.exception("Unable to load available packages")
       self.available_packages_in_repos = []
 
+    return self.available_packages_in_repos
+
 
   def install_packages(self, env):
     """
diff --git a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
index 7efe226..6e04938 100644
--- a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
+++ b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
@@ -49,14 +49,14 @@ class TestInstallPackages(RMFTestCase):
     self.maxDiff = None
 
   @staticmethod
-  def _add_packages(*args):
+  def _add_packages(*args, **kwargs):
     return [
       ["pkg1", "1.0", "repo"],
       ["pkg2", "2.0", "repo2"]
     ]
 
   @staticmethod
-  def _add_packages_available(*args):
+  def _add_packages_available(*args, **kwargs):
     return [
       ["hadoop_2_2_0_1_885", "1.0", "HDP-2.2"],
       ["hadooplzo_2_2_0_1_885", "1.0", "HDP-2.2"],
@@ -64,8 +64,8 @@ class TestInstallPackages(RMFTestCase):
     ]
 
   @staticmethod
-  def _add_packages_lookUpYum(*args):
-    return TestInstallPackages._add_packages_available(*args)
+  def _add_packages_lookUpYum(*args, **kwargs):
+    return TestInstallPackages._add_packages_available(*args, **kwargs)
 
   def test_get_installed_package_version(self):
     from ambari_commons.os_check import OSConst
@@ -185,18 +185,18 @@ class TestInstallPackages(RMFTestCase):
 
       get_provider.return_value = pkg_manager
 
-      self.executeScript("scripts/install_packages.py",
-                         classname="InstallPackages",
-                         command="actionexecute",
-                         config_dict = command_json,
-                         target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
-                         os_type=('Redhat', '6.4', 'Final'),
-      )
-      self.assertTrue(put_structured_out_mock.called)
-      self.assertEquals(put_structured_out_mock.call_args[0][0],
-                        {'package_installation_result': 'SUCCESS',
-                         'repository_version_id': 1,
-                         'actual_version': VERSION_STUB})
+      try:
+        self.executeScript("scripts/install_packages.py",
+                           classname="InstallPackages",
+                           command="actionexecute",
+                           config_dict = command_json,
+                           target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
+                           os_type=('Redhat', '6.4', 'Final'),
+        )
+      except Fail as e:
+        self.assertEquals(e.message, "Failed to distribute repositories/install packages")
+      else:
+        self.assertFalse("Packages can't be installed without repos")
 
       self.assertNoMoreResources()
 
@@ -339,7 +339,7 @@ class TestInstallPackages(RMFTestCase):
   _install_failed = False
 
   @staticmethod
-  def _add_packages_with_fail():
+  def _add_packages_with_fail(*args, **kwargs):
     arg = []
     arg.append(["pkg1_2_2_0_1_885_pack", "1.0", "repo"])
     arg.append(["pkg2_2_2_0_1_885_pack2", "2.0", "repo2"])
@@ -400,8 +400,7 @@ class TestInstallPackages(RMFTestCase):
       self.assertTrue(put_structured_out_mock.called)
       self.assertEquals(put_structured_out_mock.call_args[0][0],
                         {'repository_version_id': 1,
-                        'package_installation_result': 'FAIL',
-                         'actual_version': '2.2.0.1-885'})
+                        'package_installation_result': 'FAIL'})
       self.assertResourceCalled('Repository', 'HDP-UTILS-1.1.0.20',
                                 base_url=u'http://repo1/HDP/centos5/2.x/updates/2.2.0.0',
                                 action=['create'],

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