Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8C4A1171E1 for ; Thu, 22 Jan 2015 22:16:42 +0000 (UTC) Received: (qmail 13743 invoked by uid 500); 22 Jan 2015 22:16:42 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 13665 invoked by uid 500); 22 Jan 2015 22:16:42 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 13266 invoked by uid 99); 22 Jan 2015 22:16:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jan 2015 22:16:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D5806E0D4D; Thu, 22 Jan 2015 22:16:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yusaku@apache.org To: commits@ambari.apache.org Date: Thu, 22 Jan 2015 22:16:48 -0000 Message-Id: In-Reply-To: <6ecb3e2414a54ceaa56c58be937aa79a@git.apache.org> References: <6ecb3e2414a54ceaa56c58be937aa79a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/14] ambari git commit: AMBARI-9248. Fix post-install hook for hdp-select (dlysnichenko) 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/1154fe4b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1154fe4b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1154fe4b Branch: refs/heads/2.0-preview Commit: 1154fe4be38d9e1bdf4b311b423a80de31035617 Parents: 84bfe43 Author: Lisnichenko Dmitro Authored: Wed Jan 21 23:45:39 2015 +0200 Committer: Yusaku Sako Committed: Wed Jan 21 14:16:29 2015 -0800 ---------------------------------------------------------------------- .../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/1154fe4b/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/1154fe4b/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/1154fe4b/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():