You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/07/03 18:46:33 UTC
svn commit: r1499469 - in /incubator/ambari/trunk/ambari-server/src:
main/python/ambari-server.py test/python/TestAmbaryServer.py
Author: smohanty
Date: Wed Jul 3 16:46:33 2013
New Revision: 1499469
URL: http://svn.apache.org/r1499469
Log:
AMBARI-2544. Add the ambari.user property during upgrade. (Dmitry Lysnichenko via smohanty)
Modified:
incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1499469&r1=1499468&r2=1499469&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Wed Jul 3 16:46:33 2013
@@ -357,6 +357,12 @@ def update_ambari_properties():
for prop_key, prop_value in old_properties.getPropertyDict().items():
new_properties.process_pair(prop_key,prop_value)
+ # Adding custom user name property if it is absent
+ # In previous versions without custom user support server was started as
+ # "root" anyway so it's a reasonable default
+ if not NR_USER_PROPERTY in new_properties.keys():
+ new_properties.process_pair(NR_USER_PROPERTY, "root")
+
new_properties.store(open(conf_file,'w'))
except Exception, e:
@@ -565,7 +571,7 @@ def read_ambari_user():
def adjust_directory_permissions(ambari_user):
properties = get_ambari_properties()
bootstrap_dir = get_value_from_properties(properties, BOOTSTRAP_DIR_PROPERTY)
- print "Wiping bootstrap dir ({0}) contents...".format(bootstrap_dir)
+ print "Cleaning bootstrap directory ({0}) contents...".format(bootstrap_dir)
cmd = RECURSIVE_RM_CMD.format(bootstrap_dir)
run_os_command(cmd)
os.mkdir(bootstrap_dir)
@@ -574,7 +580,7 @@ def adjust_directory_permissions(ambari_
masterKeyFile = search_file(SECURITY_MASTER_KEY_FILENAME, keyLocation)
if masterKeyFile:
NR_ADJUST_OWNERSHIP_LIST.append((masterKeyFile, "600", "{0}", "{0}", False))
- print "Adjusting file permissions and ownership..."
+ print "Adjusting ambari-server permissions and ownership..."
for pack in NR_ADJUST_OWNERSHIP_LIST:
file = pack[0]
mod = pack[1]
@@ -605,8 +611,8 @@ def set_file_permissions(file, mod, user
def create_custom_user():
user = get_validated_string_input(
- "Please choose a user name for ambari-server daemon: ",
- "ambari",
+ "Enter user account for ambari-server daemon (root):",
+ "root",
"^[a-z_][a-z0-9_-]{1,31}$",
"Invalid username.",
False
@@ -658,7 +664,7 @@ def check_ambari_user():
update_user_setting = create_user # Only if we will create another user
else: # user is not configured yet
update_user_setting = True # Write configuration anyway
- create_user = get_YN_input("Use a separate user for ambari-server "
+ create_user = get_YN_input("Customize user account for ambari-server "
"daemon [y/n] (n)? ", False)
if not create_user:
user = "root"
Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1499469&r1=1499468&r2=1499469&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Wed Jul 3 16:46:33 2013
@@ -1669,7 +1669,7 @@ class TestAmbariServer(TestCase):
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5)
rcode = ambari_server.reset(args)
-
+ signal.alarm(0)
self.assertEqual(None, rcode)
self.assertTrue(setup_db_mock.called)
@@ -2376,6 +2376,42 @@ class TestAmbariServer(TestCase):
self.assertEquals(0, ambari_server.update_ambari_properties())
self.assertFalse(properties_mock.called)
+
+ @patch.object(ambari_server, "get_conf_dir")
+ def test_update_ambari_properties_without_user_property(self, get_conf_dir_mock):
+ '''
+ Checks: update_ambari_properties call should add ambari-server.user property if
+ it's absent
+ '''
+ properties = ["server.jdbc.user.name=ambari-server\n",
+ "server.jdbc.user.passwd=/etc/ambari-server/conf/password.dat\n",
+ "java.home=/usr/jdk64/jdk1.6.0_31\n",
+ "server.os_type=redhat6\n"]
+
+ get_conf_dir_mock.return_value = '/etc/ambari-server/conf'
+
+ (tf1, fn1) = tempfile.mkstemp()
+ (tf2, fn2) = tempfile.mkstemp()
+ ambari_server.AMBARI_PROPERTIES_RPMSAVE_FILE = fn1
+ ambari_server.AMBARI_PROPERTIES_FILE = fn2
+
+ with open(ambari_server.AMBARI_PROPERTIES_RPMSAVE_FILE, 'w') as f:
+ for line in properties:
+ f.write(line)
+
+ #Call tested method
+ ambari_server.update_ambari_properties()
+
+ ambari_properties = ambari_server.Properties()
+ ambari_properties.load(open(fn2))
+
+ self.assertTrue(ambari_server.NR_USER_PROPERTY in ambari_properties.keys())
+ value = ambari_properties[ambari_server.NR_USER_PROPERTY]
+ self.assertEqual(value, "root")
+
+ os.unlink(fn2)
+
+
@patch("sys.exit")
@patch.object(ambari_server, "get_YN_input")
@patch.object(ambari_server, "get_db_cli_tool")