Commit 7fbb1f65 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Make sure aliases written to /etc/hosts are unique.

Reviewed-by: iustinp
parent f7414041
......@@ -756,6 +756,9 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases):
"""Sets the name of an IP address and hostname in /etc/hosts.
# Ensure aliases are unique
aliases = UniqueSequence([hostname] + aliases)[1:]
fd, tmpname = tempfile.mkstemp(dir=os.path.dirname(file_name))
out = os.fdopen(fd, 'w')
......@@ -456,6 +456,15 @@ class TestEtcHosts(GanetiTestCase):
"\tmyhost.domain.tld myhost\n")
def testSettingDuplicateName(self):
SetEtcHostsEntry(self.tmpname, '', 'myhost', ['myhost'])
"# This is a test file for /etc/hosts\n"
" router gw\n"
def testRemovingExistingHost(self):
RemoveEtcHostsEntry(self.tmpname, 'router')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment