You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2015/01/21 22:46:27 UTC

ambari git commit: AMBARI-9248. Fix post-install hook for hdp-select (dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 72386bf02 -> fe14f498e


AMBARI-9248. Fix post-install hook for hdp-select (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: fe14f498e1e209c71306e42fbc1790757426d074
Parents: 72386bf
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Jan 21 23:45:39 2015 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Jan 21 23:45:39 2015 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/HostCleanup.py   | 13 ++++++++++++-
 .../test/python/ambari_agent/TestHostCleanup.py   | 18 +++++++++++++++++-
 .../scripts/shared_initialization.py              |  8 ++++++--
 3 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fe14f498/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
index 7aeb70a..398502e 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
@@ -87,8 +87,10 @@ DIRNAME_PATTERNS = [
 REPOSITORY_BLACK_LIST = ["ambari.repo"]
 PACKAGES_BLACK_LIST = ["ambari-server", "ambari-agent"]
 
-
 class HostCleanup:
+
+  SELECT_ALL_PERFORMED_MARKER = "/var/lib/ambari-agent/data/hdp-select-set-all.performed"
+
   def resolve_ambari_config(self):
     try:
       config = AmbariConfig()
@@ -134,6 +136,8 @@ class HostCleanup:
       if packageList and not PACKAGE_SECTION in SKIP_LIST:
         logger.info("Deleting packages: " + str(packageList) + "\n")
         self.do_erase_packages(packageList)
+        # Removing packages means that we have to rerun hdp-select
+        self.do_remove_hdp_select_marker()
       if userList and not USER_SECTION in SKIP_LIST:
         logger.info("\n" + "Deleting users: " + str(userList))
         self.do_delete_users(userList)
@@ -260,6 +264,13 @@ class HostCleanup:
       self.do_erase_files_silent(remList)
 
 
+  def do_remove_hdp_select_marker(self):
+    """
+    Remove marker file for 'hdp-select set all' invocation
+    """
+    if os.path.isfile(self.SELECT_ALL_PERFORMED_MARKER):
+      os.unlink(self.SELECT_ALL_PERFORMED_MARKER)
+
 
   # Alternatives exist as a stack of symlinks under /var/lib/alternatives/$name
   # Script expects names of the alternatives as input

http://git-wip-us.apache.org/repos/asf/ambari/blob/fe14f498/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py b/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
index 84b96cc..f43784c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostCleanup.py
@@ -368,7 +368,7 @@ class TestHostCleanup(TestCase):
 
   @patch.object(HostCleanup.HostCleanup, 'run_os_command')
   @patch.object(OSCheck, "get_os_type")
-  def test_do_earse_packages(self, get_os_type_method, run_os_command_method):
+  def test_do_erase_packages(self, get_os_type_method, run_os_command_method):
     out = StringIO.StringIO()
     sys.stdout = out
 
@@ -399,6 +399,22 @@ class TestHostCleanup(TestCase):
 
     sys.stdout = sys.__stdout__
 
+
+  @patch('os.path.isfile')
+  @patch('os.unlink')
+  def test_do_remove_hdp_select_marker(self, unlink_mock, isfile_mock):
+    out = StringIO.StringIO()
+    sys.stdout = out
+
+    isfile_mock.return_value = True
+
+    self.hostcleanup.do_remove_hdp_select_marker()
+
+    self.assertTrue(unlink_mock.called)
+
+    sys.stdout = sys.__stdout__
+
+
   @patch.object(HostCleanup.HostCleanup, 'get_files_in_dir')
   @patch.object(OSCheck, "get_os_type")
   def test_find_repo_files_for_repos(self, get_os_type_method,

http://git-wip-us.apache.org/repos/asf/ambari/blob/fe14f498/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/shared_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/shared_initialization.py b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/shared_initialization.py
index f256688..3b7bc54 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/shared_initialization.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/shared_initialization.py
@@ -20,10 +20,14 @@ import os
 from resource_management import *
 
 def setup_hdp_install_directory():
+  # This is a name of marker file.
+  SELECT_ALL_PERFORMED_MARKER = "/var/lib/ambari-agent/data/hdp-select-set-all.performed"
   import params
   if params.hdp_stack_version != "" and compare_versions(params.stack_version_unformatted, '2.2') >= 0:
-    Execute(format('sudo /usr/bin/hdp-select set all `ambari-python-wrap /usr/bin/hdp-select versions | grep ^{stack_version_unformatted} | tail -1`'),
-            only_if=format('ls -d /usr/hdp/{stack_version_unformatted}*')
+    Execute(format('sudo touch {SELECT_ALL_PERFORMED_MARKER} ; ' +
+                   'sudo /usr/bin/hdp-select set all `ambari-python-wrap /usr/bin/hdp-select versions | grep ^{stack_version_unformatted} | tail -1`'),
+            only_if=format('ls -d /usr/hdp/{stack_version_unformatted}*'),   # If any HDP version is installed
+            not_if=format("test -f {SELECT_ALL_PERFORMED_MARKER}")           # Do that only once (otherwise we break rolling upgrade logic)
     )
 
 def setup_config():