Repository: ambari Updated Branches: refs/heads/trunk b09dfe4a2 -> 8eb03cd57
AMBARI-15684. Provide more intuitive error message when unable to change Ambari server pid or log dirs (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8eb03cd5 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8eb03cd5 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8eb03cd5 Branch: refs/heads/trunk Commit: 8eb03cd5734f28af5d194fa4883f72e9e82315bf Parents: b09dfe4 Author: Andrew Onishuk <[email protected]> Authored: Mon Apr 4 15:21:56 2016 +0300 Committer: Andrew Onishuk <[email protected]> Committed: Mon Apr 4 15:21:56 2016 +0300 ---------------------------------------------------------------------- .../python/ambari_server/serverConfiguration.py | 8 ++ .../src/test/python/TestAmbariServer.py | 141 ++++++++++--------- ambari-server/src/test/python/TestOSCheck.py | 18 +-- .../src/test/python/TestServerClassPath.py | 14 +- .../src/test/python/TestServerUpgrade.py | 11 +- .../src/test/python/TestServerUtils.py | 8 +- 6 files changed, 116 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/ambari-server/src/main/python/ambari_server/serverConfiguration.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py index 54db372..001afd1 100644 --- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py +++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py @@ -346,6 +346,9 @@ class ServerConfigDefaults(object): self.BOOTSTRAP_DIR = properties.get_property(BOOTSTRAP_DIR_PROPERTY) self.RECOMMENDATIONS_DIR = properties.get_property(RECOMMENDATIONS_DIR_PROPERTY) + # this directories should be pre-created by user and be writable. + self.check_if_directories_writable([self.OUT_DIR, self.PID_DIR]) + self.DEFAULT_LIBS_DIR = "" self.DEFAULT_VLIBS_DIR = "" @@ -382,6 +385,11 @@ class ServerConfigDefaults(object): self.MESSAGE_ERROR_RESET_NOT_ROOT = "" self.MESSAGE_ERROR_UPGRADE_NOT_ROOT = "" self.MESSAGE_CHECK_FIREWALL = "" + + def check_if_directories_writable(self, directories): + for dir in directories: + if not os.path.isdir(dir) or not os.access(dir, os.W_OK): + raise FatalException(-1, "Please make sure {0} directory is created, and is writable by ambari-server user".format(dir)) @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY) class ServerConfigDefaultsWindows(ServerConfigDefaults): http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/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 091869f..95cb467 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -54,66 +54,68 @@ shutil.copyfile(project_dir+"/ambari-server/conf/unix/ambari.properties", "/tmp/ # We have to use this import HACK because the filename contains a dash _search_file = os_utils.search_file os_utils.search_file = MagicMock(return_value="/tmp/ambari.properties") -with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): - with patch("platform.linux_distribution", return_value = os_distro_value): - with patch("os.symlink"): - with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']): - _ambari_server_ = __import__('ambari-server') - os_utils.search_file = _search_file - with patch("__builtin__.open"): - from ambari_commons.firewall import Firewall - from ambari_commons.os_check import OSCheck, OSConst - from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl - from ambari_commons.exceptions import FatalException, NonFatalException - from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \ - print_info_msg, print_warning_msg, print_error_msg - from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions, remove_file, copy_file, \ - is_valid_filepath - from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers - from ambari_server.dbConfiguration_linux import PGConfig, LinuxDBMSConfig, OracleConfig - from ambari_server.properties import Properties - from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException - from ambari_server.serverConfiguration import configDefaults, get_java_exe_path, \ - check_database_name_property, OS_FAMILY_PROPERTY, \ - find_properties_file, get_ambari_properties, get_JAVA_HOME, \ - parse_properties_file, read_ambari_user, update_ambari_properties, update_properties_2, write_property, find_jdk, \ - get_is_active_instance, \ - AMBARI_CONF_VAR, AMBARI_SERVER_LIB, JDBC_DATABASE_PROPERTY, JDBC_RCA_PASSWORD_FILE_PROPERTY, \ - PERSISTENCE_TYPE_PROPERTY, JDBC_URL_PROPERTY, get_conf_dir, JDBC_USER_NAME_PROPERTY, JDBC_PASSWORD_PROPERTY, \ - JDBC_DATABASE_NAME_PROPERTY, OS_TYPE_PROPERTY, validate_jdk, JDBC_POSTGRES_SCHEMA_PROPERTY, \ - RESOURCES_DIR_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, JDBC_RCA_SCHEMA_PROPERTY, IS_LDAP_CONFIGURED, \ - SSL_API, SSL_API_PORT, CLIENT_API_PORT_PROPERTY,\ - JDBC_CONNECTION_POOL_TYPE, JDBC_CONNECTION_POOL_ACQUISITION_SIZE, \ - JDBC_CONNECTION_POOL_IDLE_TEST_INTERVAL, JDBC_CONNECTION_POOL_MAX_AGE, JDBC_CONNECTION_POOL_MAX_IDLE_TIME, \ - JDBC_CONNECTION_POOL_MAX_IDLE_TIME_EXCESS,\ - LDAP_MGR_PASSWORD_PROPERTY, LDAP_MGR_PASSWORD_ALIAS, JDBC_PASSWORD_FILENAME, NR_USER_PROPERTY, SECURITY_KEY_IS_PERSISTED, \ - SSL_TRUSTSTORE_PASSWORD_PROPERTY, SECURITY_IS_ENCRYPTION_ENABLED, PID_DIR_PROPERTY, SSL_TRUSTSTORE_PASSWORD_ALIAS, \ - SECURITY_MASTER_KEY_LOCATION, SECURITY_KEYS_DIR, LDAP_PRIMARY_URL_PROPERTY, store_password_file, \ - get_pass_file_path, GET_FQDN_SERVICE_URL, JDBC_USE_INTEGRATED_AUTH_PROPERTY, SECURITY_KEY_ENV_VAR_NAME, \ - JAVA_HOME_PROPERTY, JDK_NAME_PROPERTY, JCE_NAME_PROPERTY, STACK_LOCATION_KEY, SERVER_VERSION_FILE_PATH, \ - COMMON_SERVICES_PATH_PROPERTY, WEBAPP_DIR_PROPERTY, SHARED_RESOURCES_DIR, BOOTSTRAP_SCRIPT, \ - CUSTOM_ACTION_DEFINITIONS, BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, MPACKS_STAGING_PATH_PROPERTY - from ambari_server.serverUtils import is_server_runing, refresh_stack_hash - from ambari_server.serverSetup import check_selinux, check_ambari_user, proceedJDBCProperties, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \ - 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 - 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, \ - SRVR_ONE_WAY_SSL_PORT_PROPERTY, SRVR_TWO_WAY_SSL_PORT_PROPERTY, GANGLIA_HTTPS - from ambari_server.setupSecurity import adjust_directory_permissions, get_alias_string, get_ldap_event_spec_names, sync_ldap, LdapSyncOptions, \ - configure_ldap_password, setup_ldap, REGEX_HOSTNAME_PORT, REGEX_TRUE_FALSE, REGEX_ANYTHING, setup_master_key, \ - setup_ambari_krb5_jaas, ensure_can_start_under_current_user, generate_env - from ambari_server.userInput import get_YN_input, get_choice_string_input, get_validated_string_input, \ - read_password - from ambari_server_main import get_ulimit_open_files, ULIMIT_OPEN_FILES_KEY, ULIMIT_OPEN_FILES_DEFAULT - from ambari_server.serverClassPath import ServerClassPath - from ambari_server.hostUpdate import update_host_names - from ambari_server.checkDatabase import check_database - from ambari_server import serverConfiguration - serverConfiguration.search_file = _search_file +with patch("os.path.isdir", return_value = MagicMock(return_value=True)): + with patch("os.access", return_value = MagicMock(return_value=True)): + with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): + with patch("platform.linux_distribution", return_value = os_distro_value): + with patch("os.symlink"): + with patch("glob.glob", return_value = ['/etc/init.d/postgresql-9.3']): + _ambari_server_ = __import__('ambari-server') + os_utils.search_file = _search_file + with patch("__builtin__.open"): + from ambari_commons.firewall import Firewall + from ambari_commons.os_check import OSCheck, OSConst + from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl + from ambari_commons.exceptions import FatalException, NonFatalException + from ambari_commons.logging_utils import get_verbose, set_verbose, get_silent, set_silent, get_debug_mode, \ + print_info_msg, print_warning_msg, print_error_msg + from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions, remove_file, copy_file, \ + is_valid_filepath + from ambari_server.dbConfiguration import DBMSConfigFactory, check_jdbc_drivers + from ambari_server.dbConfiguration_linux import PGConfig, LinuxDBMSConfig, OracleConfig + from ambari_server.properties import Properties + from ambari_server.resourceFilesKeeper import ResourceFilesKeeper, KeeperException + from ambari_server.serverConfiguration import configDefaults, get_java_exe_path, \ + check_database_name_property, OS_FAMILY_PROPERTY, \ + find_properties_file, get_ambari_properties, get_JAVA_HOME, \ + parse_properties_file, read_ambari_user, update_ambari_properties, update_properties_2, write_property, find_jdk, \ + get_is_active_instance, \ + AMBARI_CONF_VAR, AMBARI_SERVER_LIB, JDBC_DATABASE_PROPERTY, JDBC_RCA_PASSWORD_FILE_PROPERTY, \ + PERSISTENCE_TYPE_PROPERTY, JDBC_URL_PROPERTY, get_conf_dir, JDBC_USER_NAME_PROPERTY, JDBC_PASSWORD_PROPERTY, \ + JDBC_DATABASE_NAME_PROPERTY, OS_TYPE_PROPERTY, validate_jdk, JDBC_POSTGRES_SCHEMA_PROPERTY, \ + RESOURCES_DIR_PROPERTY, JDBC_RCA_PASSWORD_ALIAS, JDBC_RCA_SCHEMA_PROPERTY, IS_LDAP_CONFIGURED, \ + SSL_API, SSL_API_PORT, CLIENT_API_PORT_PROPERTY,\ + JDBC_CONNECTION_POOL_TYPE, JDBC_CONNECTION_POOL_ACQUISITION_SIZE, \ + JDBC_CONNECTION_POOL_IDLE_TEST_INTERVAL, JDBC_CONNECTION_POOL_MAX_AGE, JDBC_CONNECTION_POOL_MAX_IDLE_TIME, \ + JDBC_CONNECTION_POOL_MAX_IDLE_TIME_EXCESS,\ + LDAP_MGR_PASSWORD_PROPERTY, LDAP_MGR_PASSWORD_ALIAS, JDBC_PASSWORD_FILENAME, NR_USER_PROPERTY, SECURITY_KEY_IS_PERSISTED, \ + SSL_TRUSTSTORE_PASSWORD_PROPERTY, SECURITY_IS_ENCRYPTION_ENABLED, PID_DIR_PROPERTY, SSL_TRUSTSTORE_PASSWORD_ALIAS, \ + SECURITY_MASTER_KEY_LOCATION, SECURITY_KEYS_DIR, LDAP_PRIMARY_URL_PROPERTY, store_password_file, \ + get_pass_file_path, GET_FQDN_SERVICE_URL, JDBC_USE_INTEGRATED_AUTH_PROPERTY, SECURITY_KEY_ENV_VAR_NAME, \ + JAVA_HOME_PROPERTY, JDK_NAME_PROPERTY, JCE_NAME_PROPERTY, STACK_LOCATION_KEY, SERVER_VERSION_FILE_PATH, \ + COMMON_SERVICES_PATH_PROPERTY, WEBAPP_DIR_PROPERTY, SHARED_RESOURCES_DIR, BOOTSTRAP_SCRIPT, \ + CUSTOM_ACTION_DEFINITIONS, BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, MPACKS_STAGING_PATH_PROPERTY + from ambari_server.serverUtils import is_server_runing, refresh_stack_hash + from ambari_server.serverSetup import check_selinux, check_ambari_user, proceedJDBCProperties, SE_STATUS_DISABLED, SE_MODE_ENFORCING, configure_os_settings, \ + 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 + 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, \ + SRVR_ONE_WAY_SSL_PORT_PROPERTY, SRVR_TWO_WAY_SSL_PORT_PROPERTY, GANGLIA_HTTPS + from ambari_server.setupSecurity import adjust_directory_permissions, get_alias_string, get_ldap_event_spec_names, sync_ldap, LdapSyncOptions, \ + configure_ldap_password, setup_ldap, REGEX_HOSTNAME_PORT, REGEX_TRUE_FALSE, REGEX_ANYTHING, setup_master_key, \ + setup_ambari_krb5_jaas, ensure_can_start_under_current_user, generate_env + from ambari_server.userInput import get_YN_input, get_choice_string_input, get_validated_string_input, \ + read_password + from ambari_server_main import get_ulimit_open_files, ULIMIT_OPEN_FILES_KEY, ULIMIT_OPEN_FILES_DEFAULT + from ambari_server.serverClassPath import ServerClassPath + from ambari_server.hostUpdate import update_host_names + from ambari_server.checkDatabase import check_database + from ambari_server import serverConfiguration + serverConfiguration.search_file = _search_file CURR_AMBARI_VERSION = "2.0.0" @@ -4305,6 +4307,8 @@ class TestAmbariServer(TestCase): @not_for_platform(PLATFORM_WINDOWS) + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12')) @patch("ambari_server_main.get_is_active_instance") @@ -4831,6 +4835,8 @@ class TestAmbariServer(TestCase): pass + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch("ambari_server.serverConfiguration.get_conf_dir") @patch("ambari_server.serverUpgrade.run_os_command") @patch("ambari_server.serverUpgrade.get_java_exe_path") @@ -4853,6 +4859,8 @@ class TestAmbariServer(TestCase): 'ambari-server.out 2>&1') pass + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12')) @patch("ambari_server.serverConfiguration.get_conf_dir") @@ -4878,6 +4886,8 @@ class TestAmbariServer(TestCase): pass + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = '/etc/conf' + os.pathsep + 'test' + os.pathsep + 'path12' + os.pathsep +'/path/to/jdbc.jar')) @@ -4922,6 +4932,8 @@ class TestAmbariServer(TestCase): self.assertTrue(run_os_command_mock.called) run_os_command_mock.assert_called_with(command, env=environ) + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch("ambari_server.serverConfiguration.get_conf_dir") @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = 'test' + os.pathsep + 'path12')) @patch("ambari_server.serverUpgrade.run_os_command") @@ -6896,6 +6908,8 @@ class TestAmbariServer(TestCase): self.assertEquals(sorted_x, sorted_y) pass + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = 'test' + os.pathsep + 'path12')) @patch("ambari_server.serverUtils.is_server_runing") @patch("ambari_commons.os_utils.run_os_command") @@ -8365,6 +8379,8 @@ class TestAmbariServer(TestCase): pass + @patch("os.path.isdir", new = MagicMock(return_value=True)) + @patch("os.access", new = MagicMock(return_value=True)) @patch.object(ServerClassPath, "get_full_ambari_classpath_escaped_for_shell", new = MagicMock(return_value = 'test' + os.pathsep + 'path12')) @patch("ambari_server.serverUtils.is_server_runing") @patch("ambari_commons.os_utils.run_os_command") @@ -8375,11 +8391,10 @@ class TestAmbariServer(TestCase): @patch("ambari_server.serverConfiguration.parse_properties_file") @patch("ambari_server.serverConfiguration.get_ambari_properties") @patch("ambari_server.serverConfiguration.get_java_exe_path") - @patch("os.access") @patch("os.path.isfile") @patch("sys.exit") @patch("ambari_server.userInput.get_YN_input") - def test_update_host_names(self, getYNInput_mock, sysExitMock, isFileMock, osAccessMock, getJavaExePathMock, + def test_update_host_names(self, getYNInput_mock, sysExitMock, isFileMock, getJavaExePathMock, getAmbariPropertiesMock, parsePropertiesFileMock, ensureDriverInstalledMock, readAmbariUserMock, ensureCanStartUnderCurrentUserMock, generateEnvMock, runOSCommandMock, isServerRunningMock): properties = Properties() @@ -8387,7 +8402,6 @@ class TestAmbariServer(TestCase): getYNInput_mock.return_value = False isFileMock.return_value = True - osAccessMock.return_value = True getJavaExePathMock.return_value = "/path/to/java" getAmbariPropertiesMock.return_value = properties readAmbariUserMock.return_value = "test_user" @@ -8400,7 +8414,6 @@ class TestAmbariServer(TestCase): self.assertEquals(len(sysExitMock.call_args_list), 3) self.assertTrue(isFileMock.called) - self.assertTrue(osAccessMock.called) self.assertTrue(getJavaExePathMock.called) self.assertTrue(readAmbariUserMock.called) self.assertTrue(ensureCanStartUnderCurrentUserMock.called) http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/ambari-server/src/test/python/TestOSCheck.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestOSCheck.py b/ambari-server/src/test/python/TestOSCheck.py index 1be783e..5b6e79d 100644 --- a/ambari-server/src/test/python/TestOSCheck.py +++ b/ambari-server/src/test/python/TestOSCheck.py @@ -39,14 +39,16 @@ _search_file = os_utils.search_file os_utils.search_file = MagicMock(return_value="/tmp/ambari.properties") utils = __import__('ambari_server.utils').utils # We have to use this import HACK because the filename contains a dash -with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): - with patch("platform.linux_distribution", return_value = os_distro_value_linux): - with patch.object(OSCheck, "os_distribution", return_value = os_distro_value): - with patch.object(utils, "get_postgre_hba_dir"): - os.environ["ROOT"] = "" - ambari_server = __import__('ambari-server') - - from ambari_server.serverConfiguration import update_ambari_properties, configDefaults +with patch("os.path.isdir", return_value = MagicMock(return_value=True)): + with patch("os.access", return_value = MagicMock(return_value=True)): + with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): + with patch("platform.linux_distribution", return_value = os_distro_value_linux): + with patch.object(OSCheck, "os_distribution", return_value = os_distro_value): + with patch.object(utils, "get_postgre_hba_dir"): + os.environ["ROOT"] = "" + ambari_server = __import__('ambari-server') + + from ambari_server.serverConfiguration import update_ambari_properties, configDefaults class TestOSCheck(TestCase): http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/ambari-server/src/test/python/TestServerClassPath.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestServerClassPath.py b/ambari-server/src/test/python/TestServerClassPath.py index fc66e7c..6e54316 100644 --- a/ambari-server/src/test/python/TestServerClassPath.py +++ b/ambari-server/src/test/python/TestServerClassPath.py @@ -33,11 +33,15 @@ import shutil project_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),os.path.normpath("../../../../")) shutil.copyfile(project_dir+"/ambari-server/conf/unix/ambari.properties", "/tmp/ambari.properties") -with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): - from ambari_server.dbConfiguration import get_jdbc_driver_path, get_native_libs_path - from ambari_server.serverConfiguration import get_conf_dir - from ambari_server.serverClassPath import ServerClassPath, AMBARI_SERVER_LIB, SERVER_CLASSPATH_KEY, JDBC_DRIVER_PATH_PROPERTY - +with patch("os.path.isdir", return_value = MagicMock(return_value=True)): + with patch("os.access", return_value = MagicMock(return_value=True)): + with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): + from ambari_server.dbConfiguration import get_jdbc_driver_path, get_native_libs_path + from ambari_server.serverConfiguration import get_conf_dir + from ambari_server.serverClassPath import ServerClassPath, AMBARI_SERVER_LIB, SERVER_CLASSPATH_KEY, JDBC_DRIVER_PATH_PROPERTY + +@patch("os.path.isdir", new = MagicMock(return_value=True)) +@patch("os.access", new = MagicMock(return_value=True)) @patch("ambari_server.serverConfiguration.search_file", new=MagicMock(return_value="/tmp/ambari.properties")) class TestConfigs(TestCase): http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/ambari-server/src/test/python/TestServerUpgrade.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestServerUpgrade.py b/ambari-server/src/test/python/TestServerUpgrade.py index 04ec337..5ac8d1c 100644 --- a/ambari-server/src/test/python/TestServerUpgrade.py +++ b/ambari-server/src/test/python/TestServerUpgrade.py @@ -32,13 +32,16 @@ shutil.copyfile(project_dir+"/ambari-server/conf/unix/ambari.properties", "/tmp/ _search_file = os_utils.search_file os_utils.search_file = MagicMock(return_value="/tmp/ambari.properties") -with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): - from ambari_server.serverUpgrade import set_current, SetCurrentVersionOptions, upgrade_stack - import ambari_server +with patch("os.path.isdir", return_value = MagicMock(return_value=True)): + with patch("os.access", return_value = MagicMock(return_value=True)): + with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): + from ambari_server.serverUpgrade import set_current, SetCurrentVersionOptions, upgrade_stack + import ambari_server os_utils.search_file = _search_file - +@patch("os.path.isdir", new = MagicMock(return_value=True)) +@patch("os.access", new = MagicMock(return_value=True)) class TestServerUpgrade(TestCase): @patch("ambari_server.serverUpgrade.is_server_runing") http://git-wip-us.apache.org/repos/asf/ambari/blob/8eb03cd5/ambari-server/src/test/python/TestServerUtils.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestServerUtils.py b/ambari-server/src/test/python/TestServerUtils.py index c34bba5..4d8c076 100644 --- a/ambari-server/src/test/python/TestServerUtils.py +++ b/ambari-server/src/test/python/TestServerUtils.py @@ -28,9 +28,11 @@ import shutil project_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),os.path.normpath("../../../../")) shutil.copyfile(project_dir+"/ambari-server/conf/unix/ambari.properties", "/tmp/ambari.properties") -with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): - from ambari_server.serverUtils import get_ambari_server_api_base - from ambari_server.serverConfiguration import CLIENT_API_PORT, CLIENT_API_PORT_PROPERTY, SSL_API, DEFAULT_SSL_API_PORT, SSL_API_PORT +with patch("os.path.isdir", return_value = MagicMock(return_value=True)): + with patch("os.access", return_value = MagicMock(return_value=True)): + with patch.object(os_utils, "parse_log4j_file", return_value={'ambari.log.dir': '/var/log/ambari-server'}): + from ambari_server.serverUtils import get_ambari_server_api_base + from ambari_server.serverConfiguration import CLIENT_API_PORT, CLIENT_API_PORT_PROPERTY, SSL_API, DEFAULT_SSL_API_PORT, SSL_API_PORT #@patch("ambari_server.serverConfiguration.search_file", new=MagicMock(return_value="/tmp/ambari.properties")) class TestServerUtils(TestCase):
