ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject ambari git commit: AMBARI-11570. Ambari agents stop heartbeating after days of uptime (rlevas)
Date Sun, 31 May 2015 22:17:54 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5204b3a02 -> c7ed673bb


AMBARI-11570. Ambari agents stop heartbeating after days of uptime (rlevas)


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

Branch: refs/heads/trunk
Commit: c7ed673bbea8371331ea92b564c61a2b8e8689ac
Parents: 5204b3a
Author: Robert Levas <rlevas@hortonworks.com>
Authored: Sun May 31 18:17:44 2015 -0400
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Sun May 31 18:17:44 2015 -0400

----------------------------------------------------------------------
 .../resource_management/TestSecurityCommons.py  |  4 ++--
 .../libraries/functions/security_commons.py     | 23 ++++++++++----------
 2 files changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c7ed673b/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py b/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
index ead0351..b44b454 100644
--- a/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
+++ b/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
@@ -283,7 +283,7 @@ class TestSecurityCommons(TestCase):
     cached_kinit_executor(kinit_path, user, keytab_file, principal, hostname, temp_dir, expiration_time)
 
     self.assertTrue(new_cached_exec_mock.called)
-    new_cached_exec_mock.assert_called_with(key, file_path + os.sep + filename, kinit_path,
user, keytab_file, principal, hostname)
+    new_cached_exec_mock.assert_called_with(key, file_path + os.sep + filename, kinit_path,
temp_dir, user, keytab_file, principal, hostname)
 
     # Test that the makedirs function is called with correct path when the directory doesn't
exist
     os_path_exists_mock.return_value = False
@@ -312,4 +312,4 @@ class TestSecurityCommons(TestCase):
     cached_kinit_executor(kinit_path, user, keytab_file, principal, hostname, temp_dir, expiration_time)
 
     self.assertTrue(new_cached_exec_mock.called)
-    new_cached_exec_mock.assert_called_with(key, file_path + os.sep + filename, kinit_path,
user, keytab_file, principal, hostname)
+    new_cached_exec_mock.assert_called_with(key, file_path + os.sep + filename, kinit_path,
temp_dir, user, keytab_file, principal, hostname)

http://git-wip-us.apache.org/repos/asf/ambari/blob/c7ed673b/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
b/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
index 688eba7..47bcee0 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
@@ -18,7 +18,7 @@ limitations under the License.
 """
 
 from datetime import datetime, timedelta
-from resource_management import Execute
+from resource_management import Execute, File
 from tempfile import mkstemp
 import os
 import ambari_simplejson as json # simplejson is much faster comparing to Python 2.6 json
module and has the same functions set.
@@ -201,33 +201,34 @@ def cached_kinit_executor(kinit_path, exec_user, keytab_file, principal,
hostnam
       cache_file.write("{}")
 
   if (not output) or (key not in output) or ("last_successful_execution" not in output[key]):
-    new_cached_exec(key, file_path, kinit_path, exec_user, keytab_file, principal, hostname)
+    new_cached_exec(key, file_path, kinit_path, temp_dir, exec_user, keytab_file, principal,
hostname)
   else:
     last_run_time = output[key]["last_successful_execution"]
     now = datetime.now()
-    if (now - datetime.strptime(last_run_time, "%Y-%m-%d %H:%M:%S.%f") > timedelta(
-      minutes=expiration_time)):
-      new_cached_exec(key, file_path, kinit_path, exec_user, keytab_file, principal, hostname)
+    if (now - datetime.strptime(last_run_time, "%Y-%m-%d %H:%M:%S.%f") > timedelta(minutes=expiration_time)):
+      new_cached_exec(key, file_path, kinit_path, temp_dir, exec_user, keytab_file, principal,
hostname)
 
 
-def new_cached_exec(key, file_path, kinit_path, exec_user, keytab_file, principal, hostname):
+def new_cached_exec(key, file_path, kinit_path, temp_dir, exec_user, keytab_file, principal,
hostname):
   """
   Entry point of an actual execution - triggered when timeout on the cache expired or on
fresh execution
   """
   now = datetime.now()
-  _, temp_kinit_cache_file = mkstemp()
-  command = "su -s /bin/bash - %s -c '%s -c %s -kt %s %s'" % \
-            (exec_user, kinit_path, temp_kinit_cache_file, keytab_file,
+  temp_kinit_cache_fd, temp_kinit_cache_filename = mkstemp(dir=temp_dir)
+  command = "%s -c %s -kt %s %s" % \
+            (kinit_path, temp_kinit_cache_filename, keytab_file,
              principal.replace("_HOST", hostname))
 
+  os.close(temp_kinit_cache_fd)
+
   try:
-    Execute(command)
+    Execute(command, user=exec_user)
 
     with open(file_path, 'w+') as cache_file:
       result = {key: {"last_successful_execution": str(now)}}
       json.dump(result, cache_file)
   finally:
-    os.remove(temp_kinit_cache_file)
+    File(temp_kinit_cache_filename, action='delete')
 
 def get_value(values, property_path, default_value):
   names = property_path.split('/')


Mime
View raw message