Repository: ambari Updated Branches: refs/heads/trunk 803bc7354 -> 27262b897
AMBARI-15300. Ability to customize Server LOG + PID dirs (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/27262b89 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/27262b89 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/27262b89 Branch: refs/heads/trunk Commit: 27262b897dba1b1c4201bf2086da644381cec933 Parents: 803bc73 Author: Andrew Onishuk <aonis...@hortonworks.com> Authored: Wed Mar 16 13:05:48 2016 +0200 Committer: Andrew Onishuk <aonis...@hortonworks.com> Committed: Wed Mar 16 13:05:48 2016 +0200 ---------------------------------------------------------------------- .../src/main/python/ambari_commons/os_utils.py | 32 +++++ ambari-server/conf/unix/ambari.properties | 3 +- .../apache/ambari/server/utils/AmbariPath.java | 1 - .../python/ambari_server/serverConfiguration.py | 111 +++++++++-------- .../src/test/python/TestAmbariServer.py | 120 ++++++++++--------- .../src/test/python/TestServerClassPath.py | 14 ++- 6 files changed, 170 insertions(+), 111 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/ambari-common/src/main/python/ambari_commons/os_utils.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_commons/os_utils.py b/ambari-common/src/main/python/ambari_commons/os_utils.py index c0edf4d..4a636d9 100644 --- a/ambari-common/src/main/python/ambari_commons/os_utils.py +++ b/ambari-common/src/main/python/ambari_commons/os_utils.py @@ -18,10 +18,12 @@ See the License for the specific language governing permissions and limitations under the License. ''' +import re import os import shutil import string from ambari_commons import OSCheck +from string import Template if OSCheck.is_windows_family(): pass @@ -170,6 +172,36 @@ def get_file_owner(file_full_name): return "" else: return pwd.getpwuid(os.stat(file_full_name).st_uid).pw_name + +def parse_log4j_file(filename): + def translate_praceholders(fmt): + # escape their markers + fmt = fmt.replace('%', '%%') + + fmt = re.sub(r'\${(.+?)}', r'%(\1)s', fmt) + + return fmt + + properties = {} + + Template.idpattern = r'[_a-z][_a-z0-9\.]*' + with open(filename, "rb") as fp: + lines = fp.readlines() + + for line in lines: + line = line.strip() + + if not line or line.startswith("#"): + continue + + # should we raise exception here? + if not "=" in line: + continue + + splited_values = line.split("=") + properties[splited_values[0].strip()] = translate_praceholders("=".join(splited_values[1:]).strip()) % properties + + return properties # # Chololatey package manager constants for Windows http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/ambari-server/conf/unix/ambari.properties ---------------------------------------------------------------------- diff --git a/ambari-server/conf/unix/ambari.properties b/ambari-server/conf/unix/ambari.properties index 449ac2a..5f05c2e 100644 --- a/ambari-server/conf/unix/ambari.properties +++ b/ambari-server/conf/unix/ambari.properties @@ -45,10 +45,11 @@ metadata.path=$ROOT/var/lib/ambari-server/resources/stacks common.services.path=$ROOT/var/lib/ambari-server/resources/common-services server.version.file=$ROOT/var/lib/ambari-server/resources/version webapp.dir=$ROOT/usr/lib/ambari-server/web +pid.dir=$ROOT/var/run/ambari-server +recommendations.dir=$ROOT/var/run/ambari-server/stack-recommendations bootstrap.dir=$ROOT/var/run/ambari-server/bootstrap bootstrap.script=$ROOT/usr/lib/python2.6/site-packages/ambari_server/bootstrap.py bootstrap.setup_agent.script=$ROOT/usr/lib/python2.6/site-packages/ambari_server/setupAgent.py -recommendations.dir=$ROOT/var/run/ambari-server/stack-recommendations stackadvisor.script=$ROOT/var/lib/ambari-server/resources/scripts/stack_advisor.py server.tmp.dir=$ROOT/var/lib/ambari-server/data/tmp ambari.python.wrap=ambari-python-wrap http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/ambari-server/src/main/java/org/apache/ambari/server/utils/AmbariPath.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/utils/AmbariPath.java b/ambari-server/src/main/java/org/apache/ambari/server/utils/AmbariPath.java index d73226d..4648cbc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/utils/AmbariPath.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/AmbariPath.java @@ -33,7 +33,6 @@ public class AmbariPath { return path; } String result = (rootDirectory + path).replaceAll("/+","/"); - LOG.info(result); return result; } } http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/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 8f2c439..dc1fd8a 100644 --- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py +++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py @@ -32,7 +32,7 @@ import ambari_server.serverClassPath from ambari_commons.exceptions import FatalException from ambari_commons.os_check import OSCheck, OSConst from ambari_commons.os_family_impl import OsFamilyImpl -from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions +from ambari_commons.os_utils import run_os_command, search_file, set_file_permissions, parse_log4j_file from ambari_commons.logging_utils import get_debug_mode, print_info_msg, print_warning_msg, print_error_msg, \ set_debug_mode from ambari_server.properties import Properties @@ -59,6 +59,7 @@ OS_FAMILY_PROPERTY = "server.os_family" OS_TYPE_PROPERTY = "server.os_type" BOOTSTRAP_DIR_PROPERTY = "bootstrap.dir" +RECOMMENDATIONS_DIR_PROPERTY = 'recommendations.dir' AMBARI_CONF_VAR = "AMBARI_CONF_DIR" AMBARI_PROPERTIES_FILE = "ambari.properties" @@ -189,11 +190,50 @@ BOOTSTRAP_SCRIPT = 'bootstrap.script' CUSTOM_ACTION_DEFINITIONS = 'custom.action.definitions' BOOTSTRAP_SETUP_AGENT_SCRIPT = 'bootstrap.setup_agent.script' STACKADVISOR_SCRIPT = 'stackadvisor.script' +PID_DIR_PROPERTY = 'pid.dir' REQUIRED_PROPERTIES = [OS_FAMILY_PROPERTY, OS_TYPE_PROPERTY, COMMON_SERVICES_PATH_PROPERTY, SERVER_VERSION_FILE_PATH, WEBAPP_DIR_PROPERTY, STACK_LOCATION_KEY, SECURITY_KEYS_DIR, JDBC_DATABASE_NAME_PROPERTY, NR_USER_PROPERTY, JAVA_HOME_PROPERTY, JDBC_PASSWORD_PROPERTY, SHARED_RESOURCES_DIR, JDBC_USER_NAME_PROPERTY, BOOTSTRAP_SCRIPT, RESOURCES_DIR_PROPERTY, CUSTOM_ACTION_DEFINITIONS, - BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY] + BOOTSTRAP_SETUP_AGENT_SCRIPT, STACKADVISOR_SCRIPT, BOOTSTRAP_DIR_PROPERTY, PID_DIR_PROPERTY] + +def get_conf_dir(): + try: + conf_dir = os.environ[AMBARI_CONF_VAR] + return conf_dir + except KeyError: + default_conf_dir = AmbariPath.get("/etc/ambari-server/conf") + print_info_msg(AMBARI_CONF_VAR + " is not set, using default " + default_conf_dir) + return default_conf_dir + +def find_properties_file(): + conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) + if conf_file is None: + err = 'File %s not found in search path $%s: %s' % (AMBARI_PROPERTIES_FILE, + AMBARI_CONF_VAR, get_conf_dir()) + print err + raise FatalException(1, err) + else: + print_info_msg('Loading properties from ' + conf_file) + return conf_file + +# Load ambari properties and return dict with values +def get_ambari_properties(): + conf_file = find_properties_file() + + properties = None + try: + properties = Properties() + with open(conf_file) as hfR: + properties.load(hfR) + + for k,v in properties.iteritems(): + properties.__dict__[k] = v.replace("$ROOT", os.environ["ROOT"]) + properties._props[k] = v.replace("$ROOT", os.environ["ROOT"]) + except (Exception), e: + print 'Could not read "%s": %s' % (conf_file, e) + return -1 + return properties class ServerDatabaseType(object): internal = 0 @@ -279,9 +319,13 @@ class ServerDatabases(object): class ServerConfigDefaults(object): def __init__(self): + properties = get_ambari_properties() + if properties == -1: + print_error_msg("Error getting ambari properties") + self.JAVA_SHARE_PATH = "/usr/share/java" self.SHARE_PATH = "/usr/share" - self.OUT_DIR = AmbariPath.get(os.sep + os.path.join("var", "log", "ambari-server")) + self.OUT_DIR = parse_log4j_file("/etc/ambari-server/conf/log4j.properties")['ambari.log.dir'] self.SERVER_OUT_FILE = os.path.join(self.OUT_DIR, "ambari-server.out") self.SERVER_LOG_FILE = os.path.join(self.OUT_DIR, "ambari-server.log") self.ROOT_FS_PATH = os.sep @@ -294,7 +338,10 @@ class ServerConfigDefaults(object): # Configuration defaults self.DEFAULT_CONF_DIR = "" - self.PID_DIR = AmbariPath.get(os.sep + os.path.join("var", "run", "ambari-server")) + self.PID_DIR = properties.get_property(PID_DIR_PROPERTY) + self.BOOTSTRAP_DIR = properties.get_property(BOOTSTRAP_DIR_PROPERTY) + self.RECOMMENDATIONS_DIR = properties.get_property(RECOMMENDATIONS_DIR_PROPERTY) + self.DEFAULT_LIBS_DIR = "" self.DEFAULT_VLIBS_DIR = "" @@ -407,11 +454,11 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults): # Rules are executed in the same order as they are listed # {0} in user/group will be replaced by customized ambari-server username self.NR_ADJUST_OWNERSHIP_LIST = [ - (AmbariPath.get("/var/log/ambari-server/*"), "644", "{0}", True), - (AmbariPath.get("/var/log/ambari-server/"), "755", "{0}", False), - (AmbariPath.get("/var/run/ambari-server/*"), "644", "{0}", True), - (AmbariPath.get("/var/run/ambari-server/"), "755", "{0}", False), - (AmbariPath.get("/var/run/ambari-server/bootstrap"), "755", "{0}", False), + (self.OUT_DIR + "/*", "644", "{0}", True), + (self.OUT_DIR, "755", "{0}", False), + (self.PID_DIR + "/*", "644", "{0}", True), + (self.PID_DIR, "755", "{0}", False), + (self.BOOTSTRAP_DIR, "755", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/ambari-env.sh"), "700", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/ambari-sudo.sh"), "700", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/keys/*"), "600", "{0}", True), @@ -431,8 +478,8 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults): (AmbariPath.get("/etc/ambari-server/conf/password.dat"), "640", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/keys/pass.txt"), "600", "{0}", False), (AmbariPath.get("/etc/ambari-server/conf/ldap-password.dat"), "640", "{0}", False), - (AmbariPath.get("/var/run/ambari-server/stack-recommendations/"), "744", "{0}", True), - (AmbariPath.get("/var/run/ambari-server/stack-recommendations/"), "755", "{0}", False), + (self.RECOMMENDATIONS_DIR, "744", "{0}", True), + (self.RECOMMENDATIONS_DIR, "755", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/resources/data/"), "644", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/resources/data/"), "755", "{0}", False), (AmbariPath.get("/var/lib/ambari-server/data/tmp/*"), "644", "{0}", True), @@ -445,8 +492,8 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults): self.NR_CHANGE_OWNERSHIP_LIST = [ (AmbariPath.get("/var/lib/ambari-server"), "{0}", True), (AmbariPath.get("/usr/lib/ambari-server"), "{0}", True), - (AmbariPath.get("/var/log/ambari-server"), "{0}", True), - (AmbariPath.get("/var/run/ambari-server"), "{0}", True), + (self.OUT_DIR, "{0}", True), + (self.PID_DIR, "{0}", True), (AmbariPath.get("/etc/ambari-server"), "{0}", True), ] self.NR_USERADD_CMD = 'useradd -M --comment "{1}" ' \ @@ -494,44 +541,6 @@ SECURITY_PROVIDER_KEY_CMD = "{0} -cp {1} " + \ -def get_conf_dir(): - try: - conf_dir = os.environ[AMBARI_CONF_VAR] - return conf_dir - except KeyError: - default_conf_dir = configDefaults.DEFAULT_CONF_DIR - print_info_msg(AMBARI_CONF_VAR + " is not set, using default " + default_conf_dir) - return default_conf_dir - -def find_properties_file(): - conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) - if conf_file is None: - err = 'File %s not found in search path $%s: %s' % (AMBARI_PROPERTIES_FILE, - AMBARI_CONF_VAR, get_conf_dir()) - print err - raise FatalException(1, err) - else: - print_info_msg('Loading properties from ' + conf_file) - return conf_file - -# Load ambari properties and return dict with values -def get_ambari_properties(): - conf_file = find_properties_file() - - properties = None - try: - properties = Properties() - with open(conf_file) as hfR: - properties.load(hfR) - - for k,v in properties.iteritems(): - properties.__dict__[k] = v.replace("$ROOT", os.environ["ROOT"]) - properties._props[k] = v.replace("$ROOT", os.environ["ROOT"]) - except (Exception), e: - print 'Could not read "%s": %s' % (conf_file, e) - return -1 - return properties - def read_ambari_user(): ''' Reads ambari user from properties file http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/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 305ad1a..659ca1f 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -42,68 +42,77 @@ from unittest import TestCase os.environ["ROOT"] = "" from only_for_platform import get_platform, not_for_platform, only_for_platform, os_distro_value, PLATFORM_LINUX, PLATFORM_WINDOWS +from ambari_commons import os_utils if get_platform() != PLATFORM_WINDOWS: from pwd import getpwnam + +import shutil +shutil.copyfile("/home/user/ambari/ambari-server/conf/unix/ambari.properties", "/tmp/ambari.properties") # We have to use this import HACK because the filename contains a dash -with patch("platform.linux_distribution", return_value = os_distro_value): - with patch("os.symlink"): - with patch("__builtin__.open"): +_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') - - 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, 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 - 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 + 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 + 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" @@ -4376,6 +4385,7 @@ class TestAmbariServer(TestCase): check_exitcode_mock.return_value = 0 p = Properties() + p.process_pair(PID_DIR_PROPERTY, '/var/run/ambari-server') p.process_pair(SECURITY_IS_ENCRYPTION_ENABLED, 'False') p.process_pair(JDBC_DATABASE_NAME_PROPERTY, 'some_value') p.process_pair(NR_USER_PROPERTY, 'some_value') http://git-wip-us.apache.org/repos/asf/ambari/blob/27262b89/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 b843df6..b3cab76 100644 --- a/ambari-server/src/test/python/TestServerClassPath.py +++ b/ambari-server/src/test/python/TestServerClassPath.py @@ -26,10 +26,18 @@ from ambari_commons.exceptions import FatalException from mock.mock import patch, MagicMock from unittest import TestCase from ambari_server.properties import Properties -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 +from ambari_commons import os_utils +os_utils.search_file = MagicMock(return_value="/tmp/ambari.properties") +import shutil +shutil.copyfile("/home/user/ambari/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 + +@patch("ambari_server.serverConfiguration.search_file", new=MagicMock(return_value="/tmp/ambari.properties")) class TestConfigs(TestCase): @patch("ambari_server.serverConfiguration.get_conf_dir")