You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2017/06/20 17:20:32 UTC

ambari git commit: AMBARI-21263. Ambari 2.5.1 upgrade fails with HDPSearch mpack installed.(vbrodetskyi)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 3dc1811e1 -> e239c8cf2


AMBARI-21263. Ambari 2.5.1 upgrade fails with HDPSearch mpack installed.(vbrodetskyi)


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

Branch: refs/heads/branch-2.5
Commit: e239c8cf27f84ad7f3478895cf29f3b1179e234d
Parents: 3dc1811
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Tue Jun 20 20:20:31 2017 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Tue Jun 20 20:20:31 2017 +0300

----------------------------------------------------------------------
 .../main/python/ambari_server/serverUpgrade.py  | 22 +++++++++---
 .../src/test/python/TestAmbariServer.py         | 35 +++++++++++++++++++-
 2 files changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e239c8cf/ambari-server/src/main/python/ambari_server/serverUpgrade.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverUpgrade.py b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
index 160c91d..8263062 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -545,6 +545,7 @@ def find_and_copy_custom_services(resources_dir, services_search_path, old_dir_n
                                     old_dir_mask, base_service_dir):
   services = glob.glob(os.path.join(resources_dir, services_search_path))
   managed_services = []
+  is_common_services_base_dir = "common-services" in base_service_dir
   for service in services:
     if os.path.isdir(service) and not os.path.basename(service) in managed_services:
       managed_services.append(os.path.basename(service))
@@ -565,10 +566,23 @@ def find_and_copy_custom_services(resources_dir, services_search_path, old_dir_n
         continue
 
       # process dirs only
-      if os.path.isdir(backup_service) and not os.path.islink(backup_service):
-        service_name = os.path.basename(backup_service)
-        if not service_name in managed_services:
-          shutil.copytree(backup_service, os.path.join(current_base_service_dir,service_name))
+      if is_common_services_base_dir:
+        version_dirs_in_backup_service_dir = glob.glob(os.path.join(backup_service,"*"))
+        if os.path.isdir(backup_service) and not os.path.islink(backup_service):
+          service_name = os.path.basename(backup_service)
+          current_service_dir_path = os.path.join(current_base_service_dir, service_name)
+          if not service_name in managed_services:
+            if not os.path.exists(current_service_dir_path):
+              os.makedirs(current_service_dir_path)
+            for version_dir_path in version_dirs_in_backup_service_dir:
+              if not os.path.islink(version_dir_path):
+                version_dir =  os.path.basename(version_dir_path)
+                shutil.copytree(version_dir_path, os.path.join(current_service_dir_path, version_dir))
+      else:
+        if os.path.isdir(backup_service) and not os.path.islink(backup_service):
+          service_name = os.path.basename(backup_service)
+          if not service_name in managed_services:
+            shutil.copytree(backup_service, os.path.join(current_base_service_dir,service_name))
 
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e239c8cf/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 6bf5e43..1ac77ab2 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -114,7 +114,7 @@ with patch.object(platform, "linux_distribution", return_value = MagicMock(retur
                   download_and_install_jdk, prompt_db_properties, setup, \
                   AmbariUserChecks, AmbariUserChecksLinux, AmbariUserChecksWindows, JDKSetup, reset, setup_jce_policy, expand_jce_zip_file
                 from ambari_server.serverUpgrade import upgrade, upgrade_local_repo, change_objects_owner, upgrade_stack, \
-                  run_stack_upgrade, run_metainfo_upgrade, run_schema_upgrade, move_user_custom_actions
+                  run_stack_upgrade, run_metainfo_upgrade, run_schema_upgrade, move_user_custom_actions, find_and_copy_custom_services
                 from ambari_server.setupHttps import is_valid_https_port, setup_https, import_cert_and_key_action, get_fqdn, \
                   generate_random_string, get_cert_info, COMMON_NAME_ATTR, is_valid_cert_exp, NOT_AFTER_ATTR, NOT_BEFORE_ATTR, \
                   SSL_DATE_FORMAT, import_cert_and_key, is_valid_cert_host, setup_truststore, \
@@ -5202,6 +5202,39 @@ class TestAmbariServer(TestCase):
     pass
 
 
+  @patch("shutil.copytree")
+  @patch("os.makedirs")
+  @patch("os.path.islink")
+  @patch("os.path.exists")
+  @patch("os.path.getctime")
+  @patch("re.compile")
+  @patch("os.path.join")
+  @patch("os.path.basename")
+  @patch("os.path.isdir")
+  @patch("glob.glob")
+  def test_find_and_copy_custom_services(self, glob_mock, isdir_mock, basename_mock, join_mock, re_compile_mock,
+                                         getctime_mock, exists_mock, islink_mock, makedirs_mock, copytree_mock):
+    # service/version dir is not link
+    glob_mock.return_value = [""]
+    isdir_mock.side_effect = [False, True, True]
+    islink_mock.return_value = False
+    exists_mock.side_effect = [True, False]
+    find_and_copy_custom_services("", "", "", "", "", "/common-services/")
+
+    self.assertTrue(makedirs_mock.called)
+    self.assertTrue(copytree_mock.called)
+
+
+    # service/version dir is link
+    makedirs_mock.reset_mock()
+    copytree_mock.reset_mock()
+    islink_mock.side_effect = [False, True]
+
+    self.assertFalse(makedirs_mock.called)
+    self.assertFalse(copytree_mock.called)
+    pass
+
+
   @not_for_platform(PLATFORM_WINDOWS)
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch("__builtin__.open")