Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
7fbb1f65
Commit
7fbb1f65
authored
Nov 20, 2007
by
Michael Hanselmann
Browse files
Make sure aliases written to /etc/hosts are unique.
Reviewed-by: iustinp
parent
f7414041
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/utils.py
View file @
7fbb1f65
...
...
@@ -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
))
try
:
out
=
os
.
fdopen
(
fd
,
'w'
)
...
...
test/ganeti.utils_unittest.py
View file @
7fbb1f65
...
...
@@ -456,6 +456,15 @@ class TestEtcHosts(GanetiTestCase):
"127.0.0.1
\t
localhost
\n
"
"192.168.1.1
\t
myhost.domain.tld myhost
\n
"
)
def
testSettingDuplicateName
(
self
):
SetEtcHostsEntry
(
self
.
tmpname
,
'1.2.3.4'
,
'myhost'
,
[
'myhost'
])
self
.
assertFileContent
(
self
.
tmpname
,
"# This is a test file for /etc/hosts
\n
"
"127.0.0.1
\t
localhost
\n
"
"192.168.1.1 router gw
\n
"
"1.2.3.4
\t
myhost
\n
"
)
def
testRemovingExistingHost
(
self
):
RemoveEtcHostsEntry
(
self
.
tmpname
,
'router'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment