ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject [1/2] ambari git commit: AMBARI-12790. Handle ambari-env.sh file like ambari.properties (dlysnichenko)
Date Mon, 17 Aug 2015 15:53:12 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 de5cb6036 -> 0cb690da3
  refs/heads/trunk 9d8164796 -> 7cf27fc4e


AMBARI-12790. Handle ambari-env.sh file like ambari.properties (dlysnichenko)


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

Branch: refs/heads/branch-2.1
Commit: 0cb690da3f6f2a7a71019b45d1774fdf4e0cfc1c
Parents: de5cb60
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Mon Aug 17 18:53:17 2015 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Mon Aug 17 18:53:17 2015 +0300

----------------------------------------------------------------------
 .../python/ambari_server/serverConfiguration.py | 24 ++++++++++++++++++++
 .../main/python/ambari_server/serverUpgrade.py  |  8 ++++++-
 .../src/test/python/TestAmbariServer.py         | 10 ++++++--
 3 files changed, 39 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0cb690da/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 4d49685..a86f170 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -60,6 +60,7 @@ BOOTSTRAP_DIR_PROPERTY = "bootstrap.dir"
 
 AMBARI_CONF_VAR = "AMBARI_CONF_DIR"
 AMBARI_PROPERTIES_FILE = "ambari.properties"
+AMBARI_ENV_FILE = "ambari-env.sh"
 AMBARI_KRB_JAAS_LOGIN_FILE = "krb5JAASLogin.conf"
 GET_FQDN_SERVICE_URL = "server.fqdn.service.url"
 
@@ -262,6 +263,7 @@ class ServerConfigDefaults(object):
     self.DEFAULT_CONF_DIR = ""
     self.PID_DIR = os.sep + os.path.join("var", "run", "ambari-server")
     self.DEFAULT_LIBS_DIR = ""
+    self.DEFAULT_VLIBS_DIR = ""
 
     self.AMBARI_PROPERTIES_BACKUP_FILE = ""
     self.AMBARI_KRB_JAAS_LOGIN_BACKUP_FILE = ""
@@ -360,8 +362,10 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults):
     # Configuration defaults
     self.DEFAULT_CONF_DIR = "/etc/ambari-server/conf"
     self.DEFAULT_LIBS_DIR = "/usr/lib/ambari-server"
+    self.DEFAULT_VLIBS_DIR = "/var/lib/ambari-server"
 
     self.AMBARI_PROPERTIES_BACKUP_FILE = "ambari.properties.rpmsave"
+    self.AMBARI_ENV_BACKUP_FILE = "ambari-env.sh.rpmsave"
     self.AMBARI_KRB_JAAS_LOGIN_BACKUP_FILE = "krb5JAASLogin.conf.rpmsave"
     # ownership/permissions mapping
     # path - permissions - user - group - recursive
@@ -915,6 +919,26 @@ def update_krb_jaas_login_properties():
 
   return 0
 
+def update_ambari_env():
+  prev_env_file = search_file(configDefaults.AMBARI_ENV_BACKUP_FILE, configDefaults.DEFAULT_VLIBS_DIR)
+  env_file = search_file(AMBARI_ENV_FILE, configDefaults.DEFAULT_VLIBS_DIR)
+
+  # Previous env file does not exist
+  if (not prev_env_file) or (prev_env_file is None):
+    print_warning_msg("Can not find %s file from previous version, skipping restore of environment
settings" %
+                      configDefaults.AMBARI_ENV_BACKUP_FILE)
+    return 0
+
+  try:
+    if env_file is not None:
+      os.remove(env_file)
+      os.rename(prev_env_file, env_file)
+      print_warning_msg("Original file %s kept" % AMBARI_ENV_FILE)
+  except OSError as e:
+    print "Couldn't move %s file: %s" % (prev_env_file, e)
+    return -1
+
+  return 0
 
 def update_ambari_properties():
   prev_conf_file = search_file(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, get_conf_dir())

http://git-wip-us.apache.org/repos/asf/ambari/blob/0cb690da/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 c22ac7c..f9d65e9 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -37,7 +37,8 @@ from ambari_server.serverConfiguration import configDefaults, \
   get_java_exe_path, get_stack_location, parse_properties_file, read_ambari_user, update_ambari_properties,
\
   update_database_name_property, get_admin_views_dir, get_views_dir,\
   AMBARI_PROPERTIES_FILE, IS_LDAP_CONFIGURED, LDAP_PRIMARY_URL_PROPERTY, RESOURCES_DIR_PROPERTY,
\
-  SETUP_OR_UPGRADE_MSG, update_krb_jaas_login_properties, AMBARI_KRB_JAAS_LOGIN_FILE, get_db_type
+  SETUP_OR_UPGRADE_MSG, update_krb_jaas_login_properties, AMBARI_KRB_JAAS_LOGIN_FILE, get_db_type,
update_ambari_env, \
+  AMBARI_ENV_FILE
 from ambari_server.setupSecurity import adjust_directory_permissions, \
   generate_env, ensure_can_start_under_current_user
 from ambari_server.utils import compare_versions
@@ -292,6 +293,11 @@ def upgrade(args):
     err = AMBARI_PROPERTIES_FILE + ' file can\'t be updated. Exiting'
     raise FatalException(retcode, err)
 
+  retcode = update_ambari_env()
+  if not retcode == 0:
+    err = AMBARI_ENV_FILE + ' file can\'t be updated. Exiting'
+    raise FatalException(retcode, err)
+
   retcode = update_krb_jaas_login_properties()
   if retcode == -2:
     pass  # no changes done, let's be silent

http://git-wip-us.apache.org/repos/asf/ambari/blob/0cb690da/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 f7ce4b8..4d2abe8 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -4036,7 +4036,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverUpgrade.upgrade_local_repo")
   @patch("ambari_server.serverUpgrade.move_user_custom_actions")
   @patch("ambari_server.serverUpgrade.update_krb_jaas_login_properties")
-  def test_upgrade_from_161(self, update_krb_jaas_login_properties_mock, move_user_custom_actions_mock,
upgrade_local_repo_mock, get_ambari_properties_mock,
+  @patch("ambari_server.serverUpgrade.update_ambari_env")
+  def test_upgrade_from_161(self, update_ambari_env_mock, update_krb_jaas_login_properties_mock,
move_user_custom_actions_mock, upgrade_local_repo_mock, get_ambari_properties_mock,
                             get_ambari_properties_2_mock, get_ambari_properties_3_mock, get_ambari_version_mock,
write_property_mock,
                             is_root_mock, update_ambari_properties_mock, find_properties_file_mock,
run_os_command_mock,
                             run_schema_upgrade_mock, read_ambari_user_mock, print_warning_msg_mock,
@@ -4076,6 +4077,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
 
     is_root_mock.return_value = True
     update_ambari_properties_mock.return_value = 0
+    update_ambari_env_mock.return_value = 0
     get_ambari_version_mock.return_value = "1.7.0"
     move_user_custom_actions_mock.return_value = None
     update_krb_jaas_login_properties_mock.return_value = -2
@@ -4247,7 +4249,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch("ambari_server.serverUpgrade.upgrade_local_repo")
   @patch("ambari_server.serverUpgrade.move_user_custom_actions")
   @patch("ambari_server.serverUpgrade.update_krb_jaas_login_properties")
-  def test_upgrade(self, update_krb_jaas_login_properties_mock, move_user_custom_actions,
upgrade_local_repo_mock,
+  @patch("ambari_server.serverUpgrade.update_ambari_env")
+  @patch("ambari_server.serverConfiguration.shutil.rmtree")
+  def test_upgrade(self, rmtree_mock, update_ambari_env_mock, update_krb_jaas_login_properties_mock,
move_user_custom_actions, upgrade_local_repo_mock,
                    get_ambari_properties_mock, get_ambari_properties_2_mock, get_ambari_properties_3_mock,
                    is_root_mock, get_ambari_version_mock, get_ambari_version_2_mock,
                    parse_properties_file_mock,
@@ -4282,7 +4286,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     get_ambari_properties_3_mock.return_value = get_ambari_properties_2_mock.return_value
= \
       get_ambari_properties_mock.return_value = properties
     update_ambari_properties_mock.return_value = 0
+    update_ambari_env_mock.return_value = 0
     run_schema_upgrade_mock.return_value = 0
+    rmtree_mock.return_value = True
     isfile_mock.return_value = False
     get_ambari_version_2_mock.return_value = get_ambari_version_mock.return_value = CURR_AMBARI_VERSION
     move_user_custom_actions.return_value = None


Mime
View raw message