You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/06/24 06:59:03 UTC
svn commit: r1495925 - in /incubator/ambari/trunk/ambari-agent/src:
main/python/ambari_agent/hostname.py test/python/TestHostname.py
Author: mahadev
Date: Mon Jun 24 04:59:02 2013
New Revision: 1495925
URL: http://svn.apache.org/r1495925
Log:
AMBARI-2472. Make public hostname for the agent configurable so that the configurable hostname is used if provided. (mahadev)
Modified:
incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/hostname.py
incubator/ambari/trunk/ambari-agent/src/test/python/TestHostname.py
Modified: incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/hostname.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/hostname.py?rev=1495925&r1=1495924&r2=1495925&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/hostname.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/python/ambari_agent/hostname.py Mon Jun 24 04:59:02 2013
@@ -22,7 +22,10 @@ import socket
import subprocess
import urllib2
import AmbariConfig
+import logging
+import traceback
+logger = logging.getLogger()
def hostname():
config = AmbariConfig.config
@@ -41,6 +44,23 @@ def hostname():
return socket.getfqdn()
def public_hostname():
+ config = AmbariConfig.config
+ out = ''
+ err = ''
+ try:
+ if config.has_option('agent', 'public_hostname_script'):
+ scriptname = config.get('agent', 'public_hostname_script')
+ output = subprocess.Popen([scriptname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = output.communicate()
+ if (0 == output.returncode and 0 != len(out.strip())):
+ return out.strip()
+ except:
+ #ignore for now.
+ trace_info = traceback.format_exc()
+ logger.info("Error using the scriptname:" + trace_info
+ + " :out " + out + " :err " + err)
+ logger.info("Defaulting to fqdn.")
+
# future - do an agent entry for this too
try:
handle = urllib2.urlopen('http://169.254.169.254/latest/meta-data/public-hostname', '', 2)
Modified: incubator/ambari/trunk/ambari-agent/src/test/python/TestHostname.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/test/python/TestHostname.py?rev=1495925&r1=1495924&r2=1495925&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/test/python/TestHostname.py (original)
+++ incubator/ambari/trunk/ambari-agent/src/test/python/TestHostname.py Mon Jun 24 04:59:02 2013
@@ -40,7 +40,6 @@ class TestHostname(TestCase):
os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)
tmpfile = file(tmpname, "w+")
-
config = AmbariConfig.config
try:
tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
@@ -55,5 +54,29 @@ class TestHostname(TestCase):
pass
+ def test_public_hostname_override(self):
+ fd = tempfile.mkstemp(text=True)
+ tmpname = fd[1]
+ os.close(fd[0])
+ os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)
+
+ tmpfile = file(tmpname, "w+")
+
+ config = AmbariConfig.config
+ try:
+ tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
+ tmpfile.close()
+
+ config.set('agent', 'public_hostname_script', tmpname)
+
+ self.assertEquals(hostname.public_hostname(), 'test.example.com',
+ "expected hostname 'test.example.com'")
+ finally:
+ os.remove(tmpname)
+ config.remove_option('agent', 'public_hostname_script')
+
+ pass
+
+