|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
|
|
|
from unittest import TestCase
|
|
|
import ambari_agent.hostname as hostname
|
|
|
-from ambari_agent.AmbariConfig import AmbariConfig
|
|
|
+import ambari_agent.AmbariConfig as AmbariConfig
|
|
|
import socket
|
|
|
import tempfile
|
|
|
import shutil
|
|
@@ -33,21 +33,24 @@ class TestHostname(TestCase):
|
|
|
pass
|
|
|
|
|
|
def test_hostname_override(self):
|
|
|
- tmpname = tempfile.mkstemp(text=True)[1]
|
|
|
+ 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 = AmbariConfig().getConfig()
|
|
|
config.set('agent', 'hostname_script', tmpname)
|
|
|
|
|
|
self.assertEquals(hostname.hostname(), 'test.example.com', "expected hostname 'test.example.com'")
|
|
|
finally:
|
|
|
os.remove(tmpname)
|
|
|
+ config.remove_option('agent', 'hostname_script')
|
|
|
|
|
|
pass
|
|
|
|