You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2018/06/08 18:51:41 UTC

[ambari] branch trunk updated: [AMBARI-24060] Sys-prepped Hosts do not Install and Finalize correctly (#1495)

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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new 19b8f1c  [AMBARI-24060] Sys-prepped Hosts do not Install and Finalize correctly (#1495)
19b8f1c is described below

commit 19b8f1c27abe55aeaa007a240121deca49e37a48
Author: ncole <nc...@hortonworks.com>
AuthorDate: Fri Jun 8 14:51:36 2018 -0400

    [AMBARI-24060] Sys-prepped Hosts do not Install and Finalize correctly (#1495)
    
    * [AMBARI-24060] Sys-prepped Hosts do not Install and Finalize correctly
    
    * Change logger call according to review comments
---
 .../ambari_commons/repo_manager/apt_manager.py     | 15 +++++-
 .../custom_actions/scripts/stack_select_set_all.py | 11 +++-
 .../custom_actions/test_stack_select_set_all.py    | 60 +++++++++++++++++++++-
 3 files changed, 82 insertions(+), 4 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 9f4330a..95a52a9 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
@@ -177,7 +177,20 @@ class AptManager(GenericManager):
       return filtered_packages
     else:
       Logger.info("Packages will be queried using all available repositories on the system.")
-      return [package[0] for package in packages]
+
+      # this is the case where the hosts are marked as sysprepped, but
+      # search the repos on-system anyway.  the url specified in ambari must match the one
+      # in the list file for this to work
+      for repo_id in repo_ids:
+        for package in packages:
+          if repo_id in package[2]:
+            filtered_packages.append(package[0])
+
+      if len(filtered_packages) > 0:
+        Logger.info("Found packages for repo {}".format(str(filtered_packages)))
+        return filtered_packages
+      else:
+        return [package[0] for package in packages]
 
   def package_manager_configuration(self):
     """
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/stack_select_set_all.py b/ambari-server/src/main/resources/custom_actions/scripts/stack_select_set_all.py
index ed9a1b0..9ae27ba 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/stack_select_set_all.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/stack_select_set_all.py
@@ -65,7 +65,7 @@ class UpgradeSetAll(Script):
     # this script runs on all hosts; if this host doesn't have stack components,
     # then don't invoke the stack tool
     # (no need to log that it's skipped - the function will do that)
-    if is_host_skippable(stack_selector_path):
+    if is_host_skippable(stack_selector_path, summary.associated_version):
       return
 
     # invoke "set all"
@@ -75,10 +75,11 @@ class UpgradeSetAll(Script):
       raise Exception("Command '{0}' exit code is nonzero".format(cmd))
 
 
-def is_host_skippable(stack_selector_path):
+def is_host_skippable(stack_selector_path, associated_version):
   """
   Gets whether this host should not have the stack select tool called.
   :param stack_selector_path  the path to the stack selector tool.
+  :param associated_version: the version to use with the stack selector tool.
   :return: True if this host should be skipped, False otherwise.
   """
   if not os.path.exists(stack_selector_path):
@@ -102,6 +103,12 @@ def is_host_skippable(stack_selector_path):
     Logger.info("{0} has no stack versions installed".format(socket.gethostname()))
     return True
 
+  # some pre-prepped systems may have a version, so there may be a version, so
+  # add the extra check if it is available
+  if not associated_version in out:
+    Logger.info("{0} is not found in the list of versions {1}".format(associated_version, out))
+    return True
+
   return False
 
 
diff --git a/ambari-server/src/test/python/custom_actions/test_stack_select_set_all.py b/ambari-server/src/test/python/custom_actions/test_stack_select_set_all.py
index b2b10c6..3bcd0bb 100644
--- a/ambari-server/src/test/python/custom_actions/test_stack_select_set_all.py
+++ b/ambari-server/src/test/python/custom_actions/test_stack_select_set_all.py
@@ -82,9 +82,16 @@ class TestStackSelectSetAll(RMFTestCase):
 
     config_dict = ConfigDictionary(json_payload)
 
+    def hdp_select_call(command, **kwargs):
+      # return no versions
+      if "versions" in command:
+        return (0,"2.5.9.9-9999")
+
+      return (0,command)
+
     family_mock.return_value = True
     get_config_mock.return_value = config_dict
-    call_mock.side_effect = fake_call   # echo the command
+    call_mock.side_effect = hdp_select_call
     exists_mock.return_value = True
 
     # Ensure that the json file was actually read.
@@ -155,6 +162,57 @@ class TestStackSelectSetAll(RMFTestCase):
     call_mock.assert_called_with(('ambari-python-wrap', u'/usr/bin/hdp-select', 'versions'), sudo = True)
     self.assertEqual(call_mock.call_count, 1)
 
+  @patch("os.path.exists")
+  @patch("resource_management.core.shell.call")
+  @patch.object(Script, 'get_config')
+  @patch.object(OSCheck, 'is_redhat_family')
+  def test_skippable_by_list(self, family_mock, get_config_mock, call_mock, exists_mock):
+    """
+    Tests that hosts are skippable if they don't have stack components installed
+    :return:
+    """
+    # Mock the config objects
+    json_file_path = os.path.join(self.get_custom_actions_dir(),
+      "ru_execute_tasks_namenode_prepare.json")
+    self.assertTrue(os.path.isfile(json_file_path))
+
+    with open(json_file_path, "r") as json_file:
+      json_payload = json.load(json_file)
+
+    json_payload["configurations"]["cluster-env"]["stack_tools"] = self.get_stack_tools()
+    json_payload["configurations"]["cluster-env"]["stack_features"] = self.get_stack_features()
+    json_payload["upgradeSummary"] = TestStackSelectSetAll._get_upgrade_summary_no_downgrade()["upgradeSummary"]
+
+    config_dict = ConfigDictionary(json_payload)
+
+    family_mock.return_value = False
+    get_config_mock.return_value = config_dict
+    exists_mock.return_value = True
+
+    def hdp_select_call(command, **kwargs):
+      # return no versions
+      if "versions" in command:
+        return (0,"2.6.7-123")
+
+      return (0,command)
+
+    call_mock.side_effect = hdp_select_call
+
+    # Ensure that the json file was actually read.
+    stack_name = default("/clusterLevelParams/stack_name", None)
+    stack_version = default("/clusterLevelParams/stack_version", None)
+    service_package_folder = default('/roleParams/service_package_folder', None)
+
+    self.assertEqual(stack_name, "HDP")
+    self.assertEqual(stack_version, '2.2')
+    self.assertEqual(service_package_folder, "common-services/HDFS/2.1.0.2.0/package")
+
+    # Begin the test
+    ru_execute = UpgradeSetAll()
+    ru_execute.actionexecute(None)
+
+    call_mock.assert_called_with(('ambari-python-wrap', u'/usr/bin/hdp-select', 'versions'), sudo = True)
+    self.assertEqual(call_mock.call_count, 1)
 
   @patch("os.path.exists")
   @patch("resource_management.core.shell.call")

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