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/31058596 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/31058596 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/31058596 Branch: refs/heads/branch-feature-AMBARI-20859 Commit: 31058596b4ed0cf5b78c464fec2585940051c597 Parents: aa33c1b Author: Vitaly Brodetskyi <[email protected]> Authored: Tue Jun 20 22:21:01 2017 +0300 Committer: Vitaly Brodetskyi <[email protected]> Committed: Tue Jun 20 22:21:01 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/31058596/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 b488ca6..a4a4ae2 100644 --- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py +++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py @@ -405,6 +405,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)) @@ -425,10 +426,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/31058596/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 7f0cb93..8c135c3 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, change_objects_owner, \ - run_schema_upgrade, move_user_custom_actions + 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, \ @@ -5336,6 +5336,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")
