You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2015/01/19 18:57:03 UTC
ambari git commit: AMBARI-9180. Move existing (user) custom actions
to a new location (dlysnichenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 4d71477d1 -> 908e7354c
AMBARI-9180. Move existing (user) custom actions to a new location (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/908e7354
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/908e7354
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/908e7354
Branch: refs/heads/trunk
Commit: 908e7354cb25c5513dc6104486699c985f27bec7
Parents: 4d71477
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Mon Jan 19 19:15:27 2015 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Mon Jan 19 19:54:50 2015 +0200
----------------------------------------------------------------------
ambari-server/src/main/python/ambari-server.py | 41 +++++++++++++++
.../src/test/python/TestAmbariServer.py | 52 ++++++++++++++++++--
2 files changed, 89 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/908e7354/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index ba3d5e7..7c08083 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -2713,11 +2713,52 @@ def upgrade(args):
os.remove(jdbc_symlink)
os.symlink(os.path.join(resources_dir,JDBC_DB_DEFAULT_DRIVER[db_name]), jdbc_symlink)
+ # Move *.py files from custom_actions to custom_actions/scripts
+ # This code exists for historic reasons in which custom action python scripts location changed from Ambari 1.7.0 to 2.0.0
+ ambari_version = get_ambari_version(properties)
+ if ambari_version is None:
+ args.warnings.append("*.py files were not moved from custom_actions to custom_actions/scripts.")
+ elif compare_versions(ambari_version, "2.0.0") == 0:
+ move_user_custom_actions()
+
+
# check if ambari has obsolete LDAP configuration
if properties.get_property(LDAP_PRIMARY_URL_PROPERTY) and not properties.get_property(IS_LDAP_CONFIGURED):
args.warnings.append("Existing LDAP configuration is detected. You must run the \"ambari-server setup-ldap\" command to adjust existing LDAP configuration.")
+def move_user_custom_actions():
+ print_info_msg('Moving *.py files from custom_actions to custom_actions/scripts')
+ properties = get_ambari_properties()
+ if properties == -1:
+ err = "Error getting ambari properties"
+ print_error_msg(err)
+ raise FatalException(-1, err)
+
+ try:
+ resources_dir = properties[RESOURCES_DIR_PROPERTY]
+ except (KeyError), e:
+ conf_file = properties.fileName
+ err = 'Property ' + str(e) + ' is not defined at ' + conf_file
+ print_error_msg(err)
+ raise FatalException(1, err)
+
+ custom_actions_dir_path = os.path.join(resources_dir, 'custom_actions')
+ custom_actions_scripts_dir_path = os.path.join(custom_actions_dir_path, 'scripts')
+ print_info_msg('Moving *.py files from %s to %s' % (custom_actions_dir_path, custom_actions_scripts_dir_path))
+
+ try:
+ for custom_action_file_name in os.listdir(custom_actions_dir_path):
+ custom_action_file_path = os.path.join(custom_actions_dir_path, custom_action_file_name)
+ if os.path.isfile(custom_action_file_path) and custom_action_file_path.endswith('.py'):
+ print_info_msg('Moving %s to %s' % (custom_action_file_path, custom_actions_scripts_dir_path))
+ shutil.move(custom_action_file_path, custom_actions_scripts_dir_path)
+ except (OSError, shutil.Error) as e:
+ err = 'Upgrade failed. Can not move *.py files from %s to %s. ' % (custom_actions_dir_path, custom_actions_scripts_dir_path) + str(e)
+ print_error_msg(err)
+ raise FatalException(1, err)
+
+
#
# The Ambari Server status.
#
http://git-wip-us.apache.org/repos/asf/ambari/blob/908e7354/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 a8f4197..cb870b8 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -22,7 +22,7 @@ import os
import datetime
import errno
import json
-from mock.mock import patch, MagicMock, create_autospec
+from mock.mock import patch, MagicMock, create_autospec, call
import operator
from optparse import OptionParser
import platform
@@ -3060,6 +3060,24 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.assertTrue(run_stack_upgrade_mock.called)
run_stack_upgrade_mock.assert_called_with("HDP", "2.0", None, None)
+ @patch.object(_ambari_server_, "get_ambari_properties")
+ @patch("os.listdir")
+ @patch("os.path.isfile")
+ @patch("shutil.move")
+ def test_move_user_custom_actions(self, shutil_move_mock, os_path_isfile_mock, os_listdir_mock, get_ambari_properties_mock):
+ properties = _ambari_server_.Properties()
+ properties.process_pair(_ambari_server_.RESOURCES_DIR_PROPERTY, 'some/test/fake/resources/dir/path')
+ get_ambari_properties_mock.return_value = properties
+ os_listdir_mock.return_value = ['sometestdir', 'sometestfile.md', 'sometestfile.py', 'sometestfile2.java', 'sometestfile2.py', 'sometestdir2.py']
+ os_path_isfile_mock.side_effect = [False, True, True, True, True, False]
+
+ _ambari_server_.move_user_custom_actions()
+
+ custom_actions_scripts_dir = os.path.join('some/test/fake/resources/dir/path', 'custom_actions', 'scripts')
+ shutil_move_mock.assert_has_calls([call(os.path.join('some/test/fake/resources/dir/path', 'custom_actions', 'sometestfile.py'), custom_actions_scripts_dir),
+ call(os.path.join('some/test/fake/resources/dir/path', 'custom_actions', 'sometestfile2.py'), custom_actions_scripts_dir)])
+ self.assertEqual(shutil_move_mock.call_count, 2)
+
@patch.object(_ambari_server_, "get_conf_dir")
@patch.object(_ambari_server_, "get_ambari_classpath")
@patch.object(_ambari_server_, "run_os_command")
@@ -3278,12 +3296,14 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
@patch.object(_ambari_server_, "is_root")
@patch.object(_ambari_server_, "get_ambari_version")
@patch.object(_ambari_server_, "get_ambari_properties")
- def test_upgrade_from_161(self, get_ambari_properties_mock, get_ambari_version_mock, is_root_mock, find_properties_file_mock,
- write_property_mock):
+ @patch.object(_ambari_server_, "move_user_custom_actions")
+ def test_upgrade_from_161(self, move_user_custom_actions, get_ambari_properties_mock, get_ambari_version_mock,
+ is_root_mock, find_properties_file_mock, write_property_mock):
args = MagicMock()
args.dbms = "postgres"
is_root_mock.return_value = True
get_ambari_version_mock.return_value = "1.7.0"
+ move_user_custom_actions.return_value = None
# Local Postgres
# In Ambari 1.6.1 for an embedded postgres database, the "server.jdbc.database" property stored the DB name,
@@ -3299,6 +3319,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.fail("Did not expect failure: " + str(fe))
else:
self.assertTrue(write_property_mock.called)
+ self.assertFalse(move_user_custom_actions.called)
# External Postgres
# In Ambari 1.6.1 for an external postgres database, the "server.jdbc.database" property stored the
@@ -3317,6 +3338,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.fail("Did not expect failure: " + str(fe))
else:
self.assertTrue(write_property_mock.called)
+ self.assertFalse(move_user_custom_actions.called)
# External Postgres missing DB type, so it should be set based on the JDBC URL.
write_property_mock.reset_mock()
@@ -3332,6 +3354,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.fail("Did not expect failure: " + str(fe))
else:
self.assertTrue(write_property_mock.call_count == 2)
+ self.assertFalse(move_user_custom_actions.called)
# External MySQL
# In Ambari 1.6.1 for an external MySQL database, the "server.jdbc.database" property stored the DB type ("mysql"),
@@ -3349,6 +3372,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.fail("Did not expect failure: " + str(fe))
else:
self.assertTrue(write_property_mock.called)
+ self.assertFalse(move_user_custom_actions.called)
# External MySQL missing DB type, so it should be set based on the JDBC URL.
write_property_mock.reset_mock()
@@ -3364,6 +3388,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
self.fail("Did not expect failure: " + str(fe))
else:
self.assertTrue(write_property_mock.call_count == 2)
+ self.assertFalse(move_user_custom_actions.called)
@patch("__builtin__.open")
@@ -3383,7 +3408,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
@patch.object(_ambari_server_, "is_root")
@patch.object(_ambari_server_, "get_ambari_properties")
@patch.object(_ambari_server_, "upgrade_local_repo")
- def test_upgrade(self, upgrade_local_repo_mock,
+ @patch.object(_ambari_server_, "move_user_custom_actions")
+ def test_upgrade(self, move_user_custom_actions, upgrade_local_repo_mock,
get_ambari_properties_mock, is_root_mock, get_ambari_version_mock,
parse_properties_file_mock,
update_ambari_properties_mock, run_schema_upgrade_mock,
@@ -3398,6 +3424,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
run_schema_upgrade_mock.return_value = 0
isfile_mock.return_value = False
get_ambari_version_mock.return_value = CURR_AMBARI_VERSION
+ move_user_custom_actions.return_value = None
# Testing call under non-root
is_root_mock.return_value = False
@@ -3420,6 +3447,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
warning_args = print_warning_msg_mock.call_args[0][0]
self.assertTrue("custom ambari user" in warning_args)
self.assertTrue(upgrade_local_repo_mock.called)
+ self.assertTrue(move_user_custom_actions.called)
# Testing with defined custom user
read_ambari_user_mock.return_value = "ambari-custom-user"
@@ -3430,12 +3458,28 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
get_ambari_properties_mock.return_value = properties
run_schema_upgrade_mock.return_value = 0
parse_properties_file_mock.called = False
+ move_user_custom_actions.called = False
retcode = _ambari_server_.upgrade(args)
self.assertTrue(get_ambari_properties_mock.called)
self.assertNotEqual(-1, retcode)
self.assertTrue(parse_properties_file_mock.called)
self.assertTrue(run_schema_upgrade_mock.called)
+ self.assertTrue(move_user_custom_actions.called)
+
+ # Assert that move_user_custom_actions is called on upgrade to Ambari == 2.0.0
+ get_ambari_version_mock.return_value = '2.0.0'
+ move_user_custom_actions.called = False
+ _ambari_server_.upgrade(args)
+ self.assertTrue(move_user_custom_actions.called)
+
+ # Assert that move_user_custom_actions is not called on upgrade to Ambari < 2.0.0
+ get_ambari_version_mock.return_value = '1.6.0'
+ move_user_custom_actions.called = False
+ _ambari_server_.upgrade(args)
+ self.assertFalse(move_user_custom_actions.called)
+
+ get_ambari_version_mock.return_value = CURR_AMBARI_VERSION
# test getAmbariProperties failed
get_ambari_properties_mock.return_value = -1